重返黑白时代:abc game for dos

这是本人的第一个游戏,原因是因为七夕将至,作为送GF的礼物,可是由于缺乏面向对象程序设计相关的知识,所以,只能凭借纯代码,在Visual C++2008环境下 ,编译生成在DOS下运行的.exe文件。

 

游戏很简单:开始后,屏幕上方会掉下各种随机的字母(A-Z),而每一个大的字母都是由其他随机的小的字母组成,这样做是纯粹为了搞混你眼睛,嘿嘿。你只要根据掉下来的大字母,在键盘上输入同样的键,则会消除该字母,同时得一分。掉落的速度会越来越快,反正我也没能够打到最快那档的,如果有一个字母没在落地前消除,则GAME OVER.

 

话说有点像金山打字游戏农民版,好吧,没学会MFC,咱就这么玩吧。

 

菜单:

重返黑白时代:abc game for dos_第1张图片

 

1.开始游戏

2.分数记录

3.帮助

4.关于

5.退出

 

游戏开始:

重返黑白时代:abc game for dos_第2张图片

 

全身都是Q的K,看仔细喽

 

得分了:

重返黑白时代:abc game for dos_第3张图片

 

+1...

 

游戏结束:

重返黑白时代:abc game for dos_第4张图片

 

级别:1级  分数:6分  输入你的名字。

 

seeyou:

重返黑白时代:abc game for dos_第5张图片

see you  by sky.

 

给GF的彩蛋,嘿嘿:

重返黑白时代:abc game for dos_第6张图片

i love u

 

about me:

重返黑白时代:abc game for dos_第7张图片

 

 

 

接下来,分享一下源代码,电脑上有Visual C++环境(最好是Microsoft Visual C++ 2008 :Express Edition 免费版本下载页 )的可以运行一下玩玩哈

 

c++代码实现如下:

