//A program that will run a game of Connect Four
#include<iostream.h> //Contains the input and output commands
#include<iomanip.h> //Declares the C++ streams input/output manipulators
#include<stdio.h> //Defines types and macros
#include<conio.h>
void main(); //Tells C++ that this is the start of a program
void gameinformation(); //holds information about the game
void game();
void menuone();
void menutwo();
void exitgame(); //enables the player to quit the game
void badinput();
void init();
void display();
void clrscr();//Indicates the start of a block of code
{
char option, choice;
char player one[10],player two[10]="playerone";="playertwo";//creating the two pleyers
char symbol='O';symbol='X'; //creating the symbols to be used in the game
}
do
{
cout<<endl<<endl;
cout<<setw(5)<<""<<"Menu"<<endl<<endl;//Menu from which the player can choose different options
cout<<setw(5)<<""<<"1: Enter data "<<endl<<endl; //Entering character onto grid
cout<<setw(5)<<""<<"2: Update data "<<endl<<endl; //Updating the grid
cout<<setw(5)<<""<<"3: View grid "<<endl<<endl; //Viewing the updated grid
cout<<setw(5)<<""<<"4: Continue "<<endl<<endl; //Continue with the current game
cout<<setw(5)<<""<<"5: Quit game "<<endl<<endl; //Quit the current game
cout<<setw(5)<<""<<"Enter option choice: "<<endl<<endl; //User enters option
cin>>option; //Input of option selected by user
cout<<endl<<endl;
cout<<endl<<endl; //Output of result of input
switch (option)
{
case '1':gameinformation();
break;
case '2':game();
break;
case '3':menuone();
break;
case '4':menutwo();
break;
case '5':exitgame();
break;
default:badinput();
}
{
while (option!='5');
void gameinformation();
}
clrscr();//Tells the program to clear the screen
cout<<"Please enter your name, player one";
cout<<"Please enter your name, player two";
void game()
{
game information();
}
void menuone();
{
}
void menutwo();
{
}
void exitgame();
{
cout<<setw(10)<<"Game is exiting"<<endl;
}
void badinput();
{
clrscr();
cout<<setw(10)<<"Sorry, that is not a valid option"<<endl;
cout<<setw(10)<<"Please choose an option - 1, 2, 3, 4 or 5"<<endl;
}
void init()
{
int row, col;
for(row=0;row<7;row++)
for(col=0;col<7;col++)
board [row][col] =' ';
}
void display()
{
int row, col;
do
{
cout<<setw(25)<<" "<<" ";
cout<<setw(10)<<"playerone<<"
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__|__|__|"<<endl;
cout<<setw(10)<<playertwo<<": X"<<symbol<<endl;
for(row=6;row>=0;row--)
{
cout<<setw(25)<<" "<<"| | | | | | | | "<<endl;
cout<<setw(25)<<" "<<"| "<<board[row][0]<<"| "<<board[row][1]
<<"| "<<board[row][2]<<"| "<<board[row][3]
<<"| "<<board[row][4]<<"| "<<board[row][5]
<<"| "<<board[row][6]<<"| "<<endl;
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__| "<<endl;
cout<<setw(25)<<" "<<"| 1| 2| 3| 4| 5| 6| 7| "<<endl;
row=0;
cout<<"Enter the column within which you wish to play";//asks the player to choose a number corresponding to a column on the grid
cin>>col; //Tells the program to enter a symbol based o=n the choice of the player
col--;
if (board[row][col]==' ')
{
board[row][col]=symbol;
}
else if {board[row][col]!=" ");
{
do
{
row++;
}
while (board[row][col]!=" ");
}
board [row][col]=symbol;
if(current player =='1')
{
symbol='X';//This is one of the two symbols to be used in the game
current player='2';
}
else if (current player=='2');
{
symbol='0';
current plater='1';
}
while(win='F');
}
}

New Topic/Question
Reply




MultiQuote





|