mirror of
https://github.com/jie65535/Tetris.git
synced 2024-07-27 19:11:10 +08:00
提交源码
编译环境 MinGW gcc 7.2.0
This commit is contained in:
66
Tetris.h
Normal file
66
Tetris.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* Tetris.h -- file */
|
||||
#ifndef _TETRIS_H_
|
||||
#define _TETRIS_H_
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <stdlib.h>
|
||||
#include <conio.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
const char mapWidth = 10;
|
||||
const char mapHeight = 20;
|
||||
const char startX = mapWidth / 2 - 2;
|
||||
const char startY = 0;
|
||||
|
||||
const char shapeListMax = 7;
|
||||
const uint16_t shapeList[shapeListMax][4] = {
|
||||
{0xcc00, 0xcc00, 0xcc00, 0xcc00}, // O
|
||||
{0x4444, 0xf00, 0x4444, 0xf00 }, // I
|
||||
{0x88c0, 0xe800, 0xc440, 0x2e00}, // L
|
||||
{0x44c0, 0x8e00, 0xc880, 0xe200}, // J
|
||||
{0x4c80, 0xc600, 0x4c80, 0xc600}, // Z
|
||||
{0x8c40, 0x6c00, 0x8c40, 0x6c00}, // S
|
||||
{0x4c40, 0x4e00, 0x8c80, 0xe400} // T
|
||||
};
|
||||
class Box {
|
||||
public:
|
||||
Box(char _index = 0, char _dir = 0, char _x = 0, char _y = 0)
|
||||
:index(index), dir(_dir), x(_x), y(_y){};
|
||||
uint16_t getShape() const {return shapeList[index][dir];};
|
||||
void randGenerateNewBox()
|
||||
{
|
||||
index = rand() % shapeListMax;
|
||||
dir = 1; // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
x = startX; // <20><>ʼx<CABC><78><EFBFBD><EFBFBD>
|
||||
y = startY; // <20><>ʼy<CABC><79><EFBFBD><EFBFBD>
|
||||
}
|
||||
public:
|
||||
char index;
|
||||
char dir;
|
||||
char x;
|
||||
char y;
|
||||
};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD>ڵ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool isFeasible(const Box &target);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6>ڵ<EFBFBD>ͼ<EFBFBD><CDBC>
|
||||
void fixedPos(const Box &target);
|
||||
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>鵽ָ<E9B5BD><D6B8>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool move(Box &A, char XOffset, char YOffset);
|
||||
// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
|
||||
bool rotate(Box &A);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
|
||||
void clearCompleted();
|
||||
// <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
void printXY(COORD coord, std::string str);
|
||||
// <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ַ<EFBFBD><D6B7>ķ<EFBFBD><C4B7><EFBFBD>
|
||||
void printBox(const Box &target, std::string printChar, short x = 0, short y = 0);
|
||||
// չʾ<D5B9><CABE>ͼ
|
||||
void showMap(COORD coord);
|
||||
// <20><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>벢<EFBFBD>ж<EFBFBD>
|
||||
void input();
|
||||
// <20><>Ϸѭ<CFB7><D1AD>
|
||||
void GameLoop();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user