Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Game in C++
#1
Guys this is just a small game created by me with my limited knowledge..
Code:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
const int totchan=10;
int h;
void game();
void instrcts();
void credits();


void menu();
void main()
{

clrscr();
textbackground(WHITE);


for(int i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
char p[]="rooneyful",p1[18], a;
gotoxy(35,12);
textcolor(0);
cprintf("Enter the password:\n");
gotoxy(35,14);
int b;
for( b=0;b<9;b++)
{
p1[b]=getch();
textcolor(0);
cprintf("¯");
}
p[b]='\0';
delay(200);
if(strcmp(p,p1)==0 )
{gotoxy(35,16);
textcolor(0);
cprintf("Access granted");
}
else
{gotoxy(35,16);
textcolor(0);
cprintf("Access denied");
getch();
exit(0);
}
delay(500);
clrscr();
for( i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
gotoxy(35,16);

if(strcmp(p,p1)==0)
{
textcolor(BLUE);
gotoxy(8,20);
cprintf( " ÛÛ     ÛÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛÛ   ÛÛ ÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛ ");
gotoxy(8,21);
cprintf(" ÛÛ     ÛÛ    ÛÛ  ÛÛ     ÛÛ  ÛÛ      Û  ÛÛ ÛÛ    ÛÛ ÛÛ");
gotoxy(8,22);
textcolor(BLACK);
cprintf(" ÛÛ     ÛÛ    ÛÛ  ÛÛ     ÛÛ  ÛÛ      Û  ÛÛ ÛÛ    ÛÛ ÛÛ");
gotoxy(8,23);
cprintf(" ÛÛ     ÛÛ    ÛÛ  ÛÛÛÛÛÛÛÛÛ  ÛÛ      Û  ÛÛ ÛÛ    ÛÛ ÛÛ   ÛÛÛ");
gotoxy(8,24);
textcolor(RED);
cprintf(" ÛÛ     ÛÛ    ÛÛ  ÛÛ     ÛÛ  ÛÛ      Û  ÛÛ ÛÛ    ÛÛ ÛÛ     Û");
gotoxy(8,25);
cprintf(" ÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛ  ÛÛ     ÛÛ  ÛÛÛÛÛÛÛÛ   ÛÛ ÛÛ    ÛÛ ÛÛÛÛÛÛÛÛ ");
gotoxy(1,30);
randomize();
for(i=2;i<40;i++)
{
gotoxy(i,32);
delay(100);
textcolor(0);
cprintf("Û");
}
delay(100);
for(i=0;i<40;i++)
{
delay(5);
textcolor(0);
cprintf("Û");
}
}


clrscr();
for( i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
menu();
getch();
}
void game()
{
int number;
int guess;
int chances=0,score=0,chanscor;
char ans;
do
{
clrscr();
for(int i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
textcolor(BLACK);
gotoxy(8,20);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛÛÛÛÛ   ÛÛ    ÛÛ  ÛÛ        ÛÛÛÛÛÛ    ÛÛ      ÛÛ");
gotoxy(8,21);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛ       ÛÛ    ÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ      ÛÛ");
textcolor(RED);
gotoxy(8,22);
cprintf("ÛÛÛÛÛÛÛÛ  ÛÛ  ÛÛ       ÛÛÛÛÛÛÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ      ÛÛ");
gotoxy(8,23);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛ       ÛÛ    ÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ      ÛÛ");
textcolor(BLACK);
gotoxy(8,24);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛ   ÛÛ  ÛÛ    ÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ  ÛÛ  ÛÛ");
gotoxy(8,25);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛÛÛÛÛÛ  ÛÛ    ÛÛ  ÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛ     ÛÛÛ  ÛÛÛ ");
gotoxy(8,30);
textcolor(BLUE+BLINK);
cprintf("                   PrE$$ EnteR to cOntiNue");
getch();
clrscr();
textcolor(0);
cprintf(" ");
clrscr();
for( i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
chances=score=0;
gotoxy(35,10);
textcolor(BLACK);
cout<<"WELCOME TO HIGH LOW GAME";
gotoxy(35,16);
cout<<"Select your choice from 0-100";
gotoxy(35,18);
cout<<"You must try to guess the number";
randomize();
number=(int)(rand()%100);
chanscor=100/totchan;
do
{
h=20;
gotoxy(35,20);
cout<<"What is your guess?(0-100)";
cin>>guess;
if((guess<0)||(guess>100))
{
gotoxy(35,24);
cout<<"SORRY but your"<<guess<<"must be from 0-100";
}
else if(guess<number)
{
gotoxy(35,26);
cout<<guess<<" is LOW,try a higher number";
}
else if(guess>number)
{
gotoxy(35,28);
cout<<guess<<"is HIGH,try a lower number";
}
else
{
clrscr();
for(int i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
gotoxy(35,12);
cout<<guess<<"is correct";
score+=chanscor*(totchan-chances);
gotoxy(35,14);
cout<<"your score is"<<score<<endl;
textcolor(CYAN);
gotoxy(3,20);
cprintf("@@@@@@ @@@@@@@@ @@      @  @@@@@@    @@@@@@@        @@     @@@@@@@    @@@@@  ");
gotoxy(3,21);
cprintf("@      @      @ @ @     @  @         @     @       @  @       @      @          ");
gotoxy(3,22);
cprintf("@      @      @ @  @    @  @         @     @      @    @      @     @    ");
textcolor(BLACK);
gotoxy(3,23);
cprintf("@      @      @ @   @   @  @         @@@@@@@     @@@@@@@@     @    @@@@@  ");
gotoxy(3,24);
cprintf("@      @      @ @    @  @  @    @ @  @     @     @      @     @         @    ");
textcolor(MAGENTA);
gotoxy(3,25);
cprintf("@      @      @ @     @ @  @       @ @      @    @      @     @        @     ");
gotoxy(3,26);

cprintf("@@@@@@ @@@@@@@@ @      @@  @@@@@@@@@ @       @   @      @     @   @@@@@       ");

break;
}
chances++;
if (guess !=number)
gotoxy(35,30);
cout<<"Now you have"<<totchan-chances<<"chances left"<<endl;
if (chances==totchan)
{
gotoxy(33,32);
cout<<"Only"<<totchan<<"chances allowed";
clrscr();
for( i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
gotoxy(8,20);
textcolor(BLACK);
cprintf(" ÛÛÛÛÛ  ÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛ   ÛÛÛÛÛÛÛ ÛÛ      ÛÛ ÛÛÛÛÛ  ÛÛÛÛÛÛÛÛ");
gotoxy(8,21);
cprintf(" ÛÛ     ÛÛ   ÛÛ  ÛÛ  Û  Û ÛÛ       ÛÛ   ÛÛ  ÛÛ    ÛÛ  ÛÛ     ÛÛ    Û");
gotoxy(8,22);
textcolor(BROWN);
cprintf(" ÛÛ     ÛÛÛÛÛÛÛ  ÛÛ  Û  Û ÛÛÛÛÛÛ   ÛÛ   ÛÛ   ÛÛ  ÛÛ   ÛÛÛÛÛ  ÛÛÛÛÛÛÛ");
gotoxy(8,23);
cprintf(" ÛÛ  ÛÛ ÛÛ   ÛÛ  ÛÛ  Û  Û ÛÛ       ÛÛ   ÛÛ   ÛÛ  ÛÛ   ÛÛ     ÛÛ    Û");
textcolor(RED );
gotoxy(8,24);
cprintf(" ÛÛÛÛÛÛ ÛÛ   ÛÛ  ÛÛ  Û  Û ÛÛÛÛÛÛ   ÛÛÛÛÛÛÛ     ÛÛ     ÛÛÛÛÛ  ÛÛ    ÛÛ");
gotoxy(33,36);
cout<<"The actual number was"<<number<<endl;
break;
}
h=h+8;
} while(guess!=number);
gotoxy(33,35);
cout<<"Thank you for playing high low game ";
gotoxy(33,37);
gotoxy(33,39);
cout<<"Want to continnue?(y/n)";
cin>>ans;

}
while (ans=='y'||ans=='y');
}

void instrcts()
{
clrscr();
for(int i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
gotoxy(8,10);
textcolor(BLUE);
cprintf("ÛÛ  ÛÛÛÛÛ   ÛÛÛ ÛÛÛÛ  ÛÛÛÛ   Û  Û   ÛÛÛ ÛÛÛÛ  ÛÛ   ÛÛÛÛ   ÛÛÛÛ   ÛÛÛ");

cprintf("ÛÛ  ÛÛ ÛÛ   ÛÛ   ÛÛ   ÛÛ Û   Û  Û   Û    ÛÛ   ÛÛ   Û  Û    ÛÛ    ÛÛ");

cprintf("ÛÛ  ÛÛ ÛÛ  ÛÛÛ   ÛÛ   ÛÛ  Û  ÛÛÛÛ   ÛÛÛ  ÛÛ   ÛÛ   ÛÛÛÛ    ÛÛ   ÛÛÛ");
gotoxy(15,10);
cout<<"HIGH LOW is a number guessing game." ;
gotoxy(15,12);
cout<<"1.In this game the user chooses a number from 0-100.";
gotoxy(15,14);
cout<<"2.The users job is to guess correct number";
gotoxy(15,16);
cout<<"3.If the chosen number is below the required number";
gotoxy(15,18);
cout<<"4.Then the computer says that it is low";
gotoxy(15,20);
cout<<"5.Else if it is above the required number";
gotoxy(15,22);
cout<<"6.Then the computer indicates it is high";
gotoxy(15,24);
cout<<"7.The score is computed";
gotoxy(15,26);
cout<<"8.It reduces with the number of chances used";
gotoxy(15,28);
cout<<"9.Hence higher the chances lower the score ";
gotoxy(35,44);
textcolor(RED);
cprintf(" Pre$$ aNY Key for MAIN MENU");
getch();
menu();
}
void credits()
{
clrscr();
for(int i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}
gotoxy(8,20);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛÛÛÛÛ   ÛÛ    ÛÛ  ÛÛ        ÛÛÛÛÛÛ    ÛÛ      ÛÛ");
gotoxy(8,21);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛ       ÛÛ    ÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ      ÛÛ");
textcolor(BLACK);
gotoxy(8,22);
cprintf("ÛÛÛÛÛÛÛÛ  ÛÛ  ÛÛ       ÛÛÛÛÛÛÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ      ÛÛ");
gotoxy(8,23);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛ       ÛÛ    ÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ      ÛÛ");
textcolor(CYAN);
gotoxy(8,24);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛ   ÛÛ  ÛÛ    ÛÛ  ÛÛ      ÛÛ      ÛÛ  ÛÛ  ÛÛ  ÛÛ");
gotoxy(8,25);
cprintf("ÛÛ    ÛÛ  ÛÛ  ÛÛÛÛÛÛÛ  ÛÛ    ÛÛ  ÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛ     ÛÛÛ  ÛÛÛ ");
gotoxy(35,35);
cout<<                    "GaMe cREatEd bY R00^eYFul";
gotoxy(35,40);
textcolor(BLUE);
cprintf( "PrE$$ any key  for MAIN MENU");

getch();
menu();
}
void menu()
{
clrscr();
int c;
textcolor(0);
gotoxy(35,10);
cprintf("HIGH LOW GAME");
gotoxy(38,14);
cprintf("MENU");
gotoxy(35,22);
cprintf("1þNEW GAME");
gotoxy(35,24);
cprintf("2þHOW TO PLAY");
gotoxy(35,26);
cprintf("3þCREDITS");
gotoxy(35,28);
cprintf("4þEXIT");
gotoxy(35,32);
cprintf("ENTER THE CHOICE");
cin>>c;
switch(c)
{
case 1:game();
     break;
case 2:instrcts();
     break;
case 3:credits();
     break;
case 4:cout<<"4þEXIT";
     getch();
     exit(0);
default: cout<<"wrong choice";
for(int i=0;i<80;i++)
{
gotoxy(i,50);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<80;i++)
{
gotoxy(i,1);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=0;i<50;i++)
{
gotoxy(1,i);
textcolor(0);
cprintf("¯");
delay(10);
}
for(i=1;i<50;i++)
{
gotoxy(80,i);
textcolor(0);
cprintf("¯");
delay(10);
}

}
}
pretty bad because of the gotos used...i hate to use function ...Rolleyes
[Image: 52I4m.png]
Reply
#2
(05-03-2010, 02:03 AM)JesusOfSuburbia Wrote: Thank's for the share man Oui i will try this later!!!

sure..no problem mate...
[Image: 52I4m.png]
Reply
#3
I'm looking at it now, thanks
Reply
#4
Thanks a lot. I am going to check it. Smile
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)