-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
133 lines (121 loc) · 3.73 KB
/
main.cpp
File metadata and controls
133 lines (121 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "plate.h"
#include <iostream>
#include <string>
using namespace std;
int row, col, num_of_mine;
int welcome(){
cout << "Welcome to Minesweeper!\nIt's your first time to play this game, let's configure your game!\nIf you "
"do not know how to play it, type in 'help'. Otherwise, type in 'continue' to start configuring your game." << endl;
string tmp;
cin >> tmp;
if(tmp == "help"){
return 1;
} else {
return 0;
}
}
int configure(){
cout << "Please type in the total number of rows." << endl;
cin >> row;
cout << "Please type in the total number of columns." << endl;
cin >> col;
cout << "Please type in the total number of mines." << endl;
cin >> num_of_mine;
if(num_of_mine <= row * col && num_of_mine >= 0) {
cout << "Your configuration is below. Do you want to start the game now?(y/n)" << endl;
cout << "row: " << row << "\tcol: " << col << "\tmines: " << num_of_mine << endl;
char tmp;
cin >> tmp;
if(tmp == 'y'){
return 1;
} else {
return 0;
}
} else {
return -1;
}
}
int reconfigure(bool with_wrong){
if(with_wrong){
cout << "There is something wrong in your configuration, please reconfigure it.\n";
cout << "row: " << row << "\tcol: " << col << "\tmines: " << num_of_mine << endl;
} else {
cout << "Let's reconfigure your game!" << endl;
}
return configure();
}
int game(){
auto * p = new plate(row, col, num_of_mine);
while(true){
if(p->won() || p->beaten){
if(p->beaten){
cout << "You lose." << endl;
} else {
cout << "You win." << endl;
}
break;
}
string tmp;
cin >> tmp;
if(tmp == "click"){
int pos_row, pos_col;
cin >> pos_row >> pos_col;
p->real_click(pos_row, pos_col);
}
else if(tmp == "mark"){
int pos_row, pos_col;
cin >> pos_row >> pos_col;
p->real_mark(pos_row, pos_col);
}
else if(tmp == "auto"){
int pos_row, pos_col;
cin >> pos_row >> pos_col;
p->real_auto_click(pos_row, pos_col);
}
}
delete p;
cout << "Restart: 1\tReconfigure: 2\tExit: 3" << endl;
int tmp;
cin >> tmp;
return tmp;
}
void help(){
cout << "This is the game's help document. You will know how to play the game here.\n"
"Now you should have known the basic rule of Minesweeper. But in this game, you have to type in all your commands.\n"
"Here are all the three commands available.\n"
"1.You can use 'click' to click some place like this: 'click 4 4', which is like you click 4 4 in normal Minesweeper game.\n"
"2.You can use 'mark' to mark that there's a mine like this: 'mark 4 4'. To clear the mark, just use 'mark 4 4' again.\n"
"3.When you have mark all the mines around a place, you can auto_click the place like this: 'auto 4 4', to click \n"
" all the place around it.\n"
"Now type in 'continue' to continue.\n";
string tmp;
cin >> tmp;
}
void bye(){
cout << "Thanks for playing the game. See you next time!" << endl;
}
int main(){
if(welcome() == 1){
help();
}
int tmp = configure();
while(tmp != 1){
tmp = reconfigure(tmp == -1);
}
while(true){
tmp = game();
if(tmp == 3){
break;
}
else if(tmp == 1){
continue;
}
else if(tmp == 2){
do{
tmp = reconfigure(tmp == -1);
}while(tmp != 1);
}
}
bye();
return 0;
}