main() { int mode=VGAHI,driver=VGA; char ch; unsigned int l; int i,gi,gj,j,flag=1;/*i,j是循环变量,flag是标记变量,-1:向x负半轴移动,+1:向x正半轴移动*/ double qx,qy,k,b=0.0,speech=0.4,x,y; double r=2.0,bx=60.0,byy=270.0; double pianx=100.0,piany=100.0,tx=20.0,ty=10.0,jx=2.0,jy=2.0; int mx=0,my=0,mb,sum;/*sum纪录砖块的数目*/ FILE * p; if((p = fopen("record.dat", "r")) == NULL) { p=fopen("record.dat","w"); fprintf(p,"0 0 0 0 0\n"); rewind(p); } fclose(p); initgraph(&driver,&mode,"C:\\tc"); setbkcolor(BLUE); Msinit(); Setmouse((int)(pianx+1+bx/2),(int)((tx+jx)*8+pianx-1-bx/2),(int)byy+piany,(int)byy+piany); star: cleardevice();/*程序重载的介入点*/ setcolor(RED); outtextxy(30,20,"^_^ Welcome to Play Hitting Brick Game! ^_^"); sum=0; qx=100.0+pianx-10;qy=180.0+pianx-10;k=0.33; setcolor(7); rectangle((int)(pianx-2),(int)(piany-2),(int)((tx+jx)*8+2+pianx),302+piany); setcolor(1); rectangle((int)(pianx-1),(int)(piany-1),(int)((tx+jx)*8+1+pianx),301+piany); /*读取盘面情况*/ p=fopen("record.dat", "r"); for(i=0;i<5;i++) fscanf(p,"%x ",&zhuan[i]); fclose(p); /*画砖块*/ for(i=0;i<5;i++) { l=1; for(j=0;j<16;j++) { if((zhuan[i]&l)==0) { Draw((int)((jx+tx)*((16*i+j)%8)+pianx+jx),(int)((jy+ty)*((int)((16*i+j)/8))+piany+jy),(int)tx,(int)ty); sum+=1; } l=l*2; } } gotoxy(5,4); printf("Press any key to start game...Q key to quit..."); ch=getch(); if(ch=='q'||ch=='Q') quitgame(); else { gotoxy(5,4); printf(" "); } for(;;) { setfillstyle(1, 0); bar(mx-bx/2,my,mx+bx/2,my+5); Msread(&mx, &my, &mb); Draw(mx-bx/2,my,bx,5); setcolor(0); mycircle(qx,qy,r,0); /*判断求是否反弹*/ if(qx-r<=pianx+1 || qx+r>=(tx+jx)*8+pianx-1) { flag=-flag; k=-k; } if(qy-r<=piany+1) k=-k; for(gi=0;gi<5;gi++) { l=1; for(gj=0;gj<16;gj++) { if((zhuan[gi]&l)==0) { j=(16*gi+gj)/8; i=(16*gi+gj)%8; x=(jx+tx)*i+jx+tx/2+pianx; y=(jy+ty)*j+jy+ty/2+piany; /*边判断1*/ if(qy>=y-ty/2 && qy<=y+ty/2 &&(pow(qx+r-x+tx/2,2)<1 || pow(qx-r-x-tx/2,2)<1)) { flag=-flag; k=-k; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) wingame(); setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)*j+piany+jy+ty); } else /*边判断2*/ if(qx>=x-tx/2 && qx<=x+tx/2 &&(pow(qy+r-y+ty/2,2)<1 || pow(qy-r-y-ty/2,2)<1)) { k=-k; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) wingame(); setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)*j+piany+jy+ty); } else /*角判断*/ if(pow(qx-x+tx/2,2)+pow(qy-y+ty/2,2)<=r*r || pow(qx-x-tx/2,2)+pow(qy-y+ty/2,2)<=r*r || pow(qx-x+tx/2,2)+pow(qy-y-ty/2,2)<=r*r || pow(qx-x-tx/2,2)+pow(qy-y-ty/2,2)<=r*r) { flag=-flag; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) wingame(); setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)*j+piany+jy+ty); } } l=l*2; } } /*棍棒的反弹*/ if(qx<=mx+bx/2 && qx>=mx-bx/2 && pow(qy+r-my,2)<1) { k=-(k/pow(k*k,0.5))*(0.3*bx/(pow(pow(qx-mx,2),0.5)+0.000001)); } if((int)(qy+r)>my+0.5) { gotoxy(5,5); printf("You have lost the game!Press any key to restart..."); getch(); goto star; } b=qy-qx*k; if(flag==1) qx=qx+speech/pow(1.0+k*k,0.5); if(flag==-1) qx=qx-speech/pow(1.0+k*k,0.5); qy=qx*k+b;/*计算球心坐标*/ setcolor(14); mycircle((int)qx,(int)qy,r,14); delay(1); if(mb==1) { gotoxy(5,5); printf("You have lost the game!Press any key to restart..."); getch(); goto star; } } }
int main() { int tmp_lives =0 ; int lives = 3; std::stack<Level> lvlstack; int menu_pointer = 0; sf::Clock beat_time; int sukowa; sf::RenderWindow window(sf::VideoMode(800, 400), "Sleepwalker"); window.setFramerateLimit(60); Highscoretable highscoretable(&window); Highscorein highscorein(1233,&window); Livesleft livesleft(&lives,&window); Gameover gameover(&window); Logo logo(&window); Jabs jabs(&window); Infopage infopage(&window); Menu menu(&menu_pointer,&window); Interlude intone("Level 1","Sometimes life is just a straight walk ahead.",&window); Interlude inttwo("Level 2","Sometimes it is like a zig-zag.",&window); Interlude intthree("Level 3","Sometimes in life you have to take two steps forward and then one back.",&window); Interlude intfour("Level 4","Don't panic.",&window); Interlude intfive("Level 5","Follow the arrows.",&window); Interlude intsix("Level 6","Colors matter.",&window); Interlude intseven("Level 7","Some arrows are traitors.",&window); Interlude inteight("Level 8","No traitors this time just run. Just run!",&window); Interlude intnine("Level 9","You little brat. You made it.",&window); Interlude intten("Level 10","The writing on the wall.",&window); Ingame lvlone(1,&lives,&window); Ingame lvltwo(2,&lives,&window); Ingame lvlthree(3,&lives,&window); Ingame lvlfour(4,&lives,&window); Ingame lvlfive(5,&lives,&window); Ingame lvlsix(6,&lives,&window); Ingame lvlseven(7,&lives,&window); Ingame lvleight(8,&lives,&window); Ingame lvlnine(9,&lives,&window); Ingame lvlten(10,&lives,&window); Level levels[10]; levels[0] = Level(1,intone,lvlone); levels[1] = Level(2,inttwo,lvltwo); levels[2] = Level(3,intthree,lvlthree); levels[3] = Level(4,intfour,lvlfour); levels[4] = Level(5,intfive,lvlfive); levels[5] = Level(6,intsix,lvlsix); levels[6] = Level(7,intseven,lvlseven); levels[7] = Level(8,inteight,lvleight); levels[8] = Level(9,intnine,lvlnine); levels[9] = Level(10,intten,lvlten); for (int i = 9 ; i>=0;i--) { lvlstack.push(levels[i]); } logo.run(); jabs.run(); //highscoretable.run(); //highscorein.run(); do { menu.run(); if(menu_pointer == 1) { infopage.run(); menu = Menu(&menu_pointer,&window); infopage.reset(); } if(menu_pointer == 2) { highscoretable.run(); menu = Menu(&menu_pointer,&window); highscoretable.reset(); } if(menu_pointer == 12) { beat_time.restart(); while (!lvlstack.empty() && window.isOpen()&&lives>0) { tmp_lives = lives; lvlstack.top().run(); lvlstack.pop(); if(lives != tmp_lives) { lvlstack.push(levels[9-lvlstack.size()]); // livesleft.run(); } } if(window.isOpen()) { if (lives>0) { sukowa = beat_time.getElapsedTime().asSeconds(); Wingame wingame(sukowa,&window); wingame.run(); menu = Menu(&menu_pointer,&window); wingame.reset(); while(!lvlstack.empty())lvlstack.pop(); for (int i = 9 ; i>=0;i--) { lvlstack.push(levels[i]); } lives = 3; } else { gameover.run(); menu = Menu(&menu_pointer,&window); gameover = Gameover(&window); while(!lvlstack.empty())lvlstack.pop(); for (int i = 9 ; i>=0;i--) { lvlstack.push(levels[i]); } lives = 3; } } } if(!window.isOpen()||menu_pointer == 15)menu_pointer = 0; }while(menu_pointer != 0 ); return 0; }
int main(int argc, char **argv) #endif { char fname[256]; char defname[] = "game.dat"; Boolean b_play; int dir; int inch; int num_step; int num; unsigned char steplog[MaxSteps]; #ifdef ENABLE_DL char buf[10]; struct high_record high; while (1) { num = 0; clear(); ansimore2("game/worker/welcome", false, 0, 0); while (num <= 0 || num > MAXDATA) { buf[0]=0; getdata(5, 61, "", buf, 5, 1, NULL, true); if (buf[0] == 0) return 0; num = atoi(buf); } sprintf(fname, "game/worker/%s.%d", defname, num); clear(); #else { if (argc > 2) { sprintf(fname, "%s/%s.%s", argv[1], defname, argv[2]); num=atoi(argv[2]); } else if (2 == argc) { if (strlen(argv[1]) > 255) exit(1); sprintf(fname, "%s.%s", defname, argv[1]); num=atoi(argv[1]); } else { strcpy(fname, defname); num==-1; } #endif num_step=0; load_highrecord(num, &high, -1); if (TRUE == InitData(fname)) { if (TRUE == InitPad()) { b_play = TRUE; DrawPad(); update_endline1(&high,num_step); inch = 0; while (b_play) { if (inch) { showdiff(); cleardiff(); move(scr_lns-1, scr_cols - 1); refresh(); } if (wingame()) { int newrecord; char buf[100]; newrecord=0; if (num_step<high.shortest||high.shortest==0) newrecord=load_highrecord(num, &high, num_step); clear(); move(12,15); prints("祝贺你,你成功的完成了这一关"); move(13,15); if (newrecord==1) { sprintf(buf,"你也创造了本关使用步数的纪录(%d步)!好厉害~",num_step); } else if (newrecord!=0) { sprintf(buf,"你也创造了本关使用步数的纪录(%d步)!",num_step); prints(buf); move(14,15); sprintf(buf,"不过,让点创纪录机会给别人吧~你都有%d个记录了:P\n",newrecord); } else { sprintf(buf,"你用了%d步,纪录是%d步。",num_step,high.shortest); } prints(buf); move(23, 0); clrtoeol(); prints("\x1b[m \x1b[5;1;33m按任何键继续 ..\x1b[m"); igetkey(); break; } if (num_step>MaxSteps) { char askbuf[100]; clear(); sprintf(askbuf,"你已经用了%d步还没有成功,重来么?(Y/N)",num_step); getdata(12,0,askbuf,buf,2,1,NULL,true); if (toupper(buf[0])=='N') break; b_play = InitPad(); DrawPad(); num_step=0; } inch = igetkey(); if ((' ' == inch)||(inch == '\n')||(inch=='\r')) break; dir = NullDir; switch (inch) { case 'i': case 'I': case KEY_UP: dir = North; break; case 'j': case 'J': case KEY_LEFT: dir = West; break; case 'l': case 'L': case KEY_RIGHT: dir = East; break; case 'k': case 'K': case KEY_DOWN: dir = South; break; case 12: // Ctrl-L case 'R': // Ctrl-L clear(); DrawPad(); break; case '\t': b_play = InitPad(); DrawPad(); num_step=0; update_endline1(&high,num_step); break; case Ctrl('H'): case '\177': case KEY_DEL: if (num_step!=0) { num_step--; regretmove(steplog[num_step]); update_endline1(&high,num_step); } break; default: break; } if (NullDir != dir) { int ret; if ((ret=workermove(dir))!=0) { if (ret==2) steplog[num_step]=dir+8; else steplog[num_step]=dir; num_step++; update_endline1(&high,num_step); } } } } DestroyPad(); } DestroyData(); } return 0; }
main() { int i,j,key,num,b[20],p; char ch; aa: window(1,1,25,80); textbackground(LIGHTGREEN); textcolor(YELLOW); clrscr(); fu(b); num=0; p=0; textcolor(LIGHTRED); gotoxy(18,1); cprintf("%c(UP) %c(DOWN) %c(LEFT) %c(RIGHT)",24,25,27,26); gotoxy(16,2); cprintf("Eat the numbers in your road whose sum is 7,"); gotoxy(14,3); cprintf("and eat 7 in the end, then you will win the game!"); textcolor(MAGENTA); for(i=4;i<21;i++) for(j=20;j<44;j++) if(k[i-4][j-20]==0) { gotoxy(j,i); cprintf("%c",219); } else if(k[i-4][j-20]!=1) { gotoxy(j,i); cprintf("%d",k[i-4][j-20]); } textcolor(YELLOW); i=5; j=21; gotoxy(j,i); cprintf("\1"); gotoxy(33,5); cprintf("7"); gotoxy(7,7); cprintf("num:%d",num); textcolor(WHITE); gotoxy(11,22); cprintf("Press any key to start game, Q key to quit..."); ch=getch(); if(ch=='Q'||ch=='q') { window(1,1,25,80); textbackground(BLACK); textcolor(LIGHTGRAY); clrscr(); exit(0); } else { textcolor(YELLOW); gotoxy(11,22); cprintf(" "); } do { key=bioskey(0); sound(200); delay(1000); nosound(); switch(key) { case DOWN: { if(k[i-4+1][j-20]==0) continue; if(k[i-4+1][j-20]!=1&&k[i-4+1][j-20]!=7&&en(b,i+j+1)) { num+=k[i-4+1][j-20]; b[p++]=i+j+1; gotoxy(7,7); cprintf("num:%d",num); } textcolor(YELLOW); gotoxy(j,i++); printf(" "); gotoxy(j,i); cprintf("\1"); gotoxy(33,5); if(k[i-4][j-20]==7&&num==7) wingame(); else if(num!=7&&k[i-4][j-20]==7) { lostgame(num); goto aa; } break; } case UP: { if(k[i-4-1][j-20]==0) continue; if(k[i-4-1][j-20]!=1&&k[i-4-1][j-20]!=7&&en(b,i+j-1)) { num+=k[i-4-1][j-20]; b[p++]=i+j-1; gotoxy(7,7); cprintf("num:%d",num); } textcolor(YELLOW); gotoxy(j,i--); printf(" "); gotoxy(j,i); cprintf("\1"); gotoxy(33,5); if(k[i-4][j-20]==7&&num==7) wingame(); else if(num!=7&&k[i-4][j-20]==7) { lostgame(num); goto aa; } break; } case LEFT: { if(k[i-4][j-20-1]==0) continue; if(k[i-4][j-20-1]!=1&&k[i-4][j-20-1]!=7&&en(b,i+j-1)) { num+=k[i-4][j-20-1]; b[p++]=i+j-1; gotoxy(7,7); cprintf("num:%d",num); } textcolor(YELLOW); gotoxy(j--,i); printf(" "); gotoxy(j,i); cprintf("\1"); gotoxy(33,5); if(k[i-4][j-20]==7&&num==7) wingame(); else if(num!=7&&k[i-4][j-20]==7) { lostgame(num); goto aa; } break; } case RIGHT: { if(k[i-4][j-20+1]==0) continue; if(k[i-4][j-20+1]!=1&&k[i-4][j-20+1]!=7&&en(b,i+j+1)) { num+=k[i-4][j-20+1]; b[p++]=i+j+1; gotoxy(7,7); cprintf("num:%d",num); } textcolor(YELLOW); gotoxy(j++,i); printf(" "); gotoxy(j,i); cprintf("\1");gotoxy(33,5); if(k[i-4][j-20]==7&&num==7) wingame(); else if(num!=7&&k[i-4][j-20]==7) { lostgame(num); goto aa; } break; } default: continue; } }while(1); }