Sunteți pe pagina 1din 37

COMPUTER SCIENCE

PROJECT FILE
ON
Gaming Interface

PROJECT PREPARED BY:


Name: SURYA A N
Class: XII Section : A
Session: 2015-2016
CS ACADEMY, ERODE.

(AFFILIATED TO CBSE, NEW DELHI)

PROJECT WORK
IN
COMPUTER SCIENCE

Gaming Interface
Prepared under the guidance of:

MS. Reeja Ravindran

Name
Class
Reg No.
School

Submitted by
: SURYA A N
: XII-A
: M216 46062 0072
: C S ACADEMY, ERODE

(AFFILIATED TO CBSE, NEW DELHI)

Standard xii

COMPUTER SCIENCE

Name of the student : SURYA A N


Class & Section
: xii a
Register No.
: M216 46062 0072
Year
: 2015 2016
Certified that this is a bona fide record of project
work titled Gaming Interface by SURYA A N of class
XII A with Register Number M216 46062 0072 in
year 2015-2016.
Date:
Principal

Teacher in-charge

Submitted on the practical examination held on


_______________
Official Seal
Date :
Examiner
Place :

ACKNOWLEDGEMENT

I express my heartfelt gratitude to Ms. Reeja


Ravindran,

my

Computer

Science

teacher

who

guided me at all stages of the project work and gave


me valuable suggestions and advices for completing
the project work.
She helped me to incorporate important
details of the project which otherwise I would have
missed. My project work is a success because of her
guidance.
I also feel the urge to mention and thank for the
tireless help lent by my fellow friends who constantly
reviewed my codes and helped me with their timely
suggestions.

CERTIFICATE
This is to certify that Mr./Ms. SURYA A N of
class XII-A has completed
his/her project
under my supervision. He/She has taken
proper care and shown utmost sincerity in
completing the project.
I certify that the project Gaming Interface is as
per CBSE Guidelines and is up to my
expectation.

Ms. Reeja Ravindran

TABLE OF CONTENTS

Project Synopsis

Header files and their purpose

Classes and Objects

Functions

Coding

Limitations

Requirements

Bibliography

PROJECT SYNOPSIS

This program is all about a gaming interface


that provides link to 3 different games and
facilitates it by providing access to it. The 3
different games added in the program are
casino, hangman and, snake and ladder
respectively. It has a security key for each
game. It also has a failsafe security system if
the key is produced wrong-it undergoes a virus
joke for threatening the illegal key entry. This
program uses many types of user defined and
predefined functions to achieve this final state
of the project. It also has a file attached to it to
store the high-score of the game Casino.
Many other design oriented functions have
been added to bring some variety visual colors
to the user from the program. The games have
been carefully reviewed with test users and
have been rated high for their simple but
efficient coding and creative output. This
program uses large number of loops and
delays for relaying the output for making this
program user friendly.

Keys For the Games


1. Casino
- c or C
2. Snake and Ladder - s or S
3. Hangman
- h or H

HEADER FILES USED


AND THEIR PURPOSE
1. fstream.h for file handling, cin
and cout
2. dos.h for Blink and text colour
functions
3. conio.h for clrscr() and getch()
functions
4. stdio.h for standard I/O
operations
5. string.h for string handling
6. ctype.h for character handling

CLASSES AND
THEIR OBJECTS

The user defined classes and their purpose


are as follows:
Class score: Used to evaluate, compare, store
and display the scores and the High score of the
chance game of Casino.
Functions used in the class:
o getdata()
o display()
o getscore()
Files used for file handling using the class
score-score.txt via the file manipulating
function highscr().
Objects Used:
o s-score of the current game(last game to
be played) played
o c-scores of the previously scored or
stored in the file.

FUNCTIONS
void getdata()-gets and assigns balanceamt as
score.
void display()-displays score.
int getscore()-get score from file.

void highscr()-Extensively for file handling.


