/*
Syed Mehroz Alam
CIS-61, First Year, Sec-A, Batch 2002-03
Computer & Information Systems Dept,
NED University, Karachi, Pakistan.
Email: smehrozalam@yahoo.com
22-June-2003
*/
#include
#include
#include
#include
#include
#include
#include
#define ENTER_KEY '\r'
#define ESCAPE_KEY 27
#define SPECIAL_KEY 0
#define UP_ARROW 72
#define DOWN_ARROW 80
#define LEFT_ARROW 75
#define RIGHT_ARROW 77
/* following values can be changed to alter the game flow
LEN: no. of balls
MAX_COLOR: no. of colors
MAX_TURN: no. of turns
*/
#define LEN 4
#define MAX_COLOR 6
#define MAX_TURN 10
void graphic_mode(void); //initializes graphics mode
void input_pattern(void); //inputs pattern from player1
void guess_pattern(void); //inputs pattern from player2
int color[LEN];
void main(void)
{
clrscr();
randomize();
graphic_mode();
char opt;
do
{
input_pattern();
guess_pattern();
cleardevice();
outtextxy(200,getmaxy()/2-20, "Play again (Press \"y\" for yes)");
opt=getch();
}
while ( opt=='y' || opt=='Y');
closegraph();
}
void graphic_mode(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "..\\bgi\\");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
}
void input_pattern(void)
{
cleardevice();
char temp[100];
setcolor(15);
sprintf(temp, "Each of the following %d balls can have 1 out of %d colors",LEN,MAX_COLOR);
outtextxy (300,10, "Mind Guesser");
setcolor(7);
outtextxy (10,22, "Programmed by Syed Mehroz Alam");
outtextxy (10,34, "CIS-61, First Year, Batch 2002-03");
outtextxy (10,46, "Computer & Information Systems Dept, NED University.");
outtextxy (10,58, "NED University.");
outtextxy (10,70, "Email: smehrozalam@yahoo.com");
outtextxy (10,95,temp);
outtextxy (10,110, "Player 1, Choose your pattern");
outtextxy (10,122, "Press Left & Right arrow keys to change current ball");
outtextxy (10,134, "Press Up & Down arrow keys to toggle color");
outtextxy (10,146, "Press 'R' for generating a random pattern");
outtextxy (10,158, "Press when done");
setcolor(15);
int pos=0, key, key2;
for (int i=0;iMAX_COLOR ) color[pos]=1;
else if ( color[pos]<1) color[pos]=MAX_COLOR;
if (pos>LEN-1) pos=LEN-1;
else if (pos<0) pos=0;
} //end elseif special key
setfillstyle(1,color[pos]);
fillellipse(30+pos*45, 200, 20, 20);
}
while (key!=ENTER_KEY);
}
void guess_pattern(void)
{
int y=0,x=0,turn=0, pos=0,key,key2,color[LEN]={0};
cleardevice();
char temp[80];
setcolor(7);
outtextxy (2,2, "Player 2, Enter your choice then press ");
sprintf(temp, "You have %d turns, Each ball can have 1 out of %d colors, ", MAX_TURN, MAX_COLOR);
outtextxy (2,12, temp);
outtextxy (2,25, "Scoring Criteria:");
outtextxy (2,35, "No. of blue pegs = no. of correct balls at correct places");
outtextxy (2,45, "No. of green pegs = no. of correct balls at incorrect places");
setcolor(15);
for (int j=0;jMAX_COLOR ) color[pos]=1;
if ( color[pos]<1) color[pos]=MAX_COLOR;
if (pos>LEN-1) pos=LEN-1;
if (pos<0) pos=0;
} //end elseif special key
setfillstyle(1,color[pos]);
fillellipse(30+pos*45+x*300, 90+y*50, 20, 20);
}
while (key!=ENTER_KEY);
//start scoring
int blue_peg=0,green_peg=0;
for (i=0;i               ( geocities.com/smehrozalam)