#include<iostream> #include<windows.h> #include <conio.h> #include <ctime> #include <cstdlib> #include<cstring> #define VK_Backspace 8 #define SPEED 200 using namespace std; const int Lenth=20; const int Width=50; int mark=0; int level=1; int count=0; char name[30]; char m[100],l[100]; void display(int screen[][Width],int Lenth,int Width) { int t; srand(time(0)); t = rand()%26+1; for(int i=0;i<Lenth;i++) { for(int j=0;j<Width;j++) { if(screen[i][j]>0) { if(screen[i][j]==27) cout<<"+"; else{ switch(t){ case 1:cout<<"A";break; case 2:cout<<"B";break; case 3:cout<<"C";break; case 4:cout<<"D";break; case 5:cout<<"E";break; case 6:cout<<"F";break; case 7:cout<<"G";break; case 8:cout<<"H";break; case 9:cout<<"I";break; case 10:cout<<"J";break; case 11:cout<<"K";break; case 12:cout<<"L";break; case 13:cout<<"M";break; case 14:cout<<"N";break; case 15:cout<<"O";break; case 16:cout<<"P";break; case 17:cout<<"Q";break; case 18:cout<<"R";break; case 19:cout<<"S";break; case 20:cout<<"T";break; case 21:cout<<"U";break; case 22:cout<<"V";break; case 23:cout<<"W";break; case 24:cout<<"X";break; case 25:cout<<"Y";break; case 26:cout<<"Z";break; default:break; } } } else cout<<" "; } cout<<endl; } } void change(int screen[][Width],int a[][5][5],int x,int y,int k) { for(int i=y,m=0;i<y+5;i++,m++) for(int j=x,n=0;j<x+5;j++,n++) screen[i][j]=a[k][m][n]; } void back(int screen[][Width],int a[][5][5],int x,int y) { for(int i=y;i<y+5;i++) for(int j=x;j<x+5;j++) screen[i][j]=0; } void ko(int screen[][Width],int a[][5][5],int x,int y) { change(screen,a,x,y,26); mark++; system("cls"); display(screen,Lenth,Width); Sleep(SPEED); back(screen,a,x,y); } int game(int screen[][Width],int a[][5][5],int x,int y,int k) { while(y+4<Lenth) { change(screen,a,x,y,k); system("cls"); display(screen,Lenth,Width); back(screen,a,x,y); keybd_event(VK_Backspace,0,0,0); keybd_event(VK_Backspace,0,KEYEVENTF_KEYUP,0); switch(getch()){ case 'a':if(k==0) {ko(screen,a,x,y); return 0;} else break; case 'b':if(k==1) {ko(screen,a,x,y); return 0;} else break; case 'c':if(k==2) {ko(screen,a,x,y); return 0;} else break; case 'd':if(k==3) {ko(screen,a,x,y); return 0;} else break; case 'e':if(k==4) {ko(screen,a,x,y); return 0;} else break; case 'f':if(k==5) {ko(screen,a,x,y); return 0;} else break; case 'g':if(k==6) {ko(screen,a,x,y); return 0;} else break; case 'h':if(k==7) {ko(screen,a,x,y); return 0;} else break; case 'i':if(k==8) {ko(screen,a,x,y); return 0;} else break; case 'j':if(k==9) {ko(screen,a,x,y); return 0;} else break; case 'k':if(k==10) {ko(screen,a,x,y); return 0;} else break; case 'l':if(k==11) {ko(screen,a,x,y); return 0;} else break; case 'm':if(k==12) {ko(screen,a,x,y); return 0;} else break; case 'n':if(k==13) {ko(screen,a,x,y); return 0;} else break; case 'o':if(k==14) {ko(screen,a,x,y); return 0;} else break; case 'p':if(k==15) {ko(screen,a,x,y); return 0;} else break; case 'q':if(k==16) {ko(screen,a,x,y); return 0;} else break; case 'r':if(k==17) {ko(screen,a,x,y); return 0;} else break; case 's':if(k==18) {ko(screen,a,x,y); return 0;} else break; case 't':if(k==19) {ko(screen,a,x,y); return 0;} else break; case 'u':if(k==20) {ko(screen,a,x,y); return 0;} else break; case 'v':if(k==21) {ko(screen,a,x,y); return 0;} else break; case 'w':if(k==22) {ko(screen,a,x,y); return 0;} else break; case 'x':if(k==23) {ko(screen,a,x,y); return 0;} else break; case 'y':if(k==24) {ko(screen,a,x,y); return 0;} else break; case 'z':if(k==25) {ko(screen,a,x,y); return 0;} else break; default:y++;break; } if(count>=0&&count<=20) {Sleep(SPEED);level=1;} else if(count>20&&count<=50) {Sleep(SPEED-50);level=2;} else if(count>50&&count<=70) {Sleep(SPEED-70);level=3;} else if(count>70&&count<=100) {Sleep(SPEED-100);level=4;} else if(count>100&&count<=150) {Sleep(SPEED-150);level=5;} else Sleep(30); } } void toyou(int screen[][Width],int a[][5][5]) { change(screen,a,1,1,8); change(screen,a,9,1,11); change(screen,a,15,1,14); change(screen,a,21,1,21); change(screen,a,27,1,4); change(screen,a,35,1,20); change(screen,a,1,Lenth-5,1); change(screen,a,7,Lenth-5,24); change(screen,a,15,Lenth-5,18); change(screen,a,22,Lenth-5,10); change(screen,a,28,Lenth-5,24); display(screen,Lenth,Width); } void seeyou(int screen[][Width],int a[][5][5]) { change(screen,a,1,1,18); change(screen,a,7,1,4); change(screen,a,13,1,4); change(screen,a,21,1,24); change(screen,a,27,1,14); change(screen,a,33,1,20); change(screen,a,1,Lenth-5,1); change(screen,a,7,Lenth-5,24); change(screen,a,15,Lenth-5,18); change(screen,a,22,Lenth-5,10); change(screen,a,28,Lenth-5,24); display(screen,Lenth,Width); } void end(int screen[][Width],int a[][5][5]) { system("cls"); cout<<"Game level="<<level<<endl; cout<<"Your mark is:"<<mark<<endl; cout<<"Leave your name:"; cin>>name; if(strcmp(name,"dailian")==0||strcmp(name,"dl")==0||strcmp(name,"lianlian")==0) toyou(screen,a); else seeyou(screen,a); } void start(int screen[][Width],int a[][5][5]) { while(1){ int x,k; srand(time(0)); x = rand()%(Width-4); srand(time(0)); k = rand()%26; if(game(screen,a,x,0,k)==0) { count++; while (kbhit()) getch(); continue;} else break; } } void about() { cout<<"All by sky."<<endl; cout<<"Just for fun."<<endl; cout<<"Blog:bolg.csdn.com/iamskying"<<endl; } void help() { cout<<"Rules of the game: Each eliminate one letterget one point, if there is a failure, game over"<<endl; } void read() { FILE *fp; int k=0; char ch; if((fp=fopen("Topscores.txt","rt+"))==NULL) fp=fopen("Topscores.txt","w+"); else{ ch=fgetc(fp); while(ch!=EOF) { ch=fgetc(fp); } } for(int i=0;name[i]!=0;i++) { ch=name[i]; fputc(ch,fp); } fputc(' ',fp); do{ ch=mark%10+'0'; m[k++]=ch; mark=mark/10; }while(mark!=0); for(int i=k-1;i>=0;i--) { ch=m[i]; fputc(ch,fp); } fputc(' ',fp); k=0; fputc('/n',fp); rewind(fp); fclose(fp); } void topscores() { FILE *fp; char ch; if((fp=fopen("Topscores.txt","rt+"))==NULL) cout<<"none now."<<endl; else{ ch=fgetc(fp); cout<<endl; cout<<"Top scores"<<endl<<endl; printf("%c",ch); while(ch!=EOF) { ch=fgetc(fp); printf("%c",ch); } printf("/n"); } } int main() { int screen[Lenth][Width]; memset(screen,0,sizeof(screen)); int a[27][5][5]={ {{0,0,1,0,0}, {0,1,0,1,0}, {0,1,0,1,0}, {1,1,1,1,1}, {1,0,0,0,1},}, {{2,2,2,2,2}, {2,0,0,0,2}, {2,2,2,2,2}, {2,0,0,0,2}, {2,2,2,2,2},}, {{3,3,3,3,3}, {3,0,0,0,0}, {3,0,0,0,0}, {3,0,0,0,0}, {3,3,3,3,3},}, {{4,4,4,4,0}, {4,0,0,0,4}, {4,0,0,0,4}, {4,0,0,0,4}, {4,4,4,4,0},}, {{5,5,5,5,5}, {5,0,0,0,0}, {5,5,5,5,5}, {5,0,0,0,0}, {5,5,5,5,5},}, {{6,6,6,6,6}, {6,0,0,0,0}, {6,6,6,6,6}, {6,0,0,0,0}, {6,0,0,0,0},}, {{7,7,7,7,7}, {7,0,0,0,0}, {7,0,7,7,7}, {7,0,0,7,0}, {7,7,7,7,0},}, {{8,0,8,0,8}, {8,0,8,0,8}, {8,8,8,8,8}, {8,0,8,0,8}, {8,0,8,0,8},}, {{0,0,9,0,0}, {0,0,9,0,0}, {0,0,9,0,0}, {0,0,9,0,0}, {0,0,9,0,0},}, {{0,0,10,0,0}, {0,0,10,0,0}, {0,0,10,0,0}, {0,0,10,0,0}, {10,10,10,0,0},}, {{11,0,0,11,0}, {11,0,11,0,0}, {11,11,0,0,0}, {11,0,11,0,0}, {11,0,0,11,0},}, {{12,0,0,0,0}, {12,0,0,0,0}, {12,0,0,0,0}, {12,0,0,0,0}, {12,12,12,0,0},}, {{0,13,0,13,0}, {13,0,13,0,13}, {13,0,13,0,13}, {13,0,13,0,13}, {13,0,13,0,13},}, {{14,0,0,0,14}, {14,14,0,0,14}, {14,0,14,0,14}, {14,0,0,14,14}, {14,0,0,0,14},}, {{15,15,15,15,15}, {15,0,0,0,15}, {15,0,0,0,15}, {15,0,0,0,15}, {15,15,15,15,15},}, {{16,16,16,16,16}, {16,0,0,0,16}, {16,16,16,16,16}, {16,0,0,0,0}, {16,0,0,0,0},}, {{17,17,17,17,17}, {17,0,0,0,17}, {17,0,0,17,17}, {17,17,17,17,17}, {0,0,0,0,17},}, {{18,18,18,18,18}, {18,0,0,0,18}, {18,18,18,18,18}, {18,0,18,0,0}, {18,0,0,18,0},}, {{19,19,19,19,19}, {19,0,0,0,0}, {19,19,19,19,19}, {0,0,0,0,19}, {19,19,19,19,19},}, {{20,20,20,20,20}, {0,0,20,0,0}, {0,0,20,0,0}, {0,0,20,0,0}, {0,0,20,0,0},}, {{21,0,0,0,21}, {21,0,0,0,21}, {21,0,0,0,21}, {21,0,0,0,21}, {0,21,21,21,0},}, {{22,0,0,0,22}, {22,0,0,0,22}, {22,0,0,0,22}, {0,22,0,22,0}, {0,0,22,0,0},}, {{23,0,23,0,23}, {23,0,23,0,23}, {23,0,23,0,23}, {23,0,23,0,23}, {0,23,0,23,0},}, {{24,0,0,0,24}, {0,24,0,24,0}, {0,0,24,0,0}, {0,24,0,24,0}, {24,0,0,0,24},}, {{25,0,0,0,25}, {0,25,0,25,0}, {0,0,25,0,0}, {0,0,25,0,0}, {0,0,25,0,0},}, {{26,26,26,26,26}, {0,0,0,26,0}, {0,0,26,0,0}, {0,26,0,0,0}, {26,26,26,26,26},}, {{0,27,0,0,27}, {0,27,0,0,27}, {27,27,27,0,27}, {0,27,0,0,27}, {0,27,0,0,27},} }; cout<<" abc game for dos"<<endl<<endl; cout<<" 1.start now"<<endl; cout<<" 2.top scores"<<endl; cout<<" 3.help"<<endl; cout<<" 4.about"<<endl; cout<<" 0.exit"<<endl; int n; cin>>n; switch(n){ case 1: system("cls"); start(screen,a); end(screen,a); read(); cout<<"Press 0 to return"<<endl; if(getch()=='0') { system("cls"); main(); } case 2: system("cls"); cout<<"Press 0 to return"<<endl; topscores(); if(getch()=='0') { system("cls"); main(); } case 3: system("cls"); cout<<"Press 0 to return"<<endl; help(); if(getch()=='0') { system("cls"); main(); } case 4: system("cls"); cout<<"Press 0 to return"<<endl; about(); if(getch()=='0') { system("cls"); main(); } case 0: system("cls"); cout<<"Thank you!"<<endl; break; default:system("cls");cout<<"Again."<<endl;main(); } return 0; }

你可能感兴趣的:(游戏,dos,Microsoft,System,express,FP)