No older revisions available
No older revisions available
const up = 0x48;
const down = 0x50;
const right = 0x4d;
const left = 0x4b;
const esc = 0x1b;
const space = 0x20;
void checkomok(int, int, char);
void checkcount(int check[], int , char);
char board[19][19];
int main()
{
int i,j;
clrscr();
for(i=0; i<19; i++)
{
for(j=0; j<19; j++)
{
board[i][j] = '+';
printf("%c ", board[i][j]);
}
printf("\n");
}
int key;
int user = 1;
int x = 1; int y = 1;
gotoxy(x,y);
do{
key = getch();
if (key == NULL)
{
key = getch();
if (key == up)
{ if(y > 1)
gotoxy(x,--y);
}
else if (key == down)
{ if (y <= 18)
gotoxy(x,++y);
}
else if (key == right)
{ if (x <= 36 )
gotoxy(++++x, y);
}
else if (key == left)
{ if (x > 1)
gotoxy(----x, y);
}
else
printf ("error");
}
if (key == space)
{ if (user == 1 && board[x/2][y-1] == '+')
{
printf("@");
board[x/2][y-1] = '@';
checkomok(x/2, y-1,'@');
user = 2;
}
else if (user == 2 && board[x/2][y-1] == '+')
{
printf("*");
board[x/2][y-1] = '*';
checkomok(x/2,y-1, '*');
user = 1;
}
}
}while(key != esc);
return 0;
}
void checkomok(int row, int col, char mark)
{
int count;
int check[4] = {0, };
if (board[row-1][col] == mark || board[row+1][col] == mark)
{
count = 1;
if (board[row-1][col] == mark)
{
while(board[row-1][col] == mark)
{
row--; count++;
}
}
if (board[row+1][col] == mark)
{
row = row + count-1;
while(board[row+1][col] == mark)
{
row++; count++;
}
}
check[0] = count;
}
if (board[row][col-1] == mark || board[row][col+1] == mark)
{
count = 1;
if (board[row][col-1] == mark)
{
while(board[row][col-1] == mark)
{
col--; count++;
}
}
if (board[row][col+1] == mark)
{
col = col + count-1;
while(board[row][col+1] == mark)
{
col++; count++;
}
}
check[1] = count;
}
if (board[row+1][col-1] == mark || board[row-1][col+1] == mark)
{
count = 1;
if (board[row+1][col-1] == mark)
{
while(board[row+1][col-1] == mark)
{
row++; col--; count++;
}
}
if (board[row-1][col+1] == mark)
{
col = col + count-1;
row = row - count+1;
while(board[row-1][col+1] == mark)
{
row--; col++; count++;
}
}
check[2] = count;
}
if (board[row+1][col+1] == mark || board[row-1][col-1] == mark)
{
count = 1;
if (board[row+1][col+1] == mark)
{
while(board[row+1][col+1] == mark)
{
row++; col++; count++;
}
}
if (board[row-1][col-1] == mark)
{ row = row - count+1;
col = col - count+1;
while(board[row-1][col-1] == mark)
{
row--; col--; count++;
}
}
check[3] = count;
}
checkcount(check, 4, mark);
}
void checkcount(int check[], int size, char mark)
{
for(int i=0; i<size; i++)
{
if ( check[i] == 5)
{
gotoxy(1,22);
printf("%c ", mark);
printf("is win!!\n");
getch();
exit(1);
}
}
}
----
["Omok"]