-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystem.cpp
139 lines (119 loc) · 1.98 KB
/
System.cpp
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
134
135
136
137
138
139
#include "TicTacToe.h"
//定义隐藏光标函数
void showCursor(bool bolean)
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = bolean;
cursor.dwSize = sizeof(cursor);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
}
void input()
{
unsigned int input;
while (1) {
if (cin >> input)
break;
else
{
cout << "error, please try again." << endl;
cin.clear();
cin.ignore(8192, '\n');
continue;
}
}
switch (input)
{
case 1:
{
TicTacToe TTT;
srand((unsigned)time(NULL));
unsigned int rows, columns;
TTT.whoseRound = rand() % 2;
if (TTT.whoseRound)
goto AI;
while (1)
{
if (TTT.showTheEnd())
return;
while (1) {
if (cin >> rows >> columns && TTT.setDots(rows - 1, columns - 1))
break;
else
{
cout << "error, please try again." << endl;
cin.clear();
cin.ignore(4096, '\n');
continue;
}
}
if (TTT.showTheEnd())
return;
AI:
srand((unsigned)time(NULL));
Sleep(rand() % 1200 + 500);
TTT.AI_setDots();
}
}
case 2:
{
TicTacToe TTT;
while (1)
{
if (TTT.showTheEnd())
return;
unsigned int rows, columns;
while (1) {
if (cin >> rows >> columns)
break;
else
{
cout << "error, please try again." << endl;
cin.clear();
cin.ignore(4096, '\n');
continue;
}
}
TTT.setDots(rows - 1, columns - 1);
if (TTT.showTheEnd())
return;
}
}
case 3:
{
int num;
while (1) {
if (cin >> num)
break;
else
{
cout << "error, please try again." << endl;
cin.clear();
cin.ignore(4096, '\n');
continue;
}
}
if (num == 8)
{
TicTacToe::_3_8_Mode = true;
}
else
{
break;
}
}
default:
break;
}
}
int main()
{
showCursor(false);
while (1)
{
TicTacToe::showMenu();
input();
system("cls");
}
return 0;
}