diff --git a/MineSweeper/Gaming.cpp b/MineSweeper/Gaming.cpp index 8f26f6a..03c7ee1 100644 --- a/MineSweeper/Gaming.cpp +++ b/MineSweeper/Gaming.cpp @@ -13,6 +13,7 @@ HBITMAP g_hbmBut[4] = { NULL }; HANDLE hHandle = NULL; HANDLE TimerID_1s = NULL; _Blocks game_map; +std::vector <_Ranker> __Easy, __Normal, __Hard; int allNums[7]; int __ROW__ = 10, __COL__ = 10, __MINE__ = 10; //int step[8][2] = { {1, 1}, {1, -1}, {-1, 1}, @@ -170,6 +171,72 @@ void StrtoInt(int* x, wchar_t* str) } } +int GetMode() +{ + if (__MINE__ == 10 && __COL__ == 10 && __ROW__ == 10) + { + return 1; + } + else if (__MINE__ == 40 && __COL__ == 16 && __ROW__ == 16) + { + return 2; + } + else if (__MINE__ == 99 && __COL__ == 30 && __ROW__ == 16) + { + return 3; + } + return 0; +} + +void AddnewScore(int utime, wchar_t* uname) +{ + _Ranker tmp = { utime, {0} }; + switch (GetMode()) + { + case 1: + memcpy(tmp.usrname, uname, sizeof(char) * 20); + __Easy.push_back(tmp); + std::sort(__Easy.begin(), __Easy.end()); + break; + case 2: + memcpy(tmp.usrname, uname, sizeof(char) * 20); + __Normal.push_back(tmp); + std::sort(__Normal.begin(), __Normal.end()); + break; + case 3: + memcpy(tmp.usrname, uname, sizeof(char) * 20); + __Hard.push_back(tmp); + std::sort(__Hard.begin(), __Hard.end()); + break; + } +} + +bool IfnewFirst(int utime) +{ + if (__MINE__ == 10 && __COL__ == 10 && __ROW__ == 10) + { + if (__Easy.empty() || __Easy.size() < 3) + return true; + else if (utime <= __Easy[2].usrtime) + return true; + } + if (__MINE__ == 40 && __COL__ == 16 && __ROW__ == 16) + { + if (__Normal.empty() || __Normal.size() < 3) + return true; + else if (utime <= __Normal[2].usrtime) + return true; + } + if (__MINE__ == 99 && __COL__ == 30 && __ROW__ == 16) + { + if (__Hard.empty() || __Hard.size() < 3) + return true; + else if (utime <= __Hard[2].usrtime) + return true; + } + return false; +} + void InitNUMPADs() { g_hbmNum[0] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(164)); @@ -295,10 +362,43 @@ int GetGame(int choose) case 3: return __MINE__; break; + case 4: + return game_map.game_state; + break; + case 5: + return game_map.time_now; + break; } return 0; } +_Ranker GetRanker(int opt, int rank) +{ + switch (opt) { + case 1: + if (__Easy.size() < rank) + { + return { -1, {0} }; + } + return __Easy[static_cast>::size_type>(rank) - 1]; + break; + case 2: + if (__Normal.size() < rank) + { + return { -1, {0} }; + } + return __Normal[static_cast>::size_type>(rank) - 1]; + break; + case 3: + if (__Hard.size() < rank) + { + return { -1, {0} }; + } + return __Hard[static_cast>::size_type>(rank) - 1]; + break; + } +} + VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired) { game_map.time_now++; GetNums(); diff --git a/MineSweeper/Gaming.h b/MineSweeper/Gaming.h index 7ad66b3..81eff68 100644 --- a/MineSweeper/Gaming.h +++ b/MineSweeper/Gaming.h @@ -1,7 +1,12 @@ #pragma once +#include "Themap.h" #include "framework.h" #include "MineSweeper.h" +#include +#include +#include +#include void MapPainting(HWND hwnd); void InitNUMPADs(); @@ -17,4 +22,7 @@ void GameStart(HWND hwnd); void ReSizeGameWnd(HWND hwnd); void InttoStr(int x, wchar_t* str); void StrtoInt(int* x, wchar_t* str); -int GetGame(int choose); \ No newline at end of file +void AddnewScore(int utime, wchar_t* uname); +bool IfnewFirst(int utime); +int GetGame(int choose); +_Ranker GetRanker(int opt, int rank); \ No newline at end of file diff --git a/MineSweeper/MineSweeper.aps b/MineSweeper/MineSweeper.aps index 0fa5e1f..4c68c04 100644 Binary files a/MineSweeper/MineSweeper.aps and b/MineSweeper/MineSweeper.aps differ diff --git a/MineSweeper/MineSweeper.cpp b/MineSweeper/MineSweeper.cpp index 77d9ec0..e83fb59 100644 --- a/MineSweeper/MineSweeper.cpp +++ b/MineSweeper/MineSweeper.cpp @@ -18,6 +18,8 @@ BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK Setting(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK Rankboard(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK Congratulat(HWND, UINT, WPARAM, LPARAM); int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, @@ -117,6 +119,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) GameRestart(); InvalidateRect(hWnd, NULL, TRUE); break; + case IDM_RANKS: + DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hWnd, Rankboard); + break; case IDM_BEGINNER: SetGame(10, 10, 10); GameRestart(); @@ -160,12 +165,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) x = GET_Y_LPARAM(lParam); } Lclick(x, y, hWnd); - //RECT bloClient; - //GetClientRect(hWnd, &bloClient); - //SetRect(&bloClient, bloClient.left, bloClient.top + 25, bloClient.right, bloClient.bottom); - InvalidateRect(hWnd, NULL, TRUE); - //UpdateWindow(hWnd); + if (GetGame(4) == 2) + { + if (IfnewFirst(GetGame(5))) + { + DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hWnd, Congratulat); + } + } } break; case WM_RBUTTONDOWN: @@ -178,8 +185,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } Rclick(x, y, hWnd); MapPainting(hWnd); - InvalidateRect(hWnd, NULL, TRUE); - //UpdateWindow(hWnd); + InvalidateRect(hWnd, NULL, TRUE); + if (GetGame(4) == 2) + { + if (IfnewFirst(GetGame(5))) + { + DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hWnd, Congratulat); + } + } } break; case WM_PAINT: @@ -219,6 +232,74 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return (INT_PTR)FALSE; } +INT_PTR CALLBACK Congratulat(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + else if (LOWORD(wParam) == IDOK) + { + wchar_t* stri; + stri = (wchar_t*)malloc(sizeof(wchar_t) * 20); + if (stri != NULL) + GetDlgItemTextW(hDlg, IDC_EDIT2, stri, 10); + AddnewScore(GetGame(5), stri); + EndDialog(hDlg, LOWORD(wParam)); + } + break; + } + return (INT_PTR)FALSE; +} + +INT_PTR CALLBACK Rankboard(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + { + _Ranker tmp = { 0, {0} }; + wchar_t* stri; + stri = (wchar_t*)malloc(sizeof(wchar_t) * 5); + if (stri != NULL) + memset(stri, 0, sizeof(stri)); + for (int i = 1; i <= 3; i++) + { + for (int j = 1; j <= 3; j++) + { + tmp = GetRanker(i, j); + if (tmp.usrtime != -1) + { + SetDlgItemTextW(hDlg, 1008 + (i - 1) * 6 + j, tmp.usrname); + InttoStr(tmp.usrtime, stri); + if (stri != NULL) + SetDlgItemTextW(hDlg, 1008 + (i - 1) * 6 + j + 3, stri); + } + } + } + free(stri); + } + break; + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} + INT_PTR CALLBACK Setting(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { diff --git a/MineSweeper/MineSweeper.rc b/MineSweeper/MineSweeper.rc index e2cf487..54bfcf3 100644 Binary files a/MineSweeper/MineSweeper.rc and b/MineSweeper/MineSweeper.rc differ diff --git a/MineSweeper/Themap.cpp b/MineSweeper/Themap.cpp index 663b0bd..1b3ec3c 100644 --- a/MineSweeper/Themap.cpp +++ b/MineSweeper/Themap.cpp @@ -25,7 +25,7 @@ bool _blocks::JudgeisWin() } if ((cnt1 + cnt2) == (size_col * size_row) || (size_row * size_col - cnt1) == tot_bomb || - flag == true) + flag == 1) { return true; } diff --git a/MineSweeper/Themap.h b/MineSweeper/Themap.h index 8bb20c8..87bb311 100644 --- a/MineSweeper/Themap.h +++ b/MineSweeper/Themap.h @@ -22,4 +22,18 @@ typedef struct _blocks int Flagnum(); int Bombnum(); bool JudgeisWin(); -}_Blocks, *_pBlocks; \ No newline at end of file +}_Blocks, *_pBlocks; + +typedef struct ranker +{ + int usrtime; + wchar_t usrname[20]; + bool operator<(const ranker& y)const + { + return this->usrtime < y.usrtime; + } + bool operator>(const ranker& y)const + { + return this->usrtime > y.usrtime; + } +}_Ranker, *_pRanker; \ No newline at end of file diff --git a/MineSweeper/resource.h b/MineSweeper/resource.h index 68498e6..1cc1a07 100644 --- a/MineSweeper/resource.h +++ b/MineSweeper/resource.h @@ -39,17 +39,42 @@ #define IDB_WINNER 194 #define IDB_LOSSER 195 #define IDD_DIALOG1 196 +#define IDD_DIALOG2 197 +#define IDD_DIALOG3 198 #define IDC_BUTTON1 1000 #define IDC_TAB1 1001 #define IDC_EDIT1 1006 #define IDC_EDIT2 1007 #define IDC_EDIT3 1008 +#define IDC_BEGIN1 1009 +#define IDC_BEGIN2 1010 +#define IDC_BEGIN3 1011 +#define IDC_BEGIN4 1012 +#define IDC_BEGIN5 1013 +#define IDC_BEGIN6 1014 +#define IDC_NORMAL1 1015 +#define IDC_NORMAL2 1016 +#define IDC_NORMAL3 1017 +#define IDC_NORMAL4 1018 +#define IDC_NORMAL5 1019 +#define IDC_NORMAL6 1020 +#define IDC_HARD1 1021 +#define IDC_HARD2 1022 +#define IDC_HARD3 1023 +#define IDC_HARD4 1024 +#define IDC_HARD5 1025 +#define IDC_HARD6 1026 +#define IDC_BEGIN18 1027 #define IDM_NEWGAME 32778 #define IDM_BEGINNER 32780 #define IDM_MEDIATE 32782 #define IDM_EXPERT 32783 #define ID_32784 32784 #define IDM_CUSTOM 32785 +#define ID_32786 32786 +#define ID_32787 32787 +#define ID_RANKS 32788 +#define IDM_RANKS 32789 #define IDC_STATIC -1 // Next default values for new objects @@ -57,9 +82,9 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 197 -#define _APS_NEXT_COMMAND_VALUE 32786 -#define _APS_NEXT_CONTROL_VALUE 1006 +#define _APS_NEXT_RESOURCE_VALUE 199 +#define _APS_NEXT_COMMAND_VALUE 32790 +#define _APS_NEXT_CONTROL_VALUE 1014 #define _APS_NEXT_SYMED_VALUE 122 #endif #endif