-
Notifications
You must be signed in to change notification settings - Fork 0
/
WUZUQI.cpp
125 lines (116 loc) · 2.38 KB
/
WUZUQI.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
#include <graphics.h>
#include <iostream>
using namespace std;
int a[15][15] = { 0 };
MOUSEMSG mouse;
int tx[4][9] = { {4,3,2,1,0,-1,-2,-3,-4}, {0,0,0,0,0,0,0,0,0}, {4,3,2,1,0,-1,-2,-3,-4}, {4,3,2,1,0,-1,-2,-3,-4} };
int ty[4][9] = { {0,0,0,0,0,0,0,0,0}, {4,3,2,1,0,-1,-2,-3,-4}, {4,3,2,1,0,-1,-2,-3,-4}, {-4,-3,-2,-1,0,1,2,3,4} };
void init();
int change(int k);
void draw_Black(int x, int y);
void draw_White(int x, int y);
bool check_win(int person, int x, int y);
void show(int person);
int main() {
init();
FlushMouseMsgBuffer();
int x, y;
int person = 1;
while (1) {
mouse = GetMouseMsg();
if (mouse.uMsg == WM_LBUTTONDOWN) {
x = change(mouse.x);
y = change(mouse.y);
if (x >= 0 && x < 15 && y >= 0 && y < 15) {
if (a[x][y] == 0) {
if (person == 1) {
draw_Black(x, y);
a[x][y] = person;
if (check_win(person, x, y)) {
show(person);
system("pause");
}
person = 2;
}
else {
draw_White(x, y);
a[x][y] = person;
if (check_win(person, x, y)) {
show(person);
system("pause");
}
person = 1;
}
}
}
}
}
}
void init() {
initgraph(720, 600);
setlinecolor(WHITE);
for (int i = 50; i <= 500; i += 30) {
line(50, i, 500, i);
}
for (int i = 50; i <= 500; i += 30) {
line(i, 50, i, 500);
}
}
int change(int k) {
int n = (k - 50) / 30;
int n1 = (k - 50) % 30;
if (n1 > 0) {
n = n + 1;
}
return n - 1;
}
void draw_Black(int x, int y) {
setfillcolor(BLACK);
int x1 = 50 + x * 30 + 15;
int y1 = 50 + y * 30 + 15;
fillcircle(x1, y1, 10);
}
void draw_White(int x, int y) {
setfillcolor(WHITE);
int x1 = 50 + x * 30 + 15;
int y1 = 50 + y * 30 + 15;
fillcircle(x1, y1, 10);
}
bool check_win(int person, int x, int y) {
int x1, y1;
for (int i = 0; i < 4; i++) {
for (int j = 0, k = 4; k < 9; j++, k++) {
int bo = false;
for (int w = j; w <= k; w++) {
x1 = x + tx[i][w];
y1 = y + ty[i][w];
if (x1 < 0 || x1 >= 15 || y1 < 0 || y1 >= 15) {
bo = true;
break;
}
if (a[x1][y1] != person) {
bo = true;
break;
}
}
if (bo) {
continue;
}
else {
return true;
}
}
}
return false;
}
void show(int person) {
cleardevice();
settextcolor(RGB(60, 100, 150));
settextstyle(80, 20, _T("微软雅黑"));
if (person == 1) {
outtextxy(130, 350, _T("黑方胜!"));
}
else {
outtextxy(130, 350, _T("白方胜!"));
}
}