Skip to content

Commit

Permalink
3.0has occurred!!
Browse files Browse the repository at this point in the history
  • Loading branch information
TcMcKrLiTb committed Dec 1, 2022
1 parent 7dd5baf commit 82d9b04
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 13 deletions.
100 changes: 100 additions & 0 deletions MineSweeper/Gaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<std::vector<_Ranker, std::allocator<_Ranker>>::size_type>(rank) - 1];
break;
case 2:
if (__Normal.size() < rank)
{
return { -1, {0} };
}
return __Normal[static_cast<std::vector<_Ranker, std::allocator<_Ranker>>::size_type>(rank) - 1];
break;
case 3:
if (__Hard.size() < rank)
{
return { -1, {0} };
}
return __Hard[static_cast<std::vector<_Ranker, std::allocator<_Ranker>>::size_type>(rank) - 1];
break;
}
}

VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired) {
game_map.time_now++;
GetNums();
Expand Down
10 changes: 9 additions & 1 deletion MineSweeper/Gaming.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#pragma once

#include "Themap.h"
#include "framework.h"
#include "MineSweeper.h"
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

void MapPainting(HWND hwnd);
void InitNUMPADs();
Expand All @@ -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);
void AddnewScore(int utime, wchar_t* uname);
bool IfnewFirst(int utime);
int GetGame(int choose);
_Ranker GetRanker(int opt, int rank);
Binary file modified MineSweeper/MineSweeper.aps
Binary file not shown.
95 changes: 88 additions & 7 deletions MineSweeper/MineSweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
{

Expand Down
Binary file modified MineSweeper/MineSweeper.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion MineSweeper/Themap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 15 additions & 1 deletion MineSweeper/Themap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,18 @@ typedef struct _blocks
int Flagnum();
int Bombnum();
bool JudgeisWin();
}_Blocks, *_pBlocks;
}_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;
31 changes: 28 additions & 3 deletions MineSweeper/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,52 @@
#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
//
#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

0 comments on commit 82d9b04

Please sign in to comment.