📄 goldenbugs.c
字号:
bkground=malloc(imagesize(287,196,351,204));
/*init the score screen*/
Score=0;
setfillstyle(1,LIGHTBLUE);
bar(233,435,403,455);
setcolor(YELLOW);
settextstyle(0,HORIZ_DIR,1);
settextjustify(0,2);
outtextxy(263,442,"SCORE:");
showscore(311,442,Score,8,1,YELLOW);
Life=2;
/*the 'rolling' of the stages*/
for(stage=1;stage<=15;stage++)
{
/*load and run the game*/
sprintf(filename,"map\\map%d.map",stage);
initgame(filename);
/*init the stage screen*/
clrgreenscr(0);
setcolor(DARKGRAY);
settextstyle(0,HORIZ_DIR,1);
settextjustify(0,2);
outtextxy(60,442,"STAGE:");
showscore(108,442,stage,2,1,DARKGRAY);
outtextxy(132,442,"LIFE:");
showscore(172,442,Life,2,1,DARKGRAY);
/*init the speed screen*/
clrgreenscr(2);
setcolor(DARKGRAY);
settextstyle(0,HORIZ_DIR,1);
settextjustify(0,2);
outtextxy(420,442,"SPEED:");
showscore(468,442,Speed,2,1,DARKGRAY);
outtextxy(492,442,"BEANS:");
showscore(540,442,Max_body_len-Now_body_len-1,4,1,DARKGRAY);
/*pause when start*/
settextstyle(0,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(YELLOW);
getimage(287,196,351,204,bkground);
sprintf(filename,"STAGE %d",stage);
outtextxy(319,200,filename);
mydelay1(20);
putimage(287,196,bkground,0);
/*play game*/
gamestage();
if(Run==GAMEQUIT)break;
/*judge if you are dead*/
if(Run==GAMELOSE)
{
Life--;
stage--;
if(Life<0)break;
}
}
if(Run==GAMEWIN||Run==GAMELOSE)showresult();
/*free the picture pointers*/
for(i=0;i<10;i++)
free(Beans[i].beanpic);
for(i=0;i<8;i++)
free(Snakebody[i]);
free(bkground);
}
/*change the mainmenu when key pressed*/
void menuchange(int choice,char *p[5],int mode,char *bugpic)
{
int len;
char *instruct[5]={"START A NEW GAME.","OPTIONS OF THE GAME.","VIEW THE CREDITS.","TOP PLAYERS.","QUIT TO WINDOWS."};
len=strlen(p[choice])*8;
/*init of the color and text*/
setfillstyle(1,BLACK);
settextjustify(1,2);
settextstyle(0,HORIZ_DIR,2);
/*change the manu according to mode*/
switch(mode)
{
/*pass this part*/
case 0:setcolor(LIGHTCYAN);
outtextxy(319,175+35*choice,p[choice]);
bar(302-len,175+35*choice,316-len,189+35*choice);
bar(321+len,175+35*choice,335+len,189+35*choice);
break;
/*choose this part*/
case 1:setcolor(WHITE);
outtextxy(319,175+35*choice,p[choice]);
putimage(302-len,175+35*choice,bugpic,0);
putimage(321+len,175+35*choice,bugpic,0);
clrgreenscr(0);
setcolor(DARKGRAY);
settextstyle(0,0,1);
settextjustify(0,2);
outtextxy(60,442,instruct[choice]);
break;
/*bugs dancing*/
case 2:putimage(302-len,175+35*choice,bugpic,0);
putimage(321+len,175+35*choice,bugpic,0);
default:;
}
}
/*the main menu*/
int menu()
{
int i;
int inkey,bugkind=0,finalchoice=10;
char *p[5]={"NEW GAME","OPTIONS","CREDITS","HIGH SCORE","EXIT"};
char *bugpic[2],filename[10];
static int choice=0,temp=0;
/*show the bkground in '*.gbp'*/
sprintf(filename,"pic\\face%d.gbp",Facenum);
showgbp(43,40,filename);
/*reset the r,g,b reg*/
for(i=0;i<16;i++)
SetPaletteRegister(Index[i],&RGB_reg[i]);
/*write the menu*/
setcolor(LIGHTCYAN);
settextjustify(1,2);
settextstyle(0,HORIZ_DIR,3);
outtextxy(319,125,"GBUGS SNAKE");
settextstyle(0,HORIZ_DIR,2);
for(i=0;i<=4;i++)
outtextxy(319,175+35*i,p[i]);
/*load the 'dancing bugs'*/
bugpic[0]=loadgbp("pic\\bug1.gbp");
bugpic[1]=loadgbp("pic\\bug2.gbp");
/*write the simble of GBS*/
setfillstyle(1,LIGHTBLUE);
bar(233,435,403,455);
setcolor(YELLOW);
settextstyle(0,0,1);
settextjustify(1,2);
outtextxy(319,442,"GOLDEN BUGS STUDIO");
/*write the date*/
showdate();
Timercounter=0;
settimer(newhandler);
/*the 'rolling' of the menu*/
menuchange(choice,p,1,bugpic[bugkind]);
while(finalchoice==10)
{
/*dance the bugs when no key pressed*/
while(!kbhit())
{
if(Timercounter>6)
{
if(bugkind==0)bugkind=1;
else bugkind=0;
menuchange(choice,p,2,bugpic[bugkind]);
Timercounter=0;
}
showtime();
}
/*change 'choice' when key pressed*/
inkey=bioskey(0);
switch(inkey)
{
case UP:choice--;
if(choice<0)choice=0;
break;
case DOWN:choice++;
if(choice>4)choice=4;
break;
case ENTER:finalchoice=choice;break;
default:;
}
/*change the menu when choice changed*/
if(choice!=temp)
{
menuchange(temp,p,0,bugpic[bugkind]);
menuchange(choice,p,1,bugpic[bugkind]);
temp=choice;
}
}
/*free the pointer and others*/
free(bugpic[0]);
free(bugpic[1]);
killtimer();
Timercounter=0;
return finalchoice;
}
/*setup the 'sets',+ when add>0,- when add<0*/
void optionsets(int choice,int add)
{
char *dif[3]={"EASY","MEDIUN","HARD"};
char *snkstyl[2]={"CLASSICAL","USER DEFINED"};
char string[6];
settextstyle(0,HORIZ_DIR,2);
settextjustify(0,1);
setcolor(YELLOW);
switch(choice)
{
case 0:Difficulty+=add;
if(Difficulty<0)Difficulty=2;
else if(Difficulty>2)Difficulty=0;
setfillstyle(1,BLACK);
bar(319,152+36*choice,500,168+36*choice);
outtextxy(319,160+36*choice,dif[Difficulty]);
break;
case 1:Snakestyle+=add;
if(Snakestyle<0)Snakestyle=1;
else if(Snakestyle>1)Snakestyle=0;
setfillstyle(1,BLACK);
bar(319,152+36*choice,510,168+36*choice);
outtextxy(319,160+36*choice,snkstyl[Snakestyle]);
break;
case 2:Gamecol+=add;
if(Gamecol<0)Gamecol=15;
else if(Gamecol>15)Gamecol=0;
setfillstyle(Gamefil,Gamecol);
bar(319,224,400,276);
setcolor(LIGHTGREEN);
rectangle(319,224,400,276);
break;
case 3:Gamefil+=add;
if(Gamefil<1)Gamefil=11;
else if(Gamefil>11)Gamefil=1;
setfillstyle(Gamefil,Gamecol);
bar(319,224,400,276);
setcolor(LIGHTGREEN);
rectangle(319,224,400,276);
break;
case 4:Facenum+=add;
if(Facenum<1)Facenum=4;
else if(Facenum>4)Facenum=1;
setfillstyle(1,BLACK);
sprintf(string,"FACE%d",Facenum);
bar(319,152+36*choice,500,168+36*choice);
outtextxy(319,160+36*choice,string);
default:;
}
}
/*change the options when key pressed*/
void changeoption(int choice,char mode,char *str[6])
{
settextstyle(0,HORIZ_DIR,2);
settextjustify(2,1);
switch(mode)
{
case 0:setcolor(LIGHTBLUE);
if(choice!=5)outtextxy(310,160+36*choice,str[choice]);
else {settextjustify(1,1);outtextxy(319,170+36*choice,str[choice]);}
break;
case 1:setcolor(WHITE);
if(choice!=5)outtextxy(310,160+36*choice,str[choice]);
else {settextjustify(1,1);outtextxy(319,170+36*choice,str[choice]);}
default:;
}
}
/*the options*/
/*sets: snakestyle,gamecol,gamefil,difficulty*/
void options()
{
int i,done=FALSE,inkey,newchoice=0,oldchoice=0;
char *str[6]={"DIFFICULTY:","SNAKESTYLE:","GROUNDCOLOR:","GROUNDFILL:","MENUFACE:","MAIN MENU"};
/*init the options*/
setfillstyle(1,BLACK);
bar(43,40,597,414);
setcolor(LIGHTBLUE);
settextstyle(0,HORIZ_DIR,2);
settextjustify(1,1);
outtextxy(319,110,"!OPTIONS!");
settextjustify(2,1);
for(i=0;i<5;i++)
outtextxy(310,160+36*i,str[i]);
settextjustify(1,1);
outtextxy(319,170+36*i,str[i]);
changeoption(newchoice,1,str);
for(i=0;i<5;i++)
optionsets(i,0);
while(done!=TRUE)
{
if(kbhit())
{
inkey=bioskey(0);
switch(inkey)
{
case UP:newchoice--;
if(newchoice<0)newchoice=5;
changeoption(oldchoice,0,str);
changeoption(newchoice,1,str);
break;
case DOWN:newchoice++;
if(newchoice>5)newchoice=0;
changeoption(oldchoice,0,str);
changeoption(newchoice,1,str);
break;
case LEFT:optionsets(newchoice,-1);break;
case RIGHT:optionsets(newchoice,1);break;
case ENTER:if(newchoice==5)done=TRUE;break;
case ESC:done=TRUE;
default:;
}
oldchoice=newchoice;
}
showtime();
}
}
/*credits picture1*/
void credits1()
{
int i;
char *string[10]={"TC Programming :","Cat Tom","VB Programming :","Little Tiger","Artists :","Cat Tom","Debugging :","Cat Tom","JV29","Little Tiger"};
setfillstyle(1,BLACK);
bar(43,40,597,414);
settextstyle(1,HORIZ_DIR,2);
settextjustify(1,1);
for(i=0;i<4;i++)
{
setcolor(CYAN);
outtextxy(319,70+60*i,string[2*i]);
setcolor(LIGHTCYAN);
outtextxy(319,100+60*i,string[2*i+1]);
}
outtextxy(319,70+60*i,string[8]);
outtextxy(319,100+60*i,string[9]);
setcolor(LIGHTMAGENTA);
settextstyle(2,HORIZ_DIR,6);
outtextxy(319,390,"Thank you for choosing GBS softs ! ! !");
}
/*credits picture2*/
void credits2()
{
setfillstyle(1,WHITE);
bar(43,40,597,414);
showgbp(93,195,"pic\\gbs.gbp");
showgbp(53,395,"pic\\contact.gbp");
}
/*show credits*/
void showcredits()
{
int inkey=UP;
char pic=1;
Timercounter=0;
settimer(newhandler);
credits1();
while(inkey!=ENTER&&inkey!=ESC)
{
if(Timercounter>195)
{
pic++;
if(pic>2)pic=1;
switch(pic)
{
case 1:credits1();break;
case 2:credits2();break;
default:;
}
Timercounter=0;
}
showtime();
if(kbhit())inkey=bioskey(0);
}
killtimer();
}
/*save options*/
void saveoptions()
{
FILE *fp;
if((fp=fopen("user\\user.set","wb"))==NULL)
{
printf("set file open error!!!");
exit(0);
}
fputc(Difficulty,fp);
fputc(Snakestyle,fp);
fputc(Gamecol,fp);
fputc(Gamefil,fp);
fputc(Facenum,fp);
fclose(fp);
}
/*read options*/
void readoptions()
{
FILE *fp;
if((fp=fopen("user\\user.set","rb"))==NULL)
{
printf("set file open error!!!");
exit(0);
}
Difficulty=fgetc(fp);
Snakestyle=fgetc(fp);
Gamecol=fgetc(fp);
Gamefil=fgetc(fp);
Facenum=fgetc(fp);
fclose(fp);
}
/*exit when key pressed in highscore*/
void mydelay2()
{
int inkey=LEFT,k=0;
Timercounter=0;
settimer(newhandler);
while(inkey!=ENTER&&inkey!=ESC)
{
if(Timercounter>15)
{
k++;
if(k>2)k=0;
switch(k)
{
case 0:setcolor(LIGHTRED);break;
case 1:setcolor(LIGHTGREEN);break;
case 2:setcolor(LIGHTBLUE);break;
default:;
}
settextstyle(0,HORIZ_DIR,2);
settextjustify(1,0);
outtextxy(319,70,"!TOP PLAYERS!");
Timercounter=0;
}
showtime();
if(kbhit())inkey=bioskey(0);
}
killtimer();
}
/*everyone knows what it is*/
main()
{
int gd=VGA,gm=VGAHI,choice,game=TRUE;
initgraph(&gd,&gm,"sys");
showlogo();
init();
readoptions();
/*goto different functions when choice made*/
while(game)
{
choice=menu();
switch(choice)
{
case 0:newgame();break;
case 1:instruction(1);options();break;
case 2:instruction(2);showcredits();break;
case 3:instruction(3);highscore(0);mydelay2();break;
case 4:game=FALSE;
default:;
}
}
saveoptions();
closegraph();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -