Tuesday, October 4, 2011

Typing Game in C

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

#include<dos.h>

void main()

{

clrscr();

int i=26,x,y,y1,x1,y2,lives=3,score=0,S=100;

char s,a;

randomize();

while(a!=27)

{

x=random(75);

y=1;

s=random(i)+65;

while(y<=25)

{

gotoxy(x,y);

textcolor(RED);

cprintf("%c",s);

delay(S);

gotoxy(x,y);

textcolor(BLACK);

cprintf("%c",s);

delay(S);

 

if(kbhit())

{

a=getch();

y1=20;

 if(s==a)

{

  gotoxy(x,y);

textcolor(RED);

cprintf("%c",s);

//y=10;

while(y1>=y)

{

textcolor(BLUE);

gotoxy(x,y1);

cprintf("*");

delay(S);

textcolor(BLACK);

gotoxy(x,y1);

cprintf("*");

delay(S);

y1--;

}

score=score+10;

textcolor(RED);

gotoxy(5,25);

cprintf("Score: %d",score);

break;

}

if(a==27)

break;

}

if(score==200)

{

S+=20;

}

y++;

//y1--;

}

if(y>23)

{

 lives-=1;

 

  if(lives<0)

  {

  clrscr();

  textcolor(GREEN);

  gotoxy(30,12);

  cprintf("You lose the game ,press any key");

  getch();

  exit(0);

  }

  textcolor(GREEN);

  gotoxy(72,24);

  cprintf("%d",lives);

  }

  }

  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

No comments :

Post a Comment