#include <fstream.h>
#include <conio.h>
#include <windows.h>
#include <stdio.h>
#include <time.h>
void menu(int order_num, int turn_order);
void display();
void turnorder(int &order_number, int &turn_order);
void game(int order_number, int turn_order);
int main()
{
int order_number=0;
int turn_order; // 0 = Computer and 1 = Person
menu(order_number,turn_order);
return 0;
}
void menu(int order_number, int turn_order)
{
char option;
do
{
cout << "Home version\n\n\n\n\n\n\n";
cout << "\t1.play \n\t2.Top Scores \n\t3.Exit\n";
cin >> option;
cin.ignore(80, '\n');
switch(option)
{
case '1':
clrscr();
game(order_number,turn_order);
break;
case '2':
clrscr();
break;
case '3':
clrscr();
cout << "Thanks";
break;
default:
clrscr();
cout << "Invalid";
break;
}
} while(option != '3');
}
void game(int order_number, int turn_order)
{
if(order_number==0)
{
turnorder(order_number,turn_order);
}
display();
}
void turnorder(int &order_number, int &turn_order)
{
int random_num;
char choice;
int wait;
do
{
cout << " VGames [ Checkers ] :: \n";
cout << " Lets Decide the Turn order to be fair...\n";
cout << " The computer will generate a number [1 or 2] \n";
cout << " Don't worry the computer will not cheat...\n";
srand(time(NULL));
random_num =rand() % 2;
cin >> choice;
cin.ignore(80, '\n');
if(choice == random_num)
{
clrscr();
cout << "You choose the right number, you will go first.\n";
order_number+=1;
turn_order=1;
wait = getch(); // Press a key to continue
break; // Break out of this sub-function
}
if (choice != random_num)
{
clrscr();
cout << "You choose the wrong number, you will go last.\n";
order_number+=1;
turn_order=0;
wait = getch(); // Press a key to continue
break; // Break out of this sub-function
} else {
clrscr();
cout << "Invaild Choice,\n"
<< "Please choose again.\n";
}
}while(order_number == 0);
}
void display()
{
char board[10][10] = {
/* 0 1 2 3 4 5 6 7 8 9 10 */
{ 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' '}, /* 0 2-D Game Board */
{ ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X',}, /* 1 10x10 */
{ 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' '}, /* 2 Blank Spaces */
{ ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X',}, /* 3 */
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, /* 4 */
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, /* 5 */
{ 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' '}, /* 6 */
{ ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O',}, /* 7 */
{ 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' '},/* 8 */
{ ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O',} /* 9 */
};
int e;
for(e=0;e<10;e++)
{
if(e==1 || e==3 || e==5 || e==7 || e==9) {
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "\n\n\t\t [ " << board[e][0] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][1] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][2] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][3] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][4] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][5] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][6] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][7] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][8] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][9] << " ] ";
} else {
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "\n\n\t\t [ " << board[e][0] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][1] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][2] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][3] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][4] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][5] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][6] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][7] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][8] << " ] ";
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
cout << "[ " << board[e][9] << " ] ";
}
}
}