#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <time.h>
#include <stdlib.h>
/* This program shows how to pick up the scan codes from a keyboard */
/* These define the scan codes(IBM) for the keys. All numbers are in decimal.*/
#define PAGE_UP 73
#define HOME 71
#define END 79
#define PAGE_DOWN 81
#define UP_ARROW 72
#define LEFT_ARROW 75
#define DOWN_ARROW 80
#define RIGHT_ARROW 77
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define F9 67
#define F10 68
void main()
{
char msg[100];
char KeyStroke;
time_t t;
int gd = DETECT, gm;
int i, x, y, flag=0;
int r=20;
int VerSpeed=1;
int HorSpeed=1;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI"); /* init graph */
/* get mid positions in x and y-axis */
x = getmaxx()/2;
y = getmaxy()/2;
clock_t startTime = clock();
do
{
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
//floodfill(x, y, RED);
circle(x, y, r);
if(x==50 && y==50)
{
printf("\nPerfect Matched, Game Over \nGame Time %.2lf Secs.\nPres ESC to close..",clock() / (double) CLOCKS_PER_SEC);
}
/* target circle */
setcolor(WHITE);
circle(50, 50, r);
/*line */
setlinestyle(SOLID_LINE, 2, 1);
line(0,350,700,350);
/* move the C.P. to the center of the screen */
moveto(getmaxx()-200,getmaxy()-100);
sprintf(msg,"Speed Ver:%d Hor:%d",VerSpeed,HorSpeed);
outtext(msg);
moveto(getmaxx()-200,getmaxy()-85);
outtext("PgUp : Inc Ver Speed");
moveto(getmaxx()-200,getmaxy()-70);
outtext("PgDown : Dec Ver Speed");
moveto(getmaxx()-200,getmaxy()-55);
outtext("Home : Inc Hor Speed");
moveto(getmaxx()-200,getmaxy()-40);
outtext("End : Dec Hor Speed");
moveto(getmaxx()-200,getmaxy()-25);
time(&t);
sprintf(msg,"Date : %s",ctime(&t));
outtext(msg);
moveto(getmaxx()-200,getmaxy()-10);
sprintf(msg,"Colck Secs : %.2lf",clock() / (double) CLOCKS_PER_SEC);
outtext(msg);
KeyStroke = getch();
if (KeyStroke == 0)
{
KeyStroke = getch(); // Even though there are 2 getch() it reads one keystroke
/* clears screen */
cleardevice();
switch (KeyStroke)
{
case UP_ARROW:
y-=VerSpeed;
circle(x, y, r);
break;
case DOWN_ARROW:
y+=VerSpeed;
circle(x, y, r);
break;
case LEFT_ARROW:
x-=HorSpeed;
circle(x, y, r);
break;
case RIGHT_ARROW:
x+=HorSpeed;
circle(x, y, r);
break;
case PAGE_UP:
VerSpeed+=1;
break;
case PAGE_DOWN:
VerSpeed-=1;
if(VerSpeed==-1)
VerSpeed=0;
break;
case HOME:
HorSpeed+=1;
break;
case END:
HorSpeed-=1;
if(HorSpeed==-1)
HorSpeed=0;
break;
}
}
else
//moveto(getmaxx()-100,getmaxy()-70);
cprintf("Use Arrow KeyStroke");
}
while (KeyStroke != 27); // 27 = Escape key
/* timee display */
/*
clock_t endTime = clock();
clock_t clockTicksTaken = endTime - startTime;
double timeInSeconds = clockTicksTaken / (double) CLOCKS_PER_SEC;
printf("\n%lf",timeInSeconds);
*/
getch();
closegraph();
}
--------------------------------------------------------------------------------------------------------------------------
Output Screens
--------------------------------------------------------------------------------------------------------------------------
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <time.h>
#include <stdlib.h>
/* This program shows how to pick up the scan codes from a keyboard */
/* These define the scan codes(IBM) for the keys. All numbers are in decimal.*/
#define PAGE_UP 73
#define HOME 71
#define END 79
#define PAGE_DOWN 81
#define UP_ARROW 72
#define LEFT_ARROW 75
#define DOWN_ARROW 80
#define RIGHT_ARROW 77
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define F9 67
#define F10 68
void main()
{
char msg[100];
char KeyStroke;
time_t t;
int gd = DETECT, gm;
int i, x, y, flag=0;
int r=20;
int VerSpeed=1;
int HorSpeed=1;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI"); /* init graph */
/* get mid positions in x and y-axis */
x = getmaxx()/2;
y = getmaxy()/2;
clock_t startTime = clock();
do
{
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
//floodfill(x, y, RED);
circle(x, y, r);
if(x==50 && y==50)
{
printf("\nPerfect Matched, Game Over \nGame Time %.2lf Secs.\nPres ESC to close..",clock() / (double) CLOCKS_PER_SEC);
}
/* target circle */
setcolor(WHITE);
circle(50, 50, r);
/*line */
setlinestyle(SOLID_LINE, 2, 1);
line(0,350,700,350);
/* move the C.P. to the center of the screen */
moveto(getmaxx()-200,getmaxy()-100);
sprintf(msg,"Speed Ver:%d Hor:%d",VerSpeed,HorSpeed);
outtext(msg);
moveto(getmaxx()-200,getmaxy()-85);
outtext("PgUp : Inc Ver Speed");
moveto(getmaxx()-200,getmaxy()-70);
outtext("PgDown : Dec Ver Speed");
moveto(getmaxx()-200,getmaxy()-55);
outtext("Home : Inc Hor Speed");
moveto(getmaxx()-200,getmaxy()-40);
outtext("End : Dec Hor Speed");
moveto(getmaxx()-200,getmaxy()-25);
time(&t);
sprintf(msg,"Date : %s",ctime(&t));
outtext(msg);
moveto(getmaxx()-200,getmaxy()-10);
sprintf(msg,"Colck Secs : %.2lf",clock() / (double) CLOCKS_PER_SEC);
outtext(msg);
KeyStroke = getch();
if (KeyStroke == 0)
{
KeyStroke = getch(); // Even though there are 2 getch() it reads one keystroke
/* clears screen */
cleardevice();
switch (KeyStroke)
{
case UP_ARROW:
y-=VerSpeed;
circle(x, y, r);
break;
case DOWN_ARROW:
y+=VerSpeed;
circle(x, y, r);
break;
case LEFT_ARROW:
x-=HorSpeed;
circle(x, y, r);
break;
case RIGHT_ARROW:
x+=HorSpeed;
circle(x, y, r);
break;
case PAGE_UP:
VerSpeed+=1;
break;
case PAGE_DOWN:
VerSpeed-=1;
if(VerSpeed==-1)
VerSpeed=0;
break;
case HOME:
HorSpeed+=1;
break;
case END:
HorSpeed-=1;
if(HorSpeed==-1)
HorSpeed=0;
break;
}
}
else
//moveto(getmaxx()-100,getmaxy()-70);
cprintf("Use Arrow KeyStroke");
}
while (KeyStroke != 27); // 27 = Escape key
/* timee display */
/*
clock_t endTime = clock();
clock_t clockTicksTaken = endTime - startTime;
double timeInSeconds = clockTicksTaken / (double) CLOCKS_PER_SEC;
printf("\n%lf",timeInSeconds);
*/
getch();
closegraph();
}
--------------------------------------------------------------------------------------------------------------------------
Output Screens
--------------------------------------------------------------------------------------------------------------------------