-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.c
107 lines (96 loc) · 1.74 KB
/
io.c
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
#include"io.h"
void playGame (array* a, array* b)
{
int select = 0; //input
int x = a->width - 1;
int y = a->height - 1;
char turn = 'x';//who plays
while (select != 'q')
{
printArray(a, x, y);
select = getch();
switch (select)
{
case KEYDOWN:
if (y > 0)
y--;
break;
case KEYUP:
if (y < a->height - 1)
y++;
break;
case KEYRIGHT:
if (x > 0)
x--;
break;
case KEYLEFT:
if (x < a->width - 1)
x++;
break;
case RETURN:
if (canPlay (a, y, x))
{
a->cell[y][x] = turn;
if (turn == 'x')
turn = 'o';
else
turn = 'x';
}
}
if (whoWins (a) == 1)
{
printf("x won\n");
return;
}
else if (whoWins (a) == -1)
{
printf("o won\n");
return;
}
}
}
int getch()
{
int c;
system("stty raw -echo");
c = getchar();
/* Here comez the hackz */
if (c == 27)
{
int c2 = getchar();
if (c2 == 91)
c = - getchar();
else
/* Pretty sure this is wrong. */
c = c2;
}
else if (c == 12) /* ^L */
system("clear");
system("stty sane");
return c;
}
/*void AI (array* a, array* b, char turn)
{
int i, j;
for (j = 0; j < a->height; j++)
{
for (i = 0; i < a->width; i++)
{
if (whoWins(add(b, turn, i, j)) == 1 && turn == 'x' || whoWins(add(b, turn, i, j)) == -1 && turn == 'o')
{
add(a, turn, i, j);
return;
}
pasteArray(a, b);
}
}
for (j = 0; j < a->height; j++)
{
for (i = 0; i < a->width; i++)
{
array* c = initArray (a->width, a->height);
pasteArray(a, c);
AI (array* a, array* c, char turn);
}
}
}TODO*/