Thursday 15 October 2015

This is another simple game using C/C++ graphics , Have a look

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
void border();
void main()
{
int gd=0,gm=0,i,x,y,xt,k=1,s=1,cl;
char ch[100][2],c;
clrscr();
printf("\n\n\tThis is very simple game.");
printf("\n\tCreated By ---THE SMIT---");
printf("\n\tYou need to press key which falls");
printf("\n\t Case Sensitive");
printf("\n\n For exit press = p\n");
printf("Press any key to start");
getch();
clrscr();
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
for(i=0;i<26;i++)
{
ch[i][0] =i + 65;
ch[i][1] = '\0';
}
border();
x=10;
y=12;
for(i=0;i<26;i++,x+=24)
{
settextstyle(0,0,2);
cl = random(15);
if(cl==0)
cl++;
setcolor(cl);
outtextxy(x,1
2,ch[i]);
}
S:
border();
xt = random(26);
x = 10 + (24 * xt);
for(y=12,i=0;y<470;y+=15,i++)
{
if(i%2==0)
{
cl = random(15);
if(cl==0);
cl++;
setcolor(cl);
settextstyle(0,0,2);
outtextxy(x,y,ch[xt]);
delay(50-(s/2));
setcolor(0);
outtextxy(x,y,ch[xt]);
border();
}
else
{
cl = random(15);
if(cl==0);
cl++;
setcolor(cl);
settextstyle(0,0,2);
outtextxy(x+5,y,ch[xt]);
delay(50-(s/2));
setcolor(0);
outtextxy(x+5,y,ch[xt]);
border();
}
if(kbhit())
{
c = getche();
if(c == ch[xt][0])
{
settextstyle(0,0,2);
cl = random(15);
if(cl==0)
cl++;
settextstyle(0,0,7);
setcolor(cl);
outtextxy(320,240,ch[xt]);
delay(500);
setcolor(0);
outtextxy(320,240,ch[xt]);
setcolor(cl);
settextstyle(0,0,2);
circle(260,240,120);
outtextxy(150,240,"Scored a point");
delay(500);
setcolor(0);
outtextxy(150,240,"Scored a point");
circle(260,240,120);
s+=8;
border();
goto S;
}
if(c == 'p')
goto Y;
}
settextstyle(0,0,2);
if(y>=410)
{
cl = random(15);
if(cl==0)
cl++;
setcolor(cl);
circle(260,240,120);
outtextxy(150,240,"Missed a point");
delay(500);
setcolor(0);
circle(260,240,120);
outtextxy(150,240,"Missed a point");
border();
k++;
if(k>5)
goto Y;
else
goto S;
}

delay(50);
}
Y:
closegraph()    ;
printf("\n\nYour Score = %d",s);
printf("\n\n\t\n\tThanx for playing...");
printf("\n\tHope you would have nice time");

getch();
 }

 void border()                             //border formation
{
int x,y,cl;
char ch[10]="smit ";
setcolor(1);
rectangle(0,0,639,479);
for(x=2,y=2;x<639;x+=40)
{
settextstyle(0,0,1);
cl = random(15);
if(cl == 0)
cl++;
setcolor(cl);
outtextxy(x,y,ch);
outtextxy(x,y+470,ch);
}
for(x=10,y=1;y<480;y+=40)
{
settextstyle(0,1,1);
cl = random(15);
if(cl == 0)
cl++;
setcolor(cl);
outtextxy(x,y,ch);
outtextxy(x+630,y,ch);
}
setcolor(random(15));
rectangle(10,10,630,470);
}








-When you score a point














-When you miss the point

2 comments:

  1. This code will work on both Turbo C and codeblock as well.

    ReplyDelete
  2. ATTENTION : - Here the character falling are Capital letter so use Caps to capture .

    ReplyDelete

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...