c++语言小游戏基本模板(可借鉴)
程序代码:
#include<iostream> #include<conio.h> #include<cmath> #include<Windows.h> #include<ctime> #include<cstdlib> #include<stack> #include<string> int t[10010]; void putnum(int start , int end, int amt){ for(int i=start;i<end;i++){ t[i]=amt; } } using namespace std; void print(string s,bool flg,char a,int &point){ for(int i=0;i<s.length();++i){ cout<<s[i]; if(flg){ system("color a0"); system("color 0a"); } Sleep(t[point]); point++; } cout<<a; } char see(){ while(kbhit()){ return getch(); } } int main(){ system("color 0a"); putnum(0,3,50); putnum(3,7,200); putnum(7,10,50); string s[100]={"===GAME===","----------------------------------------","CLICK A TO START CLICK B FOR INFO","CLICK C FOR SETTINGS CLICK D TO QUIT","----------------------------------------"};//16,24, int pin=0; print(s[0],1,'\n',pin); pin=0; putnum(0,10,0); c: putnum(0,160,50); for(int i=1;i<=4;++i){ print(s[i],0,'\n',pin); } bool start=false; while(1){ switch(see()){ case 'a': start=true; break; case 'b': goto a; break; case 'c': goto b; break; case 'd': return 0; default: continue; } if(start==true)goto stt; } stt: cout<<"this is the game\n"; while(1){if(see()=='d'){return 0;}} a: cout<<"CLICK A TO GO LEFT\n"; cout<<"CLICK D TO GO RIGHT\n"; cout<<"CLICK W TO GO UP\n"; cout<<"CLICK S TO GO DOWN\n"; cout<<"MOVE TO THE END POINT 'X' TO WIN\n"; cout<<"EAT PEA '*' TO GET ENERGY\n"; goto c; b: cout<<"CLICK B TO BACK\n"; cout<<"...\n"; while(1){if(see()=='b'){goto c;}} return 0; }