You are on page 1of 20

PROJECT FILE

SARTHAK
PANWAR
XI-B

Roll No.-37
ACKNOWLEDGE
MENT
I,

SARTHAK PANWAR

of class XI-B, am highly grateful to

Ms.CHARU MAM

for her untiring help andencouragement


during the course of project titled

“C++ GAMING”

I highly acknowledge,with deepest sense


of gratitude and indebtedness, her great
coordination and support throughout the
course of work. I would also like to express
my gratitude to my friends, who were
always there to help and motivate me.
CERTIFICATE
This is to certify that SARTHAK
PANWAR of Class XI-B has
prepared the report on the Project
Entitled “C++ GAMING”. The
reports found worthy of his
acceptance as final project report
for the Subject Computer Science
of Class XI-B. He has prepared the
report under my guidance.

Ms.Charu,
ST. JOSEPH’S ACADEMY
CODING
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

char mark[10] = {'0','1','2','3','4','5','6','7','8','9'};


const int MAXLENGTH=80;
const int MAX_TRIES=5;
const int MAXROW=7;

int letterFill (char, char[], char[]);


void initUnknown (char[], char[]);

int ticTacToe()
{
int flag();
void game();
int player = 1,i,a;
char hit;
clrscr();
do
{
game();
player=(player%2)?1:2;
cout << "Player " << player << ", enter a
number: ";
cin >> a;
hit=(player == 1) ? 'X' : 'O';
if (a == 1 && mark[ 1]=='1')
mark[1] = hit;
else if (a == 2 && mark[2]=='2')
mark[2] = hit;
else if (a == 3 && mark[3]=='3')
mark[3] = hit;
else if (a == 4 && mark[4]=='4')
mark[4] = hit;
else if (a == 5 && mark[5]=='5')
mark[5] = hit;
else if (a == 6 && mark[6]=='6')
mark[6] = hit;
else if (a == 7 && mark[7]=='7')
mark[7] = hit;
else if (a == 8 && mark[8]=='8')
mark[8] = hit;
else if (a == 9 && mark[9]=='9')
mark[9] = hit;
else
{
cout<<"Invalid move ";
getch();
}
i=flag();
player++;
}while(i==-1);
game();
if(i==1)
cout<<"==>\aPlayer "<<--player<<"
Wins The Game! ";
else
cout<<"==>\aGame draw";
cout<<"\n\n..................GAME
OVER.................."<<endl;
getch();
return 0;
}

int flag()
{
if (mark[1] == mark[2] && mark[2] ==
mark[3])
return 1;
else if (mark[4] == mark[5] && mark[5] ==
mark[6])
return 1;
else if (mark[7] == mark[8] && mark[8] ==
mark[9])
return 1;
else if (mark[1] == mark[4] && mark[4] ==
mark[7])
return 1;
else if (mark[2] == mark[5] && mark[5] ==
mark[8])
return 1;
else if (mark[3] == mark[6] && mark[6] ==
mark[9])
return 1;
else if (mark[1] == mark[5] && mark[5] ==
mark[9])
return 1;
else if (mark[3] == mark[5] && mark[5] ==
mark[7])
return 1;
else if (mark[1] != '1' && mark[2] != '2' &&
mark[3] != '3' &&
mark[4] != '4' && mark[5] != '5' &&
mark[6] != '6' &&
mark[7] != '7' && mark[8] != '8' && mark[9]
!= '9')
return 0;
else
return -1;
}

void game()
{
clrscr();
cout << "\n\n\tWELCOME TO TIC TAC
TOE!\n\n";
cout << "Player 1 (X) - Player 2 (O)" << endl
<< endl;
cout << endl;
cout << " | | " << endl;
cout << " " << mark[1] << " | " << mark[2]
<< " | " << mark[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << mark[4] << " | " << mark[5]
<< " | " << mark[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << mark[7] << " | " << mark[8]
<< " | " << mark[9] << endl;
cout << " | | " << endl << endl;
}

int hangMan()
{
clrscr();
char unknown [MAXLENGTH];
char letter;
int num_of_wrong_guesses=0;
char word[MAXLENGTH];
char words[][MAXLENGTH] =
{
"india",
"pakistan",
"nepal",
"malaysia",
"philippines",
"australia",
"iran",
"ethiopia",
"oman",
"indonesia"
};
randomize();
int n=random(10);
strcpy(word,words[n]);
initUnknown(word, unknown);
cout << "\n\nWelcome to hangman...Guess a
country Name";
cout << "\n\nEach letter is represented by a star.";
cout << "\n\nYou have to type only one letter in
one try";
cout << "\n\nYou have " << MAX_TRIES << " tries
to try and guess the word.";
cout <<
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~";
while (num_of_wrong_guesses < MAX_TRIES)
{
cout << "\n\n" << unknown;
cout << "\n\nGuess a letter: ";
cin >> letter;
if (letterFill(letter, word, unknown)==0)
{
cout << endl << "Whoops! That letter isn't in
there!" << endl;
num_of_wrong_guesses++;
}
else
{
cout << endl << "You found a letter! Isn't that
exciting!" << endl;
}
cout << "You have " << MAX_TRIES -
num_of_wrong_guesses;
cout << " guesses left." << endl;
if (strcmp(word, unknown) == 0)
{
cout << word << endl;
cout << "Yeah! You got it!";
break;
}
}
if(num_of_wrong_guesses == MAX_TRIES)
{
cout << "\nSorry, you lose...you've been hanged."
<< endl;
cout << "The word was : " << word << endl;
}
cout<<"\n\n..................GAME
OVER...................."<<endl;
getch();
return 0;
}
int letterFill (char guess, char secretword[], char
guessword[])
{
int i;
int matches=0;
for (i = 0; secretword[i]!='\0'; i++)
{
if (guess == guessword[i])
return 0;
if (guess == secretword[i])
{
guessword[i] = guess;
matches++;
}
}
return matches;
}
void initUnknown (char word[], char unknown[])
{
int i;
int length = strlen(word);
for (i = 0; i < length; i++)
unknown[i]='*';
unknown[i]='\0';
getch();
}
void main()
{
clrscr();
cout << "Welcome to the Humble Bundle!" <<
endl;
cout << endl;
char replayChoice='y';
do {
cout << "......Which game would you like to
play?......" << endl;
cout << "1.--->> Tic Tac Toe" << endl;
cout << "2.--->> Hangman" << endl;
int gameChoice;
cin>>gameChoice;
switch(gameChoice)
{
case 1: ticTacToe(); break;
case 2: hangMan(); break;
default: cout << "Wrong Input..." <<endl;
}
cout<<endl;
cout<<"\n\n ------ PRESS Y TO PLAY AGAIN
------"<<endl;
cout<<" >>";
cin >> replayChoice;
}
while((replayChoice == 'y') || (replayChoice ==
'Y'));
getch();
}

OUTPUT
1
2

3
4

5
6
BIBLIOGRAPHY
1. Computer Science with
C++ by Preeti Arora and
Pinky Gupta

2. www.google.com

You might also like