// ConnectFour.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include
#include <stdlib.h>
using namespace std;
int menu();
int grid();
int highscore();
int exit();
int player = 1;
int playGame();
int playerMove();
int columnChosen;
int user_option;
int playerMarker=0;
char columnarray[7][7]={
{’"’,’"’,’"’,’"’,’"’,’"’,’"’},
{’"’,’"’,’"’,’"’,’"’,’"’,’"’},
{’"’,’"’,’"’,’"’,’"’,’"’,’"’},
{’"’,’"’,’"’,’"’,’"’,’"’,’"’},
{’"’,’"’,’"’,’"’,’"’,’"’,’"’},
{’"’,’"’,’"’,’"’,’"’,’"’,’"’},
{’"’,’"’,’"’,’"’,’"’,’"’,’"’}};
void clearScreen()
{
system(“cls”);
}
int menu()
{
cout<<" Welcome to connectFour!";
cout<<endl;
cout<<endl;
cout<<"This is the main menu! Enter the option of your choice to continue!";
cout<<endl;
cout<<endl;
cout<<"1. Start new game!";
cout<<endl;
cout<<"2. View high scores";
cout<<endl;
cout<<"3. Exit game and return to desktop";
cout<<endl;
cout<<endl;
cout<<"Please enter your choice: ";
cin>>user_option;
return 0;
}
int grid()
{
clearScreen();
int i;
cout<<" ConnectFour"<<endl;
cout<<endl;
for(i=0; i<7; i++)
{
cout<<"| "<<columnarray[0][i]<<" | "<<columnarray[1][i]<<" | "<<columnarray[2][i]<<" | "<<columnarray[3][i]<<" | "<<columnarray[4][i]<<" | "<<columnarray[5][i]<<" | "<<columnarray[6][i]<<" | \n -------------------------------------------------"<<endl;
}
cout<<"| 0 | 1 | 2 | 3 | 4 | 5 | 6 |"<<endl<<endl<<"Player 1 = X || Player 2 = O || Empty Slot = \""<<endl;
return 0;
}
int playerMove()
{
cout<<"Please choose where you would like to drop your counter. ";
cin>>columnChosen;
if (playerMarker % 2 == 0)
{
player = 1;
}
else
{
player = 2;
}
if(columnChosen == 0)
{
//Check whether lowest space is free
if(columnarray[0][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][6] = 'O';
}
}
else if(columnarray[0][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][5] = 'O';
}
}
else if(columnarray[0][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][4] = 'O';
}
}
else if(columnarray[0][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][3] = 'O';
}
}
else if(columnarray[0][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][2] = 'O';
}
}
else if(columnarray[0][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][1] = 'O';
}
}
else if(columnarray[0][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[0][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[0][0] = 'O';
}
}
}
//COLUMN 1
else if(columnChosen == 1)
{
//Check whether lowest space is free
if(columnarray[1][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][6] = 'O';
}
}
else if(columnarray[1][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][5] = 'O';
}
}
else if(columnarray[1][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][4] = 'O';
}
}
else if(columnarray[1][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][3] = 'O';
}
}
else if(columnarray[1][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][2] = 'O';
}
}
else if(columnarray[1][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][1] = 'O';
}
}
else if(columnarray[1][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[1][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[1][0] = 'O';
}
}
}
else if(columnChosen == 2)
{
//Check whether lowest space is free
if(columnarray[2][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][6] = 'O';
}
}
else if(columnarray[2][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][5] = 'O';
}
}
else if(columnarray[2][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][4] = 'O';
}
}
else if(columnarray[2][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][3] = 'O';
}
}
else if(columnarray[2][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][2] = 'O';
}
}
else if(columnarray[2][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][1] = 'O';
}
}
else if(columnarray[2][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[2][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[2][0] = 'O';
}
}
}
else if(columnChosen == 3)
{
//Check whether lowest space is free
if(columnarray[3][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][6] = 'O';
}
}
else if(columnarray[3][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][5] = 'O';
}
}
else if(columnarray[3][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][4] = 'O';
}
}
else if(columnarray[3][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][3] = 'O';
}
}
else if(columnarray[3][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][2] = 'O';
}
}
else if(columnarray[3][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][1] = 'O';
}
}
else if(columnarray[3][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[3][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[3][0] = 'O';
}
}
}
else if(columnChosen == 4)
{
//Check whether lowest space is free
if(columnarray[4][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][6] = 'O';
}
}
else if(columnarray[4][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][5] = 'O';
}
}
else if(columnarray[4][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][4] = 'O';
}
}
else if(columnarray[4][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][3] = 'O';
}
}
else if(columnarray[4][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][2] = 'O';
}
}
else if(columnarray[4][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][1] = 'O';
}
}
else if(columnarray[4][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[4][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[4][0] = 'O';
}
}
}
else if(columnChosen == 5)
{
//Check whether lowest space is free
if(columnarray[5][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][6] = 'O';
}
}
else if(columnarray[5][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][5] = 'O';
}
}
else if(columnarray[5][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][4] = 'O';
}
}
else if(columnarray[5][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][3] = 'O';
}
}
else if(columnarray[5][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][2] = 'O';
}
}
else if(columnarray[5][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][1] = 'O';
}
}
else if(columnarray[5][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[5][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[5][0] = 'O';
}
}
}
else if(columnChosen == 6)
{
//Check whether lowest space is free
if(columnarray[6][6] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][6] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][6] = 'O';
}
}
else if(columnarray[6][5] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][5] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][5] = 'O';
}
}
else if(columnarray[6][4] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][4] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][4] = 'O';
}
}
else if(columnarray[6][3] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][3] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][3] = 'O';
}
}
else if(columnarray[6][2] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][2] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][2] = 'O';
}
}
else if(columnarray[6][1] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][1] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][1] = 'O';
}
}
else if(columnarray[6][0] == '"')
{
//If the player is player 1, drop an X
if(player == 1)
{
columnarray[6][0] = 'X';
}
//If the player is player 2, drop a O
else if(player == 2)
{
columnarray[6][0] = 'O';
}
}
}
return 0;
}
int highscore()
{
clearScreen();
cout<<"High score information will be displayed here. ";
return 0;
}
int exit()
{
return 0;
}
int main()
{
menu();
if (user_option == 1)
{
int i;
for(i=0; i<50; i++)
{
grid();
playerMove();
playerMarker++;
clearScreen();
}
}
if (user_option == 2)
{
highscore();
}
if (user_option == 3)
{
exit();
}
return 0;
}