Your Ad Here

Friday, October 10, 2008

Journey to my college

/***************************************************************************/
/* JORNEY TO PITHAWALLA COLLEGE */
/* */
/* CG Project */
/* By Jain Nikunj A */
/* C.K.Pithawala College of Engg. & Tech. */
/* B.E. Computer-III, 5th Sem (6124) */
/***************************************************************************/


#include stdlib.h
#include conio.h
#include graphics.h
#include dos.h
#include alloc.h

// Global variables

void *back,*dot,*obj1,*o1,*obj2,*o2,*turn,*text,*selector,*cselector;
unsigned int size;

int z=640,dice=0,user=0,ch=0,x1=605,y1=455,x2=625,y2=455,cnt1=1,cnt2=1,x,y;
int dirrl1=1,dirbt1=0,dirlr1=0,dirtb1=0;
int dirrl2=1,dirbt2=0,dirlr2=0,dirtb2=0;
int mvone1=0,mvone2=0,missone1=0,missone2=0;
int r=0;

//Function to draw the board of game

void board()
{
int k=1;
setlinestyle(SOLID_LINE, 1, 0);
setcolor(0);
for(x=1;x<=16;x++)
{
if (x==8)
{
setcolor(4);
setfillstyle(SOLID_FILL, 4);
rectangle(z-40,440,z,480);
floodfill(z-30,450,4);
}
else if(x==13)
{
setcolor(4);
setfillstyle(SOLID_FILL, 4);
rectangle(z-40,440,z,480);
floodfill(z-30,450,4);
}
else
{
setcolor(k);
setfillstyle(SOLID_FILL, k);
rectangle(z-40,440,z,480);
floodfill(z-30,450,k);
}
k+=2;
z-=40;
}
z=440;
for(x=1;x<=11;x++)
{
if (x==2)
{
setcolor(4);
setfillstyle(SOLID_FILL, 4);
rectangle(0,z-40,40,z);
floodfill(10,z-30,4);
}
else if (x==6)
{
setcolor(2);
setfillstyle(SOLID_FILL, 2);
rectangle(0,z-40,40,z);
floodfill(10,z-30,2);
}
else
{
setcolor(k);
setfillstyle(SOLID_FILL, k);
rectangle(0,z-40,40,z);
floodfill(10,z-30,k);
}
k+=2;
z-=40;
}
z=40;
for(x=1;x<=16;x++)
{
if (x==5)
{
setcolor(2);
setfillstyle(SOLID_FILL, 2);
rectangle(z-40,0,z,40);
floodfill(z-30,10,2);
}
else
{
setcolor(k);
setfillstyle(SOLID_FILL, k);
rectangle(z-40,0,z,40);
floodfill(z-30,10,k);
}
k+=2;
z+=40;
}
z=80;
for(x=1;x<=10;x++)
{
if (x==6)
{
setcolor(4);
setfillstyle(SOLID_FILL, 4);
rectangle(600,z-40,640,z);
floodfill(610,z-30,4);
}
else
{
setcolor(k);
setfillstyle(SOLID_FILL, k);
rectangle(600,z-40,640,z);
floodfill(610,z-30,k);
}
k+=2;
z+=40;
}
outtextxy(250,60,"Press Esc to Exit");

}

//Function to do numbering the board

void numbering()
{
setcolor(DARKGRAY);
outtextxy(0,470,"16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 GO");
outtextxy(0,430,"17");
outtextxy(0,390,"18");
outtextxy(0,350,"19");
outtextxy(0,310,"20");
outtextxy(0,270,"21");
outtextxy(0,230,"22");
outtextxy(0,190,"23");
outtextxy(0,150,"24");
outtextxy(0,110,"25");
outtextxy(0,70,"26");
outtextxy(0,30,"27");
outtextxy(40,30,"28 29 30 31 32 33 34 35 36 37 38 39 40 41 42");
outtextxy(600,430,"52");
outtextxy(600,390,"51");
outtextxy(600,350,"50");
outtextxy(600,310,"49");
outtextxy(600,270,"48");
outtextxy(600,230,"47");
outtextxy(600,190,"46");
outtextxy(600,150,"45");
outtextxy(600,110,"44");
outtextxy(600,70,"43");
setcolor(RED);
line(600,440,640,480);
setcolor(6);
outtextxy(612,445,"WIN");
}