void draw_line()-drawing line composed of certain
symbols .
void rules()-Displays Rules.
void gamescore(char name1[],char name2[],int
p1, int p2)-gives score of the game.
void board()-produces the virtual board for the
snake and
ladder game.
void play_dice(int &score)-involves in the updation
of score each round.
int letterFill (char guess, char secretword[], char
guessword[])-Function responsible for analysing
the user answer and the question keyword in
Hangman.
void initUnknown (char word[], char unknown[])Has the unknown characters.
void game1()- The Casino Game.
void game2()-The Snake and Ladder Game.
void game3()-The Hangman Game.
void ffool()-Failsafe Mechanism literally a virus
joke(time Killer).
void confirmation()-Analyses the key and produces
the main root of Root to a virtual Gaming Interface
to all 3 games and the fail safe Fuction.

CODING

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>

#include<stdio.h>
#include<string.h>
int balanceamt;
char playername[80];
class score
{
int score;
public:
void getdata()
{
score=balanceamt;
cout<<"Score\n"<<score;
}
void display()
{
cout<<score;
}
int getscore()
{
return score;
}
}s,c;
void highscr()
{
clrscr();
fstream fs;
fs.open("score.txt",ios::in|ios::out);
s.getdata();
int last=0,found=0;
while(!found&&fs.read((char*) &c, sizeof(c)))
{
if(s.getscore()>=c.getscore())
{
fs.seekg(-1* sizeof(c),ios::cur);
fs.write((char*)&s, sizeof(s));
last=1;

}
else if(last==0)
{
//fs.put(s.getscore());
fs.write((char*)&s, sizeof(s));
}
else
{
fs.put(s.getscore());
}
if(fs.eof())
{if(last==1)
found=1;
}
}
while(!fs.eof())
{
fs.read((char*)&c,sizeof(c));
c.display();
}
fs.close();
}
void draw_line(int n,char ch)
{
for(int i=0;i<n;i++)
cout<<ch;
}
void rules()
{
clrscr();
cout<<"\n\n";
draw_line(60,'-');
cout<<"\n\t\tRULES OF THE GAME\n";
draw_line(60,'-');
cout<<"\n\t0.CHEATING IS PROHIBITTED AND IF
CAUGHT DEATH PENALTY\n\t1. Choose any number
between 1 to 15\n\t2. If you win you will get 5 times

of money you bet\n\t3. If you bet on wrong number


you will lose your betting amount\n\n";
draw_line(60,'-');
cout<<endl;
}
void game1()
{
textcolor(YELLOW);
clrscr();
int amt,no,dice,extraamnt;
char ch;
clrscr();
draw_line(60,'=');
cout<<"\n\n\n\n\t\tCASINO GAME\n\n\n\n";
draw_line(60,'=');
cout<<"\n\n\nEnter Your Name :";
gets(playername);
cout<<"\nFor Monetory Security Every player is
mandatorily must \ndeposit over $1000\n\n";
balanceamt=1000;
delay(5000);
do
{
clrscr();
rules();
cout<<"\n\nYour
current
balance
is
Rs."<<balanceamt;
if(balanceamt==0)
{
clrscr();
cout<<"loser!!! U Lost So You are OUT!!\nCome
again with money to play again hope you win next
time!!";
delay(5000);
break;
}
do

{
cout<<"\n\n"<<playername<<"\tenter money to
bet";
cin>>amt;
if(amt>balanceamt)
cout<<"Your betting amount is more than your
current balance\n\nRe-enter data\n ";
else
break;
}while(1);
do
{
cout<<"Enter your lucky number to bet between 1
to 15 :";
cin>>no;
if(no<=0||no>15)
cout<<"Please check the number!! should be
between 1 to 15\n\nRe-enter data\n ";
else
break;
}while(1);
randomize();
dice=random(15)+1;
if(dice==no)
{
cout<<"\n\nGood Luck!! You won Rs."<<amt*5;
balanceamt=balanceamt+amt*5;
}
else
{
cout<<"Bad Luck this time !! You lose Rs."<<amt;
balanceamt=balanceamt-amt;
}
cout<<"\n\nThe winning number was : "<<dice;
cout<<"\n\n\t"<<playername<<" You have Rs.
"<<balanceamt<<endl;
cout<<"\n\n-->Do you want to play (y/n)? ";

cin>>ch;
}while(ch=='Y'|| ch=='y');
clrscr();
cout<<"\n\n\n";
draw_line(70,'+');
cout<<"\n\n\t\THANKS FOR COMING TO CASINO||
YOUR
BALANCE
AMOUNT
IS
RS."<<balanceamt<<"\n\n";
draw_line(70,'+');
delay(4000);
if(balanceamt>1000)
{
cout<<"\nYou won:Rs."<<balanceamt-1000<<"\n";
}
else if(balanceamt==1000)
{
cout<<"\nNice try.You have kept your wealth safe
and but U added none to it\n";
delay(5000);
textcolor(WHITE);
clrscr();
}
else
{
cout<<"\t\nSorry,You
Wasted
your
wealth"<<"\nBy:"<<1000-balanceamt<<"\n";
delay(5000);
textcolor(WHITE);
clrscr();
}
cout<<"Highscore is"<<balanceamt;
delay(2000);
highscr();
delay(4000);
clrscr();
draw_line(70,'+');
draw_line(70,'+');

cout<<"\n\nGame developed by ANS\n";


draw_line(70,'+');
getch();
}
void board()
{
clrscr();
cout<<"\n\n";
draw_line(50,'-');
cout<<"\n\t\tSNAKE AT POSITION\n";
draw_line(50,'-');
cout<<"\n\tFrom 98 to 28 \n\tFrom 95 to 24\n\tFrom
92 to 51\n\tFrom 83 to 19\n\tFrom 73 to 1\n\tFrom 69
to 33\n\tFrom 64 to 36\n\tFrom 59 to 17\n\tFrom 55
to 7\n\tFrom 52 to 11\n\tFrom 48 to 9\n\tFrom 46 to
5\n\tFrom 44 to 22\n\n";
draw_line(50,'-');
cout<<"\n\t\t LADDER AT POSITION\n";
draw_line(50,'-');
cout<<"\n\tFrom 8 to 26\n\tFrom 21 to 82\n\tFrom
43 to 77\n\tFrom 50 to 91\n\tFrom 62 to 96\n\tFrom
66 to 87\n\tFrom 80 to 100\n";
draw_line(50,'-');
cout<<endl;
}
void gamescore(char name1[],char name2[],int p1,
int p2)
{
cout<<"\n";
draw_line(50,'~');
cout<<"\n\t\tGAME STATUS\n";
draw_line(50,'~');
cout<<"\n\t--->"<<name1<<"
is
at
position
"<<p1<<endl;
cout<<"\t--->"<<name2<<"
is
at
position
"<<p2<<endl;
draw_line(50,'_');

cout<<endl;
}
void play_dice(int &score)
{
int dice;
dice=random(6)+1;
cout<<"\nYou got "<<dice<<" Point !! ";
score=score+dice;
cout<<"Now you are at position "<<score;
switch(score)
{
case 98 :score=28;break;
case 95 :score=24;break;
case 92 :score=51;break;
case 83 :score=19;break;
case 73 :score=1;break;
case 69 :score=33;break;
case 64 :score=36;break;
case 59 :score=17;break;
case 55 :score=7;break;
case 52 :score=11;break;
case 48 :score=9;break;
case 46 :score=5;break;
case 44 :score=22;break;
case 8 :score=26;break;
case 21 :score=82;break;
case 43 :score=77;break;
case 50 :score=91;break;
case 54 :score=93;break;
case 62 :score=96;break;
case 66 :score=87;break;
case 80 :score=100;
}
}
void game2()
{
textcolor(YELLOW);

clrscr();
int player1=0,player2=0,lastposition;
char player1name[80],player2name[80];
clrscr();
randomize();
draw_line(50,'=');
cout<<"\n\n\n\n\t\tSNAKE LADDER GAME\n\n\n\n";
draw_line(50,'=');
cout<<"\n\n\nEnter Name of player 1 :";
gets(player1name);
cout<<"\n\n\Enter Name of player 2 :";
gets(player2name);
while(player1<=100 && player2<=100)
{
board();
gamescore(player1name,player2name,player1,playe
r2);
cout<<"\n\n--->" <<player1name<<" Now your
Turn >> Press any key to play ";
getch();
lastposition=player1;
play_dice(player1);
if(player1<lastposition)
cout<<"\n\aOops!! Snake found !! You are at postion
"<<player1<<"\n";
else if(player1>lastposition+6)
cout<<"\nGreat!! you got a ladder !! You are at
position "<<player1;
cout<<"\n\n--->"<<player2name<<" Now your Turn
>> Press any key to play ";
getch();
lastposition=player2;
play_dice(player2);
if(player2<lastposition)
cout<<"\n\n\aOops!! Snake found !! You are at
position "<<player2<<"\n";
else if(player2>lastposition+6)

cout<<"\n\nGreat!! you got a ladder !! You are at


position "<<player2<<"\n";
getch();
}
clrscr();
cout<<"\n\n\n";
draw_line(50,'+');
cout<<"\n\n\t\tRESULT\n\n";
draw_line(50,'+');
cout<<endl;
gamescore(player1name,player2name,player1,playe
r2);
cout<<"\n\n\n";
if(player1>=player2)
cout<<player1name<<" !! You are the winner of the
game\n\n";
else
cout<<player2name<<" !! You are the winner of the
game\n\n";
draw_line(50,'+');
draw_line(70,'+');
cout<<"\n\nGame developed by ANS\n";
draw_line(70,'+');
getch();
delay(5000);
clrscr();
}
const int MAXLENGTH=80;
const int MAX_TRIES=5;
const int MAXROW=7;
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';
}
void game3()
{
textcolor(GREEN);
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",
"armenia",
"vietnam",
"japan",
"iraq",
"isreal",
"canada",
"chile",
"peru",
"uruguay",
"argentina",
"nigeria",
"brazil",
"spain",
"italy",
"russia",
"austria",
"uzbekistan",
"afganistan",
"egypt",
"colombia",
"turkey",
"finland",
"switzerland",
"maldives",
"neatherland",
"portugal",
"france",
"bhutan",
"china",
"northkorea",
"southkorea",
"sudan",
"greece",
"mangolia",
"paraguay",
"germany",

"hungary",
"southafrica",
"uganda",
"morocco"
};
randomize();
int n=random(50);
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;


delay(10000);
if (strcmp(word, unknown) == 0)
{
textcolor(CYAN);
clrscr();
cout << word << endl;
cout << "Yeah! You got it!"<<"IT IS "<<word;
delay(5000);
break;
}
}
if(num_of_wrong_guesses == MAX_TRIES)
{
textcolor(RED+BLINK);
clrscr();
cout << "\nSorry, you lose...you've been hanged."
<< endl;
cout << "The word was : " << word << endl;
delay(8000);
textcolor(WHITE);
clrscr();
}
cout<<"\n\n";
draw_line(70,'+');
cout<<"\n\nGame developed by ANS\n";
draw_line(70,'+');
}
void ffool()
{
int t=60;
textcolor(RED+BLINK);
clrscr();
long i=2;
cout<<"Your PC is under the Surveillance of JPP
virus\n\n\n\n";
delay(10000);

textcolor(RED);
clrscr();
cout<<"Your PC is under the Surveillance of JPP
virus\n\n\n\n";
cout<<"New Volume I::Deleted\n";
delay(5000);
cout<<"New Volume H::Deleted\n";
delay(1500);
cout<<"New Volume G::Discarded\n";
delay(2000);
cout<<"New Volume E::Deleted\n";
delay(2500);
cout<<"New Volume D::Deleted\n";
delay(2000);
cout<<"New Volume C::Cleaned\n";
delay(4000);
textcolor(RED);
clrscr();
cout<<"\n\n\n\n\t\t\tYour pc is Affected intensely by
an Unknown virus\n\n";
cout<<"\n\n\n\n\t\t\tHappy Valentine's day";
delay(10000);
textcolor(YELLOW+BLINK);
clrscr();
do
{delay(10);
cout<<"-_-";
delay(50);
cout<<".";
delay(50);
if(i==999)
{
delay(1000);
textcolor(RED+BLINK);
clrscr();
cout<<"SyStEm CrAsHeD";
delay(10000);

clrscr();
rip:
if(t>0)
{
textcolor(GREEN);
clrscr();
cout<<"SyStEm
ReBoOt
initiated
in
"<<"\t\t00:"<<t;
delay(1000);
t--;
clrscr();
goto rip;
}
delay(3000);
textcolor(BLUE);
clrscr();
}
i++;
}while(i!=1000);
}
void confirmation()
{
int k=0;
char f;
delay(1000);
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tWelcome
to GAMING CLUB\n\t\t\t[RESTRICTED ENTRY ONLY]";
delay(5000);
cout<<"\n\n\t\t\t\t\tEnter KEY";
delay(2000);
cout<<"\n\t\t\t\t\tHERE-->";
cin>>f;
delay(3000);
clrscr();
delay(4000);
cout<<"Your key is being processed\n";
do

{delay(1000);
cout<<"::";
delay(2000);
k++;
}while(k!=8);
clrscr();
if(f=='C'||f=='c')
{
cout<<"Valid key";
delay(3000);
clrscr();
game1();
}
else if(f=='S'||f=='s')
{
cout<<"Valid key";
delay(3000);
clrscr();
game2();
}
else if(f=='H'||f=='h')
{
cout<<"Valid key";
delay(3000);
clrscr();
game3();
}
else
{
textcolor(RED+BLINK);
clrscr();
cout<<"INVALID KEY";
delay(9000);
clrscr();
cout<<"\nILLEGAL ENTRY ATTEMPT DETECTED\n";
cout<<"\n\tFail Safe Mechanism initiated----ENTRY
KILLING VIRUS INTRODUCED";

delay(10000);
clrscr();
ffool();
cout<<"VIRUS
EXPELLED"<<"\nILLEGAL
ENTRY&CHEATING ATTEMPT AVERTED\n\n";
cout<<"Remember dude wrong key means illegal
entry here so beware\n";
delay(10000);
textcolor(WHITE);
clrscr();
confirmation();
}
}
void main()
{int a;
char b;
textcolor(CYAN);
clrscr();
wip:
cout<<"\n\nWARNING:This VENTURE is a mandatory
full go through \n\tso no turning back in the middle";
cout<<"\n[-_-]Do you want to go in (just for a
confirmation)(y/n):";
cin>>b;
if(b=='y'||b=='Y')
{}
else if(b=='n'||b=='N')
{
exit(0);
}
else
{
clrscr();
cout<<"InVALID ENTRY"<<"\nPRESS Y OR N";
goto wip;
}
textcolor(WHITE);

clrscr();
confirmation();
cout<<"\n\n\nAPROJECT
DONE
BY
ANS"<<"\n\n\n\n\n\n\t\t\t\n\n\n\n\n\n\n\n\n\n\n\n\n\n\
n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\
t(c)SURYA bros";
delay(10000);
textcolor(WHITE);
clrscr();
sip:
cout<<"Do you want to continue in the club(press 1)
or exit(press 0)";
cin>>a;
if(a==1)
{
clrscr();
confirmation();
}
else if(a==0)
{textcolor(BLUE+BLINK);
cout<<"Hope you enjoyed"<<"\nTHNX BUDDY!!";
delay(5000);
}
else
{
cout<<"\nInvalid Entry"<<"\npress 1 or 0 only";
delay(2000);
goto sip;
}
getch();
}

OUTPUTS

LIMITATIONS

FEW MORE GAMES COULD HAVE

BEEN ADDED.

COMMENTS TO THE CODE COULD

HAVE BEEN ADDED INCREASING ITS


EASY INTERPRETATION FOR CODE
READERS.

REQUIREMENTS
HARDWARE

REQUIRED
Printer, to print the required documents of
the project
Compact Drive
Processor : Pentium III
Ram : 64 MB
Harddisk : 20 Gb.
SOFTWARE REQUIRED
Operating system : Windows XP
Turbo C++, for execution of program and
Ms word, for presentation of output.

BIBLIOGRAPHY

COMPUTER SCIENCE IN C++ BY: SUMITA ARORA


Object Oriented Programming with C++ By: - E.
BALAGURUSAMY
http://www.tutorialspoint.com/cplusplus/
https://developers.google.com/edu/c++/cpp-indepth?hl=en

S-ar putea să vă placă și