-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode2.c
150 lines (116 loc) · 2.94 KB
/
code2.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
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
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<%
int navigate(char arr[3][3], int box, int player, int key)
{
switch(key)
{
case UPARROW : if( (box!=1) || (box!=2) || (box!=3) )
{ box-=3; if(box<1) box = 1; gotobox(box); }
break;
case DOWNARROW : if( (box!=7) || (box!=8) || (box!=9) )
{ box+=3; if(box>9) box = 9; gotobox(box); }
break;
case LEFTARROW : if( (box!=1) || (box!=4) || (box!=7) )
{ box--; if(box<1) box = 1; gotobox(box); }
break;
case RIGHTARROW : if( (box!=3) || (box!=6) || (box!=9) )
{ box++; if(box>9) box = 9; gotobox(box); }
break;
case ENTER : if(player == 0)
putintobox(arr,'O',box);
else if(player == 1)
putintobox(arr,'X',box);
break;
}//end of switch(key)
return box;
}
#include "conio.h"
int main()
{
/*
Declaration of variables used
*/
showframe(12,25);
printf("\nPlayer 1, enter your name:"); fgets(name[0], 30, stdin);
printf("\nPlayer 2, enter your name:"); fgets(name[1], 30, stdin);
printf("\n%s, you take 0",name[0]);
printf("\n%s, you take X",name[1]); getch();
clrscr();
do
{
while(!enter)
{
if(khbit())
ch = getch();
switch(ch)
{
case UPARROW : box = navigate(a[3][3], box, player, UPARROW);
}
}
if(quit) break;
//check if the player wins
win = checkforwin(a);
}while(!win);
if(win)
{
}
else if(quit)
{
}
return 0;
}
int main()
{
// FILE *fh;
int ch;
fh = fopen("ascii.txt","r");
for(i=0;i<256;i++){
fprint(fh,"\n%d - %c",i,i);
}
fclose(fh);
return 0;
}
int boxesleft(char a[3][3])
{
int i,j,boxesleft=9;
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{ if((a[i][j] == 'X') ||(a[i][j] == 'O'))
boxesleft--;
}
}
return boxesleft;
}
int checkforwin(char arr[3][3])
{
int w=0;
/* 0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2
*/
//rows
if((arr[0][0] == arr[0][1]) && (arr[0][1] == arr[0][2])) w = 1;
else if((arr[1][0] == arr[1][1]) && (arr[1][1] == arr[1][2])) w = 1;
else if((arr[2][0] == arr[2][1]) && (arr[2][1] == arr[2][2])) w = 1;
//coloums
else if((arr[0][0] == arr[1][0]) && (arr[1][0] == arr[2][0])) w = 1;
else if((arr[0][1] == arr[1][1]) && (arr[1][1] == arr[2][1])) w = 1;
else if((arr[0][2] == arr[1][2]) && (arr[1][2] == arr[2][2])) w = 1;
//diagonal
else if((arr[0][0] == arr[1][1]) && (arr[1][1] == arr[2][2])) w = 1;
else if((arr[0][2] == arr[1][1]) && (arr[1][1] == arr[2][0])) w = 1;
return w;
}
//Function to handle the navigation
%>
<div>
</body>
</html>