//Function to display the dice number

void dispdice()
{
switch (dice)
{
case 1: putimage(315, 235, dot, COPY_PUT); break;
case 2: putimage(295, 215, dot, COPY_PUT);
putimage(335, 255, dot, COPY_PUT); break;
case 3: putimage(295, 215, dot, COPY_PUT);
putimage(315, 235, dot, COPY_PUT);
putimage(335, 255, dot, COPY_PUT); break;
case 4: putimage(295, 215, dot, COPY_PUT);
putimage(335, 215, dot, COPY_PUT);
putimage(335, 255, dot, COPY_PUT);
putimage(295, 255, dot, COPY_PUT); break;
case 5: putimage(295, 215, dot, COPY_PUT);
putimage(335, 215, dot, COPY_PUT);
putimage(335, 255, dot, COPY_PUT);
putimage(295, 255, dot, COPY_PUT);
putimage(315, 235, dot, COPY_PUT); break;
case 6: putimage(295, 215, dot, COPY_PUT);
putimage(335, 215, dot, COPY_PUT);
putimage(295, 235, dot, COPY_PUT);
putimage(335, 235, dot, COPY_PUT);
putimage(295, 255, dot, COPY_PUT);
putimage(335, 255, dot, COPY_PUT); break;
}
}

//Function to get the dice number

void getdice()
{
dice=random(6);
dice++;
dispdice();
}

//Function to print the status of each box

void status()
{
setcolor(14);
outtextxy(270, 175, "Dice output..");
outtextxy(270, 120, "Turn..");
setcolor(4);
setlinestyle(SOLID_LINE, 1, 3);
rectangle(270, 190, 370, 290);
rectangle(270, 135, 370, 160);
}

//Code for playing the game or movement of the player object

void play()
{
int i;
getimage(605,455,615,465,o1);
getimage(625,455,635,465,o2);
putimage(605,455,obj1,COPY_PUT);
putimage(625,455,obj2,COPY_PUT);
while(1)
{
if(user==0)
{
putimage(185,325,text,COPY_PUT);
putimage(272,137,turn,COPY_PUT);
setcolor(GREEN);
outtextxy(275,145," PLAYER 1");
again: ch=getch();
if (ch==13)
{
getdice();
}
else if (ch==27)
{
goto over;
}
else
{
goto again;
}
if (missone1==0 && cnt1==18)
{
missone1=1;
user=1;
outtextxy(215,330," He is at petrol pump");
delay(2000);
goto invalid1;
}
if (cnt1==48 && dice>5)
{
user=1;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid1;
}
else if (cnt1==49 && dice>4)
{
user=1;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid1;
}
else if (cnt1==50 && dice>3)
{
user=1;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid1;
}
else if (cnt1==51 && dice>2)
{
user=1;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid1;
}
else if (cnt1==52 && dice>1)
{
user=1;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid1;
}
if (cnt1==8)
{
mvone1=1;
outtextxy(225,330,"Wating for his friend");
delay(1000);
}
if (mvone1==0 || dice==1) //make a change
{
mvone1=0;
for (i=1;i<=dice;i++,cnt1++)
{
putimage(x1,y1,o1,COPY_PUT);
if (dirrl1==1)
{
x1-=40;
if (x1<0)
{
x1+=40;
y1-=40;
dirbt1=1;
dirrl1=0;
}
getimage(x1,y1,x1+10,y1+10,o1);
putimage(x1,y1,obj1,COPY_PUT);
delay(300);
}
else if (dirbt1==1)
{
y1-=40;
if (y1<0)
{
y1+=40;
x1+=40;
dirbt1=0;
dirlr1=1;
}
getimage(x1,y1,x1+10,y1-10,o1);
putimage(x1,y1,obj1,COPY_PUT);
delay(300);
}
else if (dirlr1==1)
{
x1+=40;
if (x1>640)
{
x1-=40;
y1+=40;
dirtb1=1;
dirlr1=0;
}
getimage(x1,y1,x1+10,y1+10,o1);
putimage(x1,y1,obj1,COPY_PUT);
delay(300);
}
else if (dirtb1==1)
{
y1+=40;
if (y1>480)
{
dirtb1=0;
//finish
putimage(605,455,obj1,COPY_PUT);
goto over;
}
getimage(x1,y1,x1+10,y1+10,o1);
putimage(x1,y1,obj1,COPY_PUT);
delay(300);
}
}
if (cnt1==53)
{
goto over;
}
if (cnt1==13)
{
putimage(185,325,text,COPY_PUT);
outtextxy(225,330,"Forgot his File at home");
delay(2000);
putimage(x1,y1,o1,COPY_PUT);
x1=605;
y1=455;
getimage(605,455,615,465,o1);
putimage(605,455,obj1,COPY_PUT);
cnt1=1;
}
if (cnt1==22)
{
putimage(185,325,text,COPY_PUT);
outtextxy(255,330,"Took a Shortcut");
delay(2000);
putimage(x1,y1,o1,COPY_PUT);
x1=125;
y1=15;
getimage(125,15,135,25,o1);
putimage(125,15,obj1,COPY_PUT);
cnt1=30;
dirbt1=0;
dirlr1=1;
}
if (cnt1==31)
{
putimage(185,325,text,COPY_PUT);
outtextxy(255,330,"Took a Shortcut");
delay(2000);
putimage(x1,y1,o1,COPY_PUT);
x1=605;
y1=55;
getimage(605,55,615,65,o1);
putimage(605,55,obj1,COPY_PUT);
cnt1=43;
dirlr1=0;
dirtb1=1;
}
if (cnt1==48)
{
putimage(185,325,text,COPY_PUT);
outtextxy(265,330,"!!!POLICE!!!");
delay(2000);
putimage(185,325,text,COPY_PUT);
outtextxy(225,330,"Had to take a longcut");
delay(2000);
putimage(x1,y1,o1,COPY_PUT);
x1=45;
y1=15;
getimage(45,15,55,25,o1);
putimage(45,15,obj1,COPY_PUT);
cnt1=28;
dirtb1=0;
dirlr1=1;
}
if (dice==6)
{
user=0;
}
else
{
user=1;
}
}
else
{
delay(500);
user=1;
}
invalid1: putimage(280,200,back,COPY_PUT);
}
else
{
putimage(185,325,text,COPY_PUT);
putimage(272,137,turn,COPY_PUT);
setcolor(BROWN);
outtextxy(275,145," PLAYER 2");
again1: ch=getch();
if (ch==13)
{
getdice();
}
else if (ch==27)
{
goto over;
}
else
{
goto again1;
}
if (missone2==0 && cnt2==18)
{
missone2=1;
user=0;
outtextxy(215,330," He is at petrol pump");
delay(2000);
goto invalid2;
}
if (cnt2==48 && dice>5)
{
user=0;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid2;
}
else if (cnt2==49 && dice>4)
{
user=0;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid2;
}
else if (cnt2==50 && dice>3)
{
user=0;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid2;
}
else if (cnt2==51 && dice>2)
{
user=0;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid2;
}
else if (cnt2==52 && dice>1)
{
user=0;
putimage(185,325,text,COPY_PUT);
outtextxy(260,330,"!!!TRAFFIC JAM!!!");
delay(1000);
goto invalid2;
}
if (cnt2==8)
{
mvone2=1;
outtextxy(225,330,"Wating for his friend");
delay(1000);
}
if (mvone2==0 || dice==1)
{
mvone2=0;
for (i=1;i<=dice;i++,cnt2++)
{
putimage(x2,y2,o2,COPY_PUT);
if (dirrl2==1)
{
x2-=40;
if (x2<0)
{
x2+=40;
y2-=40;
dirbt2=1;
dirrl2=0;
}
getimage(x2,y2,x2+10,y2+10,o2);
putimage(x2,y2,obj2,COPY_PUT);
delay(300);
}
else if (dirbt2==1)
{
y2-=40;
if (y2<0)
{
y2+=40;
x2+=40;
dirbt2=0;
dirlr2=1;
}
getimage(x2,y2,x2+10,y2+10,o2);
putimage(x2,y2,obj2,COPY_PUT);
delay(300);
}
else if (dirlr2==1)
{
x2+=40;
if (x2>640)
{
x2-=40;
y2+=40;
dirtb2=1;
dirlr2=0;
}
getimage(x2,y2,x2+10,y2+10,o2);
putimage(x2,y2,obj2,COPY_PUT);
delay(300);
}
else if (dirtb2==1)
{
y2+=40;
if (y2>480)
{
dirtb2=0;
putimage(625,455,obj2,COPY_PUT);
goto over;
}
getimage(x2,y2,x2+10,y2+10,o2);
putimage(x2,y2,obj2,COPY_PUT);
delay(300);
}
}
if (cnt2==53)
{
goto over;
}
if (cnt2==13)
{
putimage(185,325,text,COPY_PUT);
outtextxy(225,330,"Forgot his File at home");
delay(1000);
putimage(x2,y2,o2,COPY_PUT);
x2=625;
y2=455;
getimage(625,455,635,465,o2);
putimage(625,455,obj2,COPY_PUT);
cnt2=1;
}
if (cnt2==22)
{
putimage(185,325,text,COPY_PUT);
outtextxy(255,330,"Took a Shortcut");
delay(1000);
putimage(x2,y2,o2,COPY_PUT);
x2=145;
y2=15;
getimage(145,15,155,25,o2);
putimage(145,15,obj2,COPY_PUT);
cnt2=30;
dirbt2=0;
dirlr2=1;
}
if (cnt2==31)
{
putimage(185,325,text,COPY_PUT);
outtextxy(255,330,"Took a Shortcut");
delay(1000);
putimage(x2,y2,o2,COPY_PUT);
x2=625;
y2=55;
getimage(625,55,635,65,o2);
putimage(625,55,obj2,COPY_PUT);
cnt2=43;
dirlr2=0;
dirtb2=1;
}
if (cnt2==48)
{
putimage(185,325,text,COPY_PUT);
outtextxy(265,330,"!!!POLICE!!!");
delay(1000);
putimage(185,325,text,COPY_PUT);
outtextxy(225,330,"Had to take a longcut");
delay(1000);
putimage(x2,y2,o2,COPY_PUT);
x2=65;
y2=15;
getimage(65,15,75,25,o2);
putimage(65,15,obj2,COPY_PUT);
cnt2=28;
dirtb2=0;
dirlr2=1;
}
if (dice==6)
{
user=1;
}
else
{
user=0;
}
}
else
{
delay(500);
user=0;
}
invalid2: putimage(280,200,back,COPY_PUT);
}
}
over:
}

// Function to make the select arrow

void menuselector()
{
line(200,210,220,210);
line(220,210,220,200);
line(220,200,230,215);
line(230,215,220,230);
line(220,230,220,220);
line(220,220,200,220);
line(200,220,200,210);
}

// Function to grt the final screen

void finalscreen()
{
cleardevice();
setcolor(2);
settextstyle(10,0,4);
outtextxy(20,20,"Project in C.G");
outtextxy(20,100,"Created by : ");
outtextxy(350,200,"Nikunj Jain");
getch();
exit(0);
}

// Function to show the rules option details from menu

void rules()
{
cleardevice();
settextstyle(8,0,4);
setcolor(9);
outtextxy(250,50,"RULES");
setcolor(3);
settextstyle(3,0,1);
outtextxy(10,100,"1> Only two players can play the game.");
outtextxy(10,130,"2> When player is at 8 he should throw 1 on dice to move ahead.");
outtextxy(10,160,"3> When player is at 18 he will miss one turn.");
outtextxy(10,190,"4> When player is at 22 he will jump to 30.");
outtextxy(10,220,"5> When player is at 31 he will jump to 43.");
outtextxy(10,250,"6> When player is at 48 he will jump back to 28.");
outtextxy(10,280,"7> When player is at 13 he will jump back to Home.");
outtextxy(300,400,"Press Esc to go back to main menu");
l1: ch=getch();
if (ch!=27)
{
goto l1;
}
}


