I need to write a tic tac toe game. What I would like it do is
1) keep track of the number of games won by the 2 players and the tie games.
2) each time a move is made the grid recompiles and shows all the moves that have been made.
3) as soon as a player gets 3 in a row the game states who the winner is and adds the win to the correct player.
4) i am setting up each function in its own file.
header file:
#ifndef TICTACTOE_h
#define TICTACTOE_h
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
const int SCR_W=80;
const int SCR_H=25;
const int BOARD_W=14;
const int BOARD_H=8;
const char PLAYER_1 = X;
//const char PLAYER_2 = O;
//helper functions
/*void collabels();
void drawrowvirt();
void drawrowhorz();
void drawrowplayer (char row [3], int rownumber);*/
void extern initboard(char board[3][3]);
void extern drawboard(char board[3][3]);
void extern player1 (char);
//void extern player2 (char);
#endif
main:
#include "tictactoe.h"
void drawboard (char board [3][3]);
void initboard (char board [3][3]);
void collabels();
void drawrowvirt();
void drawrowhorz();
void drawrowplayer (char row [3], int rownumber);
int row, column;
int main ()
{
system ("color b");
char board [3][3];
initboard (board);
drawboard (board);
for (int i = 0; i <5; ++i)
cout << endl;
system ("PAUSE");
}
void initboard(char board[3][3])
{
for(int i=0,j;i<3;++i)
for(j=0;j<3;++j)
board[i][j]=' ';
}
void drawboard(char board[3][3])
{
system("cls");
cout << "Player 1" << setw (32) <<right
<< "Tie" <<setw (40)<<right
<< "Player 2" ;
for(int i=0;i<5;++i)
cout<<endl;
collabels();
for(int i=0;i<2;++i)
{
drawrowvirt();
drawrowplayer(board[i],i+1);
drawrowhorz();
}
drawrowvirt();
drawrowplayer(board[2],3);
}
void collabels()
{
cout<<setw((SCR_W/2)-(BOARD_W/2)) <<' ' <<"C1"<<setw (3)<<' ' <<"C2"<<setw (3)<<' ' <<"C2"<<endl<<endl;
}
void drawrowvirt()
{
cout<<setw( 3 + (SCR_W/2)-(BOARD_W/2) )<<' '<<(char)186<<setw(3)<<' '<<(char)186<<endl;
}
void drawrowhorz()
{
cout<<setw( (SCR_W/2)-(BOARD_W/2) )<<' '<<left;
cout<<setfill((char)205);
cout<<setw(3)<<""<<(char)206<<setw(3)<<""<<(char)206<<setw(3)<<""<<endl;
cout<<setfill(' ');
}
void drawrowplayer(char row[3],int rownumber)
{
cout<<setw( -3 + ((SCR_W/2)-(BOARD_W/2)) )<<' '<<'R'<<rownumber<<" "<<row[0]<<' '<<(char)186<<' '<<row[1]<<' '<<(char)186<<' '<<row[2]<<endl;
}
player 1:
#include "tictactoe.h"
void player1 (ttt_array)
{
cout << "Player 1 enter a row number 1, 2 or 3\n";
cin >> row;
cout <<"Player 1 enter a column number 1, 2 or 3\n";
cin >> column;
}
this is as far as i have gotten I am stuck. it does display with no errors.
can any one help?
Idealy if i could turn the const's into private functions would be great.
thanks
happy
Last edited on