C++ 和 EasyX 图形库,实现2048小游戏,供大家参考,具体内容如下
MainGame2048.cpp
#include#include #include #include #include #include #include"Game2048.h" #define BLOCK_SIZE 60 #define SIZE_COL 10 #define SIZE_ROW 10 using namespace std; void DisplayMap(Game2048& mygame); int GetMove(); int main(int argc, char * argv[]) { HWND hwnd=initgraph(SIZE_COL*BLOCK_SIZE, SIZE_ROW*BLOCK_SIZE); setbkmode(TRANSPARENT); setbkcolor(RGB(180,180,180)); settextcolor(RGB(0,180,80)); cleardevice(); while (1) { Game2048 mygame(SIZE_ROW, SIZE_COL); while (1) { DisplayMap(mygame); int mov = GetMove(); cout << mov << endl; if (!mygame.Run(mov)) break; } if (MessageBox(hwnd, "游戏结束,是否重玩?", "Tips", MB_YESNO) == IDNO) break; } return 0; } int GetMove() { char move = ' '; move = getch(); if (move == 'w' || move == '8' || move == 'W') return MOV_UP; if (move == 's' || move == '5' || move == 'S') return MOV_DOWN; if (move == 'a' || move == '4' || move == 'A') return MOV_LEFT; if (move == 'd' || move == '6' || move == 'D') return MOV_RIGHT; if (move == '*') return MOV_NULL; return 0; } void DisplayMap(Game2048& mygame) { BeginBatchDraw(); cleardevice(); char temp[20] = { 0 }; system("cls"); cout << mygame.GetScore() << " " << mygame.GetStep() << " " << mygame.GetUsedTime()<<" " << mygame.GetMaxNum() << endl; for (int i = 0; i


