Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- //---------------------------------------------------------------
- char board[9] = {'1','2','3','4','5','6','7','8','9'}; //variables.
- char pl1 = 'X';
- char pl2 = 'O';
- int choice;
- int i= 0;
- int ii;
- cout << pl1 << endl;
- cout << pl2 << endl;
- //----------------------------------------------------------------
- cout << "Welcome to the Tic Tac Toe game!\n" << "------------------------" << "\n\n";
- cout << "Player 1 has" " " << pl1;
- cout << "\nPlayer 2 has" " " << pl2 << endl << endl;
- //----------------------------------------------------------------
- for (int i = 0; i <= 6; i++);
- {
- cout << board[0] << "|" << board[1] << "|" << board[2] << endl; //board creation(9 times...).
- cout << board[3] << "|" << board[4] << "|" << board[5] << endl;
- cout << board[6] << "|" << board[7] << "|" << board[8] << endl << endl;
- //-----------------------------------------------------------------
- cout << "Player's 1 turn:";
- cin >> choice;
- switch (choice)
- {
- case 1:(choice == 1);
- board[0] = pl1;
- break;
- case 2:(choice == 2);
- board[1] = pl1;
- break;
- case 3:(choice == 3);
- board[2] = pl1;
- //boardFull();
- break;
- case 4:(choice == 4);
- board[3] = pl1;
- //boardFull();
- break;
- case 5:(choice == 5);
- board[4] = pl1;
- //boardFull();
- break;
- case 6:(choice == 6);
- board[5] = pl1;
- //boardFull();
- break;
- case 7:(choice == 7);
- board[6] = pl1;
- break;
- case 8:(choice == 8);
- board[7] = pl1;
- break;
- case 9:(choice == 9);
- board[8] = pl1;
- //boardFull();
- break;
- }
- //--------------------------------------------------------------------------------
- cout << board[0] << "|" << board[1] << "|" << board[2] << endl; //board creation(9 times...).
- cout << board[3] << "|" << board[4] << "|" << board[5] << endl;
- cout << board[6] << "|" << board[7] << "|" << board[8] << endl << endl;
- //--------------------------------------------------------------------------------
- cout << "Player's 2 turn:";
- cin >> choice;
- switch (choice)
- {
- case 1:(choice == 1);
- board[0] = pl2;
- break;
- case 2:(choice == 2);
- board[1] = pl2;
- break;
- case 3:(choice == 3);
- board[2] = pl2;
- break;
- case 4:(choice == 4);
- board[3] = pl2;
- break;
- case 5:(choice == 5);
- board[4] = pl2;
- break;
- case 6:(choice == 6);
- board[5] = pl2;
- break;
- case 7:(choice == 7);
- board[6] = pl2;
- break;
- case 8:(choice == 8);
- board[7] = pl2;
- break;
- case 9:(choice == 9);
- board[8] = pl2;
- break;
- }
- }
- //-----------------------------------------------------------------
- /*void boardFull(){
- for (ii=0; ii < 10; ii++)
- if (board[ii] != pl1 && board[ii] != pl2)
- {
- break;
- }
- }*/
- //-----------------------------------------------------------------
- { if (board[0] == pl1 && board[1] == pl1 && board[2] == pl1)
- cout << "Player 1 won!";
- else if(board[3] == pl1 && board[4] == pl1 && board[5] == pl1)
- cout << "Player 1 won!";
- else if(board[6] == pl1 && board[7] == pl2 && board[8] == pl1)
- cout << "Player 1 won!";
- else if(board[0] == pl2 && board[3] == pl2 && board[6] == pl1)
- cout << "Player 1 won!";
- else if(board[1] == pl1 && board[4] == pl1 && board[7] == pl1)
- cout << "Player 1 won!";
- else if(board[2] == pl1 && board[5] ==pl1 && board[8] == pl1)
- cout << "Player 1 won!";
- else if(board[0] == pl1 && board[4] == pl1 && board[8] == pl1)
- cout << "Player 1 won!";
- else if(board[2] == pl1 && board[4] == pl1 && board[6] == pl1)
- cout << "Player 1 won!";
- }
- //----------------------------------------------------------------
- { if(board[0] == pl2 && board[1] == pl2 && board[2] == pl2)
- cout << "Player 1 won!";
- else if(board[3] == pl2 && board[4] == pl2 && board[5] == pl2)
- cout << "Player 1 won!";
- else if(board[6] == pl2 && board[7] == pl2 && board[8] == pl2)
- cout << "Player 1 won!";
- else if(board[0] == pl2 && board[3] == pl2 && board[6] == pl2)
- cout << "Player 1 won!";
- else if(board[1] == pl2 && board[4] == pl2 && board[7] == pl2)
- cout << "Player 1 won!";
- else if(board[2] = pl2 && board[5] == pl2 && board[8] == pl2)
- cout << "Player 1 won!";
- else if(board[0] == pl2 && board[4] == pl2 && board[8] == pl2)
- cout << "Player 1 won!";
- else if(board[2] == pl2 && board[4] == pl2 && board[6] == pl2)
- cout << "Player 1 won!";
- }
- void func()
- error> {
- blah
- }
- //----------------------------------------------------------------
- char a;
- cin >> a;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement