Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class board{
- public:
- void show();
- char squares [9];
- };
- void board::show(){
- cout << endl;
- for ( int i = 0; i < 9; i++){
- if (i % 3 == 0)
- cout << " ";
- cout << squares[i];
- if ( i % 3 == 0 || i ==1 || i == 4 || i == 7)
- cout << " | ";
- if (i != 0 && (i+1)%3 == 0){
- cout << endl;
- if ( i != 8)
- cout << " ----------";
- cout << endl;
- }
- }
- cout << endl;
- }
- void play(char player, unsigned int square){
- board1.squares[square] = player;
- }
- int main(){
- board board1;
- for (int i = 0; i < 9; i++)
- board1.squares[i]= i+1+48;
- board1.show();
- bool gameOver = 0;
- unsigned int first = rand()%1 + 1;
- unsigned int square;
- unsigned int round = 1;
- while (gameOver != 0){
- if (round % 2 != 0){
- cout << "It's player X's turn: " << endl << "Where do you want to play?\n";
- cin >> square;
- play('X',square);
- }
- else{
- cout << "It's player O's turn: " << endl << "Where do you want to play?\n";
- cin >> square;
- play('O',square);
- }
- cout << endl << endl;
- board1.show();
- round++;
- if (round == 4)
- gameOver = 1;
- return 0;
- }
Add Comment
Please, Sign In to add comment