From 1438fee45dda283a6d709f41018628ddca771e46 Mon Sep 17 00:00:00 2001 From: TcMcKrLiTb <3161371343@qq.com> Date: Wed, 16 Nov 2022 14:34:05 +0800 Subject: [PATCH] 2.0! --- MineSweeper/Gaming.cpp | 126 ++++++++++++++++++++++++++++++------ MineSweeper/Gaming.h | 7 +- MineSweeper/MineSweeper.aps | Bin 81460 -> 82456 bytes MineSweeper/MineSweeper.cpp | 115 ++++++++++++++++++++++++++++++-- MineSweeper/MineSweeper.rc | Bin 11846 -> 14286 bytes MineSweeper/Themap.cpp | 49 ++++++++++++-- MineSweeper/Themap.h | 1 + MineSweeper/resource.h | 16 ++++- README.md | 18 ++++++ 9 files changed, 295 insertions(+), 37 deletions(-) diff --git a/MineSweeper/Gaming.cpp b/MineSweeper/Gaming.cpp index a2e4768..a107798 100644 --- a/MineSweeper/Gaming.cpp +++ b/MineSweeper/Gaming.cpp @@ -12,13 +12,15 @@ HBITMAP g_hbmBlo[14] = { NULL }; HBITMAP g_hbmBut[4] = { NULL }; HANDLE hHandle = NULL; HANDLE TimerID_1s = NULL; -int allNums[7]; _Blocks game_map; +int allNums[7]; +int __ROW__ = 10, __COL__ = 10, __MINE__ = 10; void MapPainting(HWND hwnd) { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); HDC hdcMem = CreateCompatibleDC(hdc); + GetNums(); ButPainting(&ps, &hdc, &hdcMem, game_map.game_state); NumPainting(&ps, &hdc, &hdcMem, ((game_map.size_col) * 25) - 39, allNums[1], allNums[2], allNums[3], allNums[4], allNums[5], allNums[6]); //Sleep(1000); @@ -138,6 +140,34 @@ void ReSizeGameWnd(HWND hwnd) TRUE); } +void InttoStr(int x, wchar_t* str) +{ + int i = 0; + while (x) + { + str[i] = (x % 10) + '0'; + x /= 10; + i++; + } + for (int j = 0; j < i / 2; j++) + { + wchar_t t = str[j]; + str[j] = str[i - j - 1]; + str[i - j - 1] = t; + } +} + +void StrtoInt(int* x, wchar_t* str) +{ + int len = 0; + *x = 0; + while (str[len++] != 0); + for (int i = 0; i < len - 1; i++) { + *x *= 10; + *x += str[i] - '0'; + } +} + void InitNUMPADs() { g_hbmNum[0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(164)); @@ -148,7 +178,7 @@ void InitNUMPADs() void InitBLOCKs() { game_map.game_state = 0; - game_map.InitBox(10, 10); + game_map.InitBox(__ROW__, __COL__); for (int i = 1; i <= 13; i++) g_hbmBlo[i] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE((int)(173 + i) - 1)); } @@ -161,7 +191,6 @@ void GameOver(bool winorlose) { if (Result) { ; } - } else { @@ -183,6 +212,44 @@ void GameOver(bool winorlose) { } } +void GameRestart() +{ + if (TimerID_1s != NULL) + { + if (game_map.game_state == 1) + { + BOOL Result = DeleteTimerQueueTimer(hHandle, TimerID_1s, NULL); + if (Result) { + ; + } + } + } + game_map.time_now = 0; + GetNums(); + game_map.game_state = 0; + game_map.InitBox(__ROW__, __COL__); + return; +} + +void JudgeNum(int* x, int choose) +{ + switch (choose) + { + case 1: + *x = *x < 1 ? 1 : *x; + *x = *x > 34 ? 34 : *x; + break; + case 2: + *x = *x < 4 ? 4 : *x; + *x = *x > 60 ? 60 : *x; + break; + case 3: + *x = *x < 1 ? 1 : *x; + *x = *x > ((__ROW__ * __COL__) - 1) ? ((__ROW__ * __COL__) - 1) : *x; + break; + } +} + void GetNums() { int num1 = game_map.Bombnum(); int num2 = game_map.time_now; @@ -193,6 +260,30 @@ void GetNums() { } } +void SetGame(int row, int col, int mine) +{ + __ROW__ = row; + __COL__ = col; + __MINE__ = mine; + return; +} + +int GetGame(int choose) +{ + switch (choose) + { + case 1: + return __ROW__; + break; + case 2: + return __COL__; + break; + case 3: + return __MINE__; + break; + } +} + VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired) { game_map.time_now++; GetNums(); @@ -233,7 +324,7 @@ void Lclick(int x, int y, HWND hwnd) if (game_map.game_state == 0) { GameStart(hwnd); - game_map.RandomSetMines(x, y, 10); + game_map.RandomSetMines(x, y, __MINE__); } if (game_map._vis[x][y] == false) { @@ -257,7 +348,16 @@ void Lclick(int x, int y, HWND hwnd) game_map._vis[x][y] = true; } } - if (game_map.JudgeisWin() == true) { + if (game_map.JudgeisWin() == true) + { + for (int i = 1; i <= game_map.size_row; i++) + { + for (int j = 1; j <= game_map.size_col; j++) + { + if (game_map._Block[i][j] == -1) + game_map._flag[i][j] = true; + } + } GameOver(true); } } @@ -265,21 +365,7 @@ void Lclick(int x, int y, HWND hwnd) { if (y > (10 + (25 * (game_map.size_col + 1))) / 2 - 23 && y < (10 + (25 * (game_map.size_col + 1))) / 2 + 22) { - if (TimerID_1s != NULL) - { - if (game_map.game_state == 1) - { - BOOL Result = DeleteTimerQueueTimer(hHandle, TimerID_1s, NULL); - if (Result) { - ; - } - } - } - game_map.time_now = 0; - GetNums(); - game_map.game_state = 0; - game_map.InitBox(10, 10); - + GameRestart(); } } } diff --git a/MineSweeper/Gaming.h b/MineSweeper/Gaming.h index add4461..7ad66b3 100644 --- a/MineSweeper/Gaming.h +++ b/MineSweeper/Gaming.h @@ -9,7 +9,12 @@ void InitBLOCKs(); void Lclick(int x, int y, HWND hwnd); void Rclick(int x, int y, HWND hwnd); void GetNums(); +void SetGame(int row, int col, int mine); void GameOver(bool winorlose); +void GameRestart(); +void JudgeNum(int* x, int choose); void GameStart(HWND hwnd); void ReSizeGameWnd(HWND hwnd); -void ReSizeFameWnd(HWND hwnd); \ No newline at end of file +void InttoStr(int x, wchar_t* str); +void StrtoInt(int* x, wchar_t* str); +int GetGame(int choose); \ No newline at end of file diff --git a/MineSweeper/MineSweeper.aps b/MineSweeper/MineSweeper.aps index 5e117ae519ff4f3875d96e4c1402205b1ae261bf..3547521100b181325d5853f7eae6709483cb5019 100644 GIT binary patch delta 2418 zcmZ`)ZETZO6h61@3hTDE`)b#Zbz^P}fkC^kb_1tlEz7cgvAzr((-IIFGA1ENA|b9b z{2=~N^dPq@U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