Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. bool pl1Won();
  5.  
  6. char board[9] = {'o','x','x','o','x','x','o','x','x'};
  7.  
  8. int main()
  9. {
  10. //----------------------------------
  11. char pl1 = 'X';
  12. char pl2 = 'O';
  13. int choice;
  14.  
  15. //----------------------------------------------------------------
  16. cout << "Welcome to the Tic Tac Toe game!\n" << "------------------------" << "\n\n";
  17. cout << "Player 1 has" " " << pl1;
  18. cout << "\nPlayer 2 has" " " << pl2 << endl << endl;
  19. //----------------------------------------------------------------
  20. cout << board[0] << "|" << board[1] << "|" << board[2] << endl;
  21. cout << board[3] << "|" << board[4] << "|" << board[5] << endl;
  22. cout << board[6] << "|" << board[7] << "|" << board[8] << endl << endl;
  23.  
  24. //for()
  25. //{
  26.  
  27. if(pl1Won() == true)
  28. {
  29. cout << "Player 1 has won!";
  30. }
  31.  
  32. //}
  33. //
  34. cin.get();
  35. return 0;
  36. }
  37. bool pl1Won()
  38. {
  39. if (board[2] == 'x' && board[4] == 'x' && board[8] == 'x') // Else if() for the others
  40. {
  41. return true; // Win
  42. }else
  43. {
  44. return false; // Not yet
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement