#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
void display()
{
cout << "--------------------------------------------------------------------------------";
cout << "-------------------------------WORD GUESSING GAME-------------------------------";
cout << "--------------------------------------------------------------------------------";
cout << "\n\n Start Game";
cout << "\n\n How to Play";
cout << "\n\n Credits";
cout << "\n\n Quit";
gotoxy(22,25);
cout<<"Press \'W\' to go up and \'S\' to go down";
gotoxy(29,24);
cout<<"Press <ENTER> to select";
}
struct coordinate
{ int x,y;};
struct level
{
char hint[5][11];
char answer[10];
};
void youwin(int points)
{
clrscr();
gotoxy(1,1);
cout<<" .\n";
cout<<" J:L (\"\"\")\n";
cout<<" |:| III\n";
cout<<" |:| III\n";
cout<<" |:| III\n" ;
cout<<" |:| __III__\n";
cout<<" |:| /:-.___,-:\\\n";
cout<<" |:| \\] |:| [/\n" ;
cout<<" |:| |:|\n" ;
cout<<" |:| |:|\n" ;
cout<<" |:| |:|\n" ;
cout<<"/] |:| [\\ |:|\n" ;
cout<<"\\:-'\"\"\"`-:/ |:|\n" ;
cout<<" \"\"III\"\" |:|\n";
cout<<" III |:|\n" ;
cout<<" III |:|\n" ;
cout<<" III |:|\n" ;
cout<<" (___) J:F \n" ;
cout<<" \"" ;
gotoxy(35,8);
cout<<"__ __ _ \n";
gotoxy(35,9);
cout<<"\\ \\/ /___ __ __ _ __(_)___ \n";
gotoxy(35,10);
cout<<" \\ / __ \\/ / / / | | /| / / / __ \\\n";
gotoxy(35,11);
cout<<" / / /_/ / /_/ / | |/ |/ / / / / /\n";
gotoxy(35,12);
cout<<"/_/\\____/\\__,_/ |__/|__/_/_/ /_/ \n";
gotoxy(43,15);
cout<<"Your points are "<< points;
}
void prtchar(char x,int length)
{
for (int i = 1; i <=length; i++)
{
cout << x;
}
}
void prtbox(coordinate &a,coordinate &b)
{
gotoxy(a.x,a.y);
prtchar('-',((b.x)-(a.x)+1));
gotoxy(a.x,b.y);
prtchar('-',((b.x)-(a.x)+1));
int x;
for(x=((a.y)+1);x<b.y;x++)
{
gotoxy(a.x,x);
cout<<'|';
gotoxy(b.x,x);
cout<<'|';
}
}
void select(int selection)
{
coordinate a,b;
if (selection==0)
{
a.x= 35;
a.y= 5;
b.x= 46;
b.y= 7;
}
else if (selection ==1)
{
a.x=34;
a.y=7;
b.x=46;
b.y=9;
}
else if (selection == 2)
{
a.x=36;
a.y=9;
b.x=44;
b.y=11;
}
else if (selection== 3)
{
a.x=37;
a.y=11;
b.x=42;
b.y=13;
}
prtbox(a,b);
}
void assignlevel(level &a,int select)
{
if(select==1)
{
strcpy(a.hint[0],"dough");
strcpy(a.hint[1],"wheat");
strcpy(a.hint[2],"5 lettered");
strcpy(a.hint[3],"bun");
strcpy(a.hint[4],"bakery");
strcpy(a.answer,"bread");
}
else if(select==2)
{
strcpy(a.hint[0],"jackpot");
strcpy(a.hint[1],"luck");
strcpy(a.hint[2],"lotto");
strcpy(a.hint[3],"win");
strcpy(a.hint[4],"bingo");
strcpy(a.answer,"lottery");
}
else if(select==3)
{
strcpy(a.hint[0],"egypt");
strcpy(a.hint[1],"pharoh");
strcpy(a.hint[2],"triangle");
strcpy(a.hint[3],"tomb");
strcpy(a.hint[4],"sphinx");
strcpy(a.answer,"pyramid");
}
else if(select==4)
{
strcpy(a.hint[0],"device");
strcpy(a.hint[1],"electronic");
strcpy(a.hint[2],"widget");
strcpy(a.hint[3],"inspector");
strcpy(a.hint[4],"gizmo");
strcpy(a.answer,"gadget");
}
else if(select==5)
{
strcpy(a.hint[0],"fish");
strcpy(a.hint[1],"rice");
strcpy(a.hint[2],"japanese");
strcpy(a.hint[3],"roll");
strcpy(a.hint[4],"dish");
strcpy(a.answer,"sushi");
}
else if(select==6)
{
strcpy(a.hint[0],"fog");
strcpy(a.hint[1],"air");
strcpy(a.hint[2],"london");
strcpy(a.hint[3],"pollution");
strcpy(a.hint[4],"fumes");
strcpy(a.answer,"smog");
}
else if(select==7)
{
strcpy(a.hint[0],"event");
strcpy(a.hint[1],"gregorian");
strcpy(a.hint[2],"date");
strcpy(a.hint[3],"month");
strcpy(a.hint[4],"year");
strcpy(a.answer,"calendar");
}
else if(select==8)
{
strcpy(a.hint[0],"snack");
strcpy(a.hint[1],"pastry");
strcpy(a.hint[2],"cookie");
strcpy(a.hint[3],"dough");
strcpy(a.hint[4],"crispy");
strcpy(a.answer,"biscuit");
}
else if(select==9)
{
strcpy(a.hint[0],"wall");
strcpy(a.hint[1],"stone");
strcpy(a.hint[2],"block");
strcpy(a.hint[3],"house");
strcpy(a.hint[4],"red");
strcpy(a.answer,"brick");
}
else if(select==10)
{
strcpy(a.hint[0],"racket");
strcpy(a.hint[1],"set");
strcpy(a.hint[2],"ball");
strcpy(a.hint[3],"table");
strcpy(a.hint[4],"court");
strcpy(a.answer,"tennis");
}
else
{
strcpy(a.hint[0],"Level not designed");
strcpy(a.hint[1],"???");
strcpy(a.hint[2],"???");
strcpy(a.hint[3],"???");
strcpy(a.hint[4],"???");
strcpy(a.answer,"???");
}
}
int levels(int select)
{
level a;
char inp; //for accepting commands
char input[10]; //for accepting answer
coordinate b,c;
int i,loopvar=0; //loop variable
int hint =0;
while(1)
{
gotoxy(36,3);
cout<< "LEVEL "<<select;
assignlevel(a,select);
gotoxy(1,2);
cout << "Points for winning "<< (100 - (20*hint));
b.x=20;
b.y=1;
c.y=3;
if (hint ==0)
{
c.x=24;
}
else
{
c.x=23;
}
gotoxy(60,2);
cout<<"Press \'+\' for hint";
prtbox(b,c);
for(i=0;i<=hint;i++) // example "dough", 80/2 = 40(middle), 40+-2=range
{
gotoxy((40-(strlen(a.hint[i])/2)),(6+(i*2)));
cout << a.hint[i];
}
b.y=17;
c.y=19;
b.x=(39.5-(0.5*(double(loopvar)))); //print answer box
c.x=(41.5+(0.5*(double(loopvar))));
prtbox(b,c);
gotoxy(((39.5-(0.5*(double(loopvar))))+1),(18));
for(i=0;i<loopvar;i++)
{
cout<<input[i];
}
cout<<' ';
for(i=0;a.answer!='\0';i++)
{
if(input[i]!=a.answer[i])
break;
if((strlen(a.answer)-1)==i)
{
clrscr();
youwin(100 - (20*hint));
getch();
clrscr();
return 0;
}
}
inp=getch();
clrscr();
if(inp=='+')
{
if(hint!=4)
{
hint++;
}
}
else if(inp==8) //backspace for clearing characters of answer[10]
{
if(loopvar!=0)
{
loopvar--;
}
}
else if( ((inp>='a')&&(inp<='z'))||((inp>='A')&&(inp<='Z')))
{
if(loopvar!=8)
{
input[loopvar]=inp;
loopvar++;
}
}
else if(inp=='-') //'-' for going back
{
break;
}
}
clrscr();
return 0;
}
void startgame()
{
int select=1;
char c;
while(1)
{ gotoxy(28,1);
cout<<" __ __ __";
gotoxy(28,2);
cout<<"| | | | | | |";
gotoxy(28,3);
cout<<"| |-- | | |-- | --";
gotoxy(28,4);
cout<<"|__ |__ \\/ |__ |__ __|";
int x;
coordinate a,b;
for(x=1;x<10;x++)
{
gotoxy(((x*7)+2),8);
cout<<x;
a.x=((x*7)+1);
b.x=((x*7)+3);
a.y=7;
b.y=9;
prtbox(a,b);
}
a.x=71;
b.x=74;
a.y=7;
b.y=9;
gotoxy(72,8);
cout<<10;
prtbox(a,b);//box 10 printed
if(select!=10)
{
a.x=(7*select);
b.x=((7*select)+4);
a.y=6;
b.y=10;
}
else
{
a.x=70;
b.x=75;
a.y=6;
b.y=10;
}
prtbox(a,b);
c=getch();
clrscr();
if ((c=='a')||(c=='A'))
{
if(select!=1)
{
select--;
}
}
else if ((c=='d')||(c=='D'))
{
if(select!=10)
{
select++;
}
}
else if (c=='-')//'-' for going back to main page
{
break;
}
else if (c==13)
{
levels(select);
}
}
}
void howtoplay()
{
gotoxy(35,3);
cout<<"HOW TO PLAY";
gotoxy(1,5);
cout<<"\nPress \'W\' and \'S\' to go up and down\n";
cout<<"Press \'A\' and \'D\' to go left and right\n";
cout<<"Press <Enter> to select\n";
cout<<"Press \'-\' to go back\n";
cout<<"For each hint 20 points will be reduced";
cout<<"\n\nPRESS ANY KEY TO GO BACK";
getch();
}
void credits()
{
int i=25;
for(;i>=-8;i--)
{
clrscr();
if((i>0)&&(i<=25))
{
gotoxy(37,i);
cout<<"CREDITS";
}
if(((i+3)>0)&&((i+3)<=25))
{
gotoxy(34,(i+3));
cout<<"Deepak Prasad";
}
if(((i+5)>0)&&((i+5)<=25))
{
gotoxy(35,(i+5));
cout<<"Vikas Kumar";
}
if(((i+7)>0)&&((i+7)<=25))
{
gotoxy(30,(i+7));
cout<<"Abhishek Kumar Mahato";
}
if(((i+9)>0)&&((i+9)<=25))
{
gotoxy(35,(i+9));
cout<<"Sumit Kumar";
}
delay(200);
}
}
void quit()
{
clrscr();
retry:
gotoxy(27,12);
cout<<"Do you really want to quit?";
gotoxy(38,13);
cout<<"Y/N";
char c;
c= getch();
if((c=='y')||(c=='Y'))
exit(0);
else if(!((c=='n')||(c=='N')))
goto retry;
}
void main()
{
char c='w';
int selec=0;
while(1)
{
clrscr();
display();
select(selec);
c=getch();
if((c=='w')||(c=='W'))//up
{
if(selec!=0)
selec--;
}
else if((c=='s')||(c=='S'))//down
{
if(selec!=3)
selec++;
}
else if (c=='-')
break;
else if(c==13) //enter for selection(ASCII value 13)
{
clrscr();
if(selec==0)
startgame();
else if(selec==1)
howtoplay();
else if(selec==2)
credits();
else if(selec==3)
quit();
}
}
}