#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int mx,my;
int user=0;
void border();
void display(int rem,int you)
{
int nol,xno=35;
cleardevice();
border();
setcolor(getmaxcolor());
for(nol=1;nol<=rem;nol++)
{
line(xno,35,xno,135);
xno+=27;
}
gotoxy(35,14);
printf("STICKS LEFT : %d",rem);
if(user==1)
{
gotoxy(35,20);
printf("I PICK : %d",5-you);
settextstyle(10,0,4);
outtextxy(190,350,"MY TURN");
user=0;
getch();
display(rem-5+you,5-you);
}
if(user==0)
{
gotoxy(35,20);
printf("YOU PICK : ");
settextstyle(10,0,4);
outtextxy(180,350,"YOUR TURN");
if(rem!=1)
{
scanf("%d",&you);
if(you<0||you>4)
{ cleardevice();
settextstyle(10,0,4);
outtextxy(190,350,"INVALID");
}
user=1;
display(rem-you,you);
}
if(rem==0||rem==1)
{
cleardevice ();
border();
setcolor(RED);
settextstyle(4,0,5);
outtextxy(180,200,"YOU LOST !!");
getch();
cleardevice();
border();
setcolor(13);
settextstyle(3,0,3);
outtextxy(210,40,"DEVELOPED BY :");
setcolor(9);
settextstyle(4,0,6);
outtextxy(40,180,"LAXMAN D CHOUHAN");
setcolor(12);
settextstyle(1,0,1);
outtextxy(60,330,"PLEASE SEND YOUR SUGGESTIONS AND FEEDBACK AT");
setcolor(14);
settextstyle(3,0,2);
outtextxy(195,348,"[[Email Removed]]");
getch();
exit(0);
}
}
if(user==2)
user=0;
}
void border()
{
setcolor(YELLOW);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
}
int main(void)
{ int comp,you;
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
printf("\n\nIN THIS GAME THERE ARE 21 STICKS.");
printf("\n\nYOU AND I CAN PICK UP 1,2,3 OR 4 STICKS AT A TIME.");
printf("\n\nWE WILL ALTERNATIVELY PICK UP STICKS AND THE PERSON WHO PICKS THE LAST STICK IS THE LOSER.");
printf("\nAND I PROMISE IT WILL BE YOU.");
printf("\n\n\nPRESS ENTER TO BEGIN THE GAME.......");
getch();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\tc\\bgi");
mx = getmaxx();
my = getmaxy();
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
display(21,0);
getch();
/* clean up */
getch();
closegraph();
return 0;
}