MENU.CPP
资源名称:泡泡龙源代码.zip [点击查看]
上传用户:junwei_58
上传日期:2007-05-15
资源大小:79k
文件大小:4k
源码类别:
其他智力游戏
开发平台:
Visual C++
- #define MENU_CPP
- #include <stdlib.h>
- #include "game.h"
- #include "keyintr.h"
- #include "menu.h"
- #include "speceffe.h"
- #include "top10.h"
- char *menuitem[13]={
- " continue game " ,
- " restart level " ,
- " leave level " ,
- " game speed 10 " ,
- " music on " ,
- " exit game " ,
- " Start " ,
- " main menu " ,
- " High Scores " ,
- " 1 player " ,
- " Sound on " ,
- " edit mode " ,
- " vs cpu " ,
- };
- /////////////////////////////////////
- // class menu member functions
- /////////////////////////////////////
- menu::menu(int X,int Y,menumode M):
- x(X),y(Y),width(150){
- switch(M){
- case MAIN:
- itemlist[0]=START; //itemlist[1]=PLAYER;
- itemlist[1]=TOP10; //itemlist[3]=SPEED;
- itemlist[2]=SOUND; itemlist[3]=EXIT;
- itemNum=4;select=0;
- break;
- default:menu::~menu();break;
- }
- }
- menu::~menu(){}
- void menu::show()const{
- int i;
- for(i=0;i<itemNum;i++)redrawtext(i);
- }
- void menu::redrawtext(int i)const{
- setbkcolor(BKGROUNDCOLOR);
- if(i==select){
- setcolor(TEXTCOLOR2);
- textxy(x+10,y+i*17+10,menuitem[itemlist[i]]);
- setcolor(TEXTCOLOR);
- textxy(x+9,y+i*17+9,menuitem[itemlist[i]],0);
- }else{
- setcolor(TEXTCOLOR2);
- textxy(x+10,y+i*17+10,menuitem[itemlist[i]]);
- }
- }
- void menu::hide(){rectantB(x,y,width,itemNum*21,0);}//putimage(x,y,img_b,COPY_PUT);}
- void menu::key(){
- int loop=1;
- show();
- while(loop){
- while(keyboard.status==READY);
- if(keyboard.status==PRESS){
- keyboard.status=READY;
- switch(keyboard.recentPressKey){
- case KEY_enter:case KEY_space:
- switch(itemlist[select]){//KEY_enter:
- case EXIT: return;// case LEAVE_LEVEL: gameover=1;levelid=0;loop=0;break;//levelid = last main level
- case TOMAIN: gameover=1;loop=0;break;//should start the menu// case RESTART_LEVEL:gameover=1;loop=0;break;// case CONTINUE: loop=0;gameover=0;break;
- case TOP10:
- smoothout();
- top10();
- getch_Key();
- smoothout();
- show();
- break;// case EDIT: editmode();break;
- case START:
- // int i,j;
- hide();
- thegameloop();
- show();
- break;
- }break;
- case KEY_up:
- if(select>0){
- beep();
- //if(problem)message(problemStr[problem],1);
- //problem=0;
- select--;
- redrawtext(select+1);
- redrawtext(select);
- }break;
- case KEY_down:
- if(select<itemNum-1){
- beep();
- //if(problem)message(problemStr[problem],1);
- //problem=0;
- select++;
- redrawtext(select-1);
- redrawtext(select);
- }break;
- case KEY_left:
- switch(itemlist[select]){
- case MUSIC:beep();switchMusic();redrawtext(select);break;
- case SOUND:beep();switchSound();redrawtext(select);break;
- case PLAYER:beep();turnPlayer(UP);redrawtext(select);break;
- default:break;
- }break;
- case KEY_right:
- switch(itemlist[select]){
- case MUSIC:beep();switchMusic();redrawtext(select);break;
- case SOUND:beep();switchSound();redrawtext(select);break;
- case PLAYER:beep();turnPlayer(DOWN);redrawtext(select);break;
- default:break;
- }break;
- default:break;
- }
- }else keyboard.status=READY;
- }
- hide();
- }
- void switchMusic(){
- if(!musicON){
- musicON=1;
- menuitem[MUSIC][10]='n';
- menuitem[MUSIC][11]=' ';
- }else{
- musicON=0;
- menuitem[MUSIC][10]='f';
- menuitem[MUSIC][11]='f';
- }
- //message(problemStr[1]);problem=1;
- }
- void switchSound(){
- if(!soundON){
- soundON=1;
- menuitem[SOUND][10]='n';
- menuitem[SOUND][11]=' ';
- }else{
- soundON=0;
- menuitem[SOUND][10]='f';
- menuitem[SOUND][11]='f';
- }
- }
- void turnPlayer(int d){
- switch(d){
- case UP:
- switch(players){
- case 2:
- char *a=menuitem[PLAYER];
- menuitem[PLAYER]=menuitem[AI];
- menuitem[AI]=a;
- players=1;
- menuitem[PLAYER][3]='2';
- menuitem[PLAYER][11]='s';
- break;
- case 1:
- players=0;
- menuitem[PLAYER][3]='1';
- menuitem[PLAYER][11]=' ';
- break;
- case 0:
- players=2;
- a=menuitem[PLAYER];
- menuitem[PLAYER]=menuitem[AI];
- menuitem[AI]=a;
- }break;
- case DOWN:
- switch(players){
- case 0:
- players=1;
- menuitem[PLAYER][3]='2';
- menuitem[PLAYER][11]='s';
- break;
- case 2:
- char *a=menuitem[PLAYER];
- menuitem[PLAYER]=menuitem[AI];
- menuitem[AI]=a;
- players=0;
- menuitem[PLAYER][3]='1';
- menuitem[PLAYER][11]=' ';
- break;
- case 1:
- players=2;
- a=menuitem[PLAYER];
- menuitem[PLAYER]=menuitem[AI];
- menuitem[AI]=a;
- }break;
- }
- }