void menuselect()
{
int sx=200,sy=200,sx1=230,sy1=230;
while(1)
{
ch=getch();
if (ch==13 && sy==200)
{
return ;
}
else if (ch==13 && sy==300)
{
r=1;
return;
}
else if (ch==13 && sy==400)
{
finalscreen();
}
else if(ch==80)
{
putimage(sx,sy,cselector,COPY_PUT);
if(sy==400 && sy1==430)
{
sy=200;
sy1=230;
}
else
{
sy+=100;
sy1+=100;
}
putimage(sx,sy,selector,COPY_PUT);
ch=0;
}
}
}


/**************/
/* MAIN */
/**************/

void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
randomize();

//To get the image of Turn box

size= imagesize(272, 137, 368, 158);
turn=malloc(size);
getimage(272, 137, 368, 158,turn);

// For Player 1 object

rectangle(100, 100, 110, 110);
setfillstyle(1, 2);
floodfill(102, 102, 15);
size=imagesize(100, 100, 110, 110);
obj1=malloc(size);
getimage(100, 100, 110, 110, obj1);
cleardevice();

// For player 2 object

rectangle(100, 100, 110, 110);
setfillstyle(1, 6);
floodfill(102, 102, 15);
size=imagesize(100, 100, 110, 110);
obj2=malloc(size);
getimage(100, 100, 110, 110, obj2);
cleardevice();

o1=malloc(size); o2=malloc(size);

//For dice backround

setcolor(WHITE);
setfillstyle(SOLID_FILL, 15);
rectangle(280, 200, 360, 280);
floodfill(290, 210, 15);
size=imagesize(280, 200, 360, 280);
back=malloc(size);
getimage(280, 200, 360, 280, back);

//For dice dots

setcolor(15);
setfillstyle(1, 15);
rectangle(315, 235, 325, 245);
floodfill(320, 240, 15);
setcolor(5);
setfillstyle(1, 5);
circle(320,240,5);
floodfill(320, 240, 5);
size=imagesize(315, 235, 325, 245);
dot=malloc(size);
getimage(315, 235, 325, 245, dot);

//Get image of the text status

size= imagesize(185,325,455,345);
text= malloc(size);
getimage(185,325,455,345,text);

cleardevice();

l2: setcolor(4);
y=0;
setfillstyle(1,1);
fillellipse(320,75,0,0);
delay(1500);
for(x=0;x<=320;x+=40,y+=(60/8))
{
fillellipse(320,75,x,y);
delay(500);
}
setcolor(4);
settextstyle(4,0,5);
outtextxy(50,50,"Journey To Pithawalla College");
setcolor(BLUE+LIGHTGREEN);
settextstyle(1,0,2);
outtextxy(250,200,"PLAY GAME");
outtextxy(250,300,"RULES");
outtextxy(250,400,"EXIT");
menuselector();

//For the image of selector

size=imagesize(200,200,230,230);
selector=malloc(size);
getimage(200,200,230,230,selector);

//to clear the image of selector

size=imagesize(0,0,30,30);
cselector=malloc(size);
getimage(0,0,30,30,cselector);
menuselect();
if (r==1)
{
rules();
cleardevice();
r=0;
goto l2;
}
cleardevice();
settextstyle(0,0,0);
setcolor(WHITE);
setfillstyle(SOLID_FILL, 15);
rectangle(280, 200, 360, 280);
floodfill(290, 210, 15);
setcolor(YELLOW);
outtextxy(275,305,"TEXT MESSAGE");
setcolor(RED);
setlinestyle(SOLID_LINE, 1, 3);
rectangle(180,320,460,350);
board();
numbering();
status();
play();
settextstyle(7,0,3);
if (user==0 && cnt1==53)
{
outtextxy(180,320," Player 1 wins");
}
else if (user==1 && cnt2==53)
{
outtextxy(180,320," Player 2 wins");
}
else if (ch==27)
{
finalscreen();
goto end;
}
while(1)
{
ch=getch();
if (ch==27)
{
finalscreen();
}
}
end:
}
/**************************************************************************/

No comments: