Воскресенье, 01.12.2024, 00:48 | Приветствую Вас Гость

...

Код

Главная » Статьи » C++

tic-tac-toe

#include <cstdlib>
#include <iostream>

using namespace std;
char matrix[10] = {'-','-','-','-','-','-','-','-','-'};

int DisplayMatrix()
{

cout << matrix[0] << " " << matrix[1] << " " <<matrix[2] << endl;
cout << matrix[3] << " " << matrix[4] << " " <<matrix[5] << endl;
cout << matrix[6] << " " << matrix[7] << " " <<matrix[8] << endl;

}


int CheckMatrix(char player)
{    
//position 1
if (matrix[0] == player && matrix[1] == player && matrix[2]== player)
{
cout << "Win " << player ;
}

//position 2
if (matrix[3] == player && matrix[4] == player && matrix[5] == player)
{
cout << "Win " << player ;
}

//position 3
if (matrix[6] == player && matrix[7] == player && matrix[8] == player)
{
cout << "Win " << player ;
}

//position 4

if (matrix[0] == player && matrix[3] == player && matrix[6]== player)
{
cout << "Win " << player ;
}

//position 5
if (matrix[1] == player && matrix[4] == player && matrix[7] == player)
{
cout << "Win " << player ;
}

//position 6

if (matrix[2] == player && matrix[5] == player && matrix[8] == player)
{
cout << "Win " << player ;
}

//position 7

if (matrix[0] == player && matrix[4] == player && matrix[8] == player)
{
cout << "Win " << player ;
}

//position 8
if (matrix[2] == player && matrix[4] == player && matrix[6] == player)
{
cout << "Win " << player ;
}

 

}


int main(int argc, char *argv[])
{

int number = 0;
int idplayer = 0;

while (true)
{

DisplayMatrix();
CheckMatrix('X');
CheckMatrix('O');

 

if (idplayer == 0)
{
cout << "Input X ";
cin  >> number;
for (int i = 0; i < 10; i++)
{
if (number == i && matrix[i] == '-') matrix[i] = 'X';
}
idplayer = 1;
}

if (idplayer == 1)
{
cout << "Input O ";
cin  >> number;
for (int i = 0; i < 10; i++)
{
if (number == i && matrix[i] == '-') matrix[i] = 'O';
}

idplayer = 0;
}

}

}

Категория: C++ | Добавил: moskov (30.08.2015)
Просмотров: 503 | Рейтинг: 0.0/0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]

Меню сайта

Категории раздела

PHP [41]
C++ [71]
Autoit [108]
Processing [105]
Basic4GL [7]
Fasm [2]
PABC [7]
Js [237]
Gentee [1]
Python [204]
Java android [3]
Small Basic [9]

Мини-чат

Статистика


Онлайн всего: 1
Гостей: 1
Пользователей: 0

Форма входа

Друзья сайта

  • ЗОВ КОСМОСА

  • Хулиган Вселенной

  • Тюремная поэзия

  • Религиозная поэзия

  • Сайт клана ЛеГиоН
  • Поиск