Advertisement
AlezM

TicTacToe

Aug 3rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // TicTacToe.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. char map[9] = {
  10.     '1', '2', '3',
  11.     '4', '5', '6',
  12.     '7', '8', '9'
  13. };
  14.  
  15. void Frame() {
  16.     system("cls");
  17.  
  18.     cout << "   |   |   " << endl;
  19.     cout << " " << map[6] << " | " << map[7] << " | " << map[8] << endl;
  20.     cout << "___|___|___" << endl;
  21.     cout << "   |   |   " << endl;
  22.     cout << " " << map[3] << " | " << map[4] << " | " << map[5] << endl;
  23.     cout << "___|___|___" << endl;
  24.     cout << "   |   |   " << endl;
  25.     cout << " " << map[0] << " | " << map[1] << " | " << map[2] << endl;
  26.     cout << "   |   |   " << endl;
  27. }
  28.  
  29. bool CheckWin() {
  30.  
  31.  
  32.     return false;
  33. }
  34.  
  35. int main()
  36. {
  37.     int step = 0;
  38.     int choice;
  39.     char xo[2] = { 'X', 'O' };
  40.  
  41.     Frame();
  42.     while (step < 9) {
  43.         cout << "Step of: " << xo[step % 2] << endl;;
  44.  
  45.         while (true) {         
  46.             cin >> choice;
  47.             if (map[choice - 1] != xo[0] && map[choice - 1] != xo[1]) {
  48.                 map[choice - 1] = xo[step % 2];
  49.                 break;
  50.             }
  51.             else
  52.                 cout << "Try again." << endl;
  53.         }  
  54.         step++;
  55.         Frame();
  56.  
  57.         if (step > 5) {
  58.             if ( CheckWin() ) {
  59.                 cout << "Win " << xo[step % 2];
  60.                 break;
  61.             }
  62.         }
  63.     }
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement