1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <Windows.h>
char gameboard (short);
int main()
{
using namespace std;
short boardn[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
short in;
short playernum = 1;
for( ; ; )
{
cout << gameboard(boardn[0]) << "----------" << gameboard(boardn[1]) << "----------" << gameboard(boardn[2]) << " 1 2 3" << endl;
cout <<"| | |" << endl;
cout <<"| | |" << endl;
cout <<"| "<< gameboard(boardn[3]) << "------" << gameboard(boardn[4]) << "------" << gameboard(boardn[5]) <<" |" << " 4 5 6" << endl;
cout <<"| | | | |" << endl;
cout <<"| | | | |" << endl;
cout <<"|" " | " << gameboard(boardn[6]) << "-" << gameboard(boardn[7]) << "-" << gameboard(boardn[8]) << " |" " |" << " 7 8 9" << endl;
cout <<"| | | | | |" << endl;
cout << gameboard(boardn[9]) << "---" << gameboard(boardn[10]) << "----" << gameboard(boardn[11]) << " " << gameboard(boardn[12]) <<"----" << gameboard(boardn[13]) << "---" << gameboard(boardn[14]) << " 10 11 12 13 14 15" << endl;
cout <<"| | | | | |" << endl;
cout <<"|" " | " << gameboard(boardn[15]) << "-" << gameboard(boardn[16]) << "-" << gameboard(boardn[17]) << " |" " |" << " 16 17 18" << endl;
cout <<"| | | | |" << endl;
cout <<"| | | | |" << endl;
cout <<"| "<< gameboard(boardn[18]) << "------" << gameboard(boardn[19]) << "------" << gameboard(boardn[20]) <<" |" << " 19 20 21" << endl;
cout <<"| | |" << endl;
cout <<"| | |" << endl;
cout << gameboard(boardn[21]) << "----------" << gameboard(boardn[22]) << "----------" << gameboard(boardn[23]) << " 22 23 24" << endl;
cout << "The numbers to the right of the board correspond to the placement of a stone on the board." << endl;
cout << "Please select the placement of your stone. Player # " << playernum <<endl;
cin >> in;
boardn[in-1] = playernum;
if (in > 24)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),4);
cout << "Illegal move please re-enter a number that is between 1-24. \a" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
}
if (in < 0)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),4);
cout << "Illegal move please re-enter a number that is between 1-24. \a" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
}
else
playernum = playernum == 2 ? 1 : 2;
}
}
char gameboard (short a)
{
char b;
switch(a)
{
case 0:
b = 'X';
break;
case 1:
b = '1';
break;
case 2:
b = '2';
break;
};
return b;
}
| |