Here is my code - apologies if I haven't posted it correctly!! I'm having problems displaying the 'O's & 'X's.
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
char board[9];
int TURN = 0;
int MOVE;
//functions
void instructions();
int displayBoard();
void hline (int x, int y, int col);
void vline (int x, int y, int col);
void playgame();
char PLAYER_TURN();
char CPU_TURN();
void drawX(int x, int y);
void drawO(int x, int y);
int checkWinner();
int main()
{
clrscr();
char key; //define a character called key
do
{
cout << "\n\n\n\n\n\n\t\t\t\tTIC TAC TOE\n\n\n\t\t";
cout << "Think You Can Win a Game of Tic Tac Toe?\n\n\n\t\t";
cout << "Please choose one of the following options...\n\n\n";
cout << "\n\tView Instructions Press '1'";
cout << "\n\tStart New Game Press '2'";
cout << "\n\tExit Program Press '3'";
do
{
key= getch();//input choice
}
while (key!='1' && key!='2' && key!='3');
if (key=='1')
{
instructions();
}
if (key=='2')
{
playgame();
}
}
while (key!='3');
}
void instructions()
{
clrscr();
cout << " \n\tPlayer 1 always is always X";
cout << "\n\n\tThe object of the game is to get 3 matching symbols in a row\n\n\tThe grid is numbered as shown below....";
cout << "Press a key to continue...";
gotoxy(20,15);
cout << "0 | 1 | 2\n";
gotoxy(20,16);
cout << "---------\n";
gotoxy(20,17);
cout << "3 | 4 | 5\n";
gotoxy(20,18);
cout << "---------\n";
gotoxy(20,19);
cout << "6 | 7 | 8";
getch();
clrscr();
}
void playgame()
{
int i;
for (i=0;i<10;i++) board[i]= -1;
PLAYER_TURN();
CPU_TURN();
PLAYER_TURN();
CPU_TURN();
PLAYER_TURN();
checkWinner();
CPU_TURN();
checkWinner();
PLAYER_TURN();
checkWinner();
CPU_TURN();
checkWinner();
PLAYER_TURN();
checkWinner();
}
int displayBoard()
{
int i;
clrscr();
hline(5,10,17);
hline(5,16,17);
vline(10,5,17);
vline(16,5,17);
for (i = 0; i<9;i++);
{
if (i == 0)
{
drawX(5,5);
}
else if (i == 1)
{
drawX (11,5);
}
else if (i == 2)
{
drawX (17,5);
}
else if (i == 3)
{
drawX (5,11);
}
else if (i == 4)
{
drawX (11,11);
}
else if (i == 5)
{
drawX (17,11);
}
else if (i == 6)
{
drawX (5,17);
}
else if (i == 7)
{
drawX (11,17);
}
else if (i == 8)
{
drawX (17,17);
}
}
{
if (i == 0)
{
drawO (5,5);
}
else if (i == 1)
{
drawO (11,5);
}
else if (i == 2)
{
drawO (17,5);
}
else if (i == 3)
{
drawO (5,11);
}
else if (i == 4)
{
drawO (11,11);
}
else if (i == 5)
{
drawO (17,11);
}
else if (i == 6)
{
drawO (5,17);
}
else if (i == 7)
{
drawO (11,17);
}
else if (i == 8)
{
drawO (17,17);
}
return 0;
}
}
void hline (int x, int y, int col)
{
int i;
textcolor (col);
for (i=0;i<17;i++)
{
gotoxy(i+x,y);
cprintf("%c",219);
}
}
void vline (int x, int y, int col)
{
int i;
textcolor (col);
for (i=0;i<17;i++)
{
gotoxy(x,i+y);
cprintf("%c",219);
}
}
void drawX (int x, int y)
{
gotoxy(x,y+1);
cprintf(" X X");
gotoxy(x,y+2);
cprintf(" X ");
gotoxy(x,y+3);
cprintf(" X X");
}
void drawO (int x, int y)
{
gotoxy(x,y+1);
cprintf(" O ");
gotoxy(x,y+2);
cprintf(" O O");
gotoxy(x,y+3);
cprintf(" O ");
}
char PLAYER_TURN()
{
int i;
int x,y;
board[9];
drawX(x,y);
displayBoard();
{
for (i = 0; i<10;i++);
{
while(board[i] ==! -1);
}
checkWinner();
}
return 0;
}
char CPU_TURN()
{
int i;
int x,y;
board[9];
drawO(x,y);
displayBoard();
for (i = 0; i<10;i++);
{
board[i] == -1;
}
checkWinner();
}
int checkWinner()
{
while(TURN < 10)
{
if (board[0]== 'X' && board[4]== 'X' && board[8]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[6]== 'X' && board[4]== 'X' && board[2]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[0]== 'X' && board[3]== 'X' && board[6]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[1]== 'X' && board[4]== 'X' && board[7]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[2]== 'X' && board[5]== 'X' && board[8]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[0]== 'X' && board[1]== 'X' && board[2]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[3]== 'X' && board[4]== 'X' && board[5]== 'X') {cout<<"Player 1 is the winner";break;}
if (board[6]== 'X' && board[7]== 'X' && board[8]== 'X') {cout<<"Player 1 is the winner";break;}
// Check for Player 2...
if (board[0]== 'O' && board[4]== 'O' && board[8]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[6]== 'O' && board[4]== 'O' && board[2]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[0]== 'O' && board[3]== 'O' && board[6]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[1]== 'O' && board[4]== 'O' && board[7]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[2]== 'O' && board[5]== 'O' && board[8]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[0]== 'O' && board[1]== 'O' && board[2]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[3]== 'O' && board[4]== 'O' && board[5]== 'O') {cout<<"Player 2 is the winner";break;}
if (board[6]== 'O' && board[7]== 'O' && board[8]== 'O') {cout<<"Player 2 is the winner";break;}
}
}