c++迷宫打怪游戏
最近寫了一段迷宮打怪游戲,我想著要有生命值、分數、name(名字),干脆用了類,實際用不用都一樣...不要自己改代碼,因為里面的x/y坐標是反著的,你們搞不清楚,一改就廢
代碼(dev-c++運行通過,無報錯無警告):
#include<iostream> #include<cstdio> #include<time.h> #include<windows.h> #include<iomanip> #include<string> #include<conio.h> using namespace std;class game {public:void setcoin(int c,string n,int r){coin = c;name = n;ren = r;}void increasecoin(){coin += 5;}void increaseren(){ren -= 5;}void print(){cout<<endl<<"coin = "<<coin;cout<<endl<<"name = "<<name<<endl;cout<<endl<<"生命 = "<<ren;}private:int coin;string name;int ren; };int main() {start:system("color F0");/*****地圖*****/ char a[1000][1000] = {"########################################","#* # #","## $######### ################# ###### #","# # # # # ## # #","# # # #### ## # ##@# #### ##### ## # # #","# # # # # # # # # # # #","# # # #### ###### ############### # #","# # ## # # # # # #","# # #### ######## ################# # #","# ## # #$ #%# ##### # # #","# #####$### # # # ### # #","### # # # # ##### # # #","# ######################## # # # #","# # # # ## # ###","# ### #### ####### ########### #### ## #","# # # # +#","########################################",//大怪4 小怪3 };/*****初始化*****/cout<<"走迷宮游戲(+是出口,$是金幣,%是大怪獸,@是小怪獸,打掉2個怪獸且生命大于80才能通關)"<<endl;cout<<"請輸入你的昵稱"<<endl;string na;cin>>na;game player;player.setcoin(0,na,100);int jb=0;int rr=100;/*****打印map(a)*****/ for (int i=0;i<=16;i++){puts(a[i]);}/*****移動*****/char ch;int x=1,y=1;while(1){ch=_getch();if(ch=='a'){if(a[x][y-1]!='#'){a[x][y]=' ';y--;a[x][y]='*';}}if(ch=='s'){if(a[x+1][y]!='#'){a[x][y]=' ';x++;a[x][y]='*';}}if(ch=='d'){if(a[x][y+1]!='#'){a[x][y]=' ';y++;a[x][y]='*';}}if(ch=='w'){if(a[x-1][y]!='#'){a[x][y]=' ';x--;a[x][y]='*';}}system("cls");for(int i=0;i<=16;i++)puts(a[i]);if (x==15&&y==37){break;}if (x==2&&y==3){cout<<endl<<"金幣+5";player.increasecoin();jb+=5; }if (x==9&&y==15){cout<<endl<<"金幣+5";player.increasecoin();jb+=5; }if (x==10&&y==9){cout<<endl<<"金幣+5";player.increasecoin();jb+=5;}if (x==9&&y==18){a[10][16] = '#';cout<<endl<<"你的戰斗力是"<<jb/3<<",大怪獸戰斗力是4,";if (jb/3>4){cout<<"你贏了, 但你的生命值-5";player.increaseren();rr -= 5;if (x==9&&y==18){cout<<" ";}}if (jb/3<4){cout<<"你輸了,但怪獸被打死,你的生命值-15";player.increaseren();player.increaseren();player.increaseren();rr-=15;}}if (x==4&&y==18){cout<<endl<<"你的戰斗力是"<<jb/4<<",小怪獸戰斗力是3,";if (jb/4>3){cout<<"你贏了, 但你的生命值-5";player.increaseren();rr -= 5;}if (jb/4<3){cout<<"你輸了,但怪獸被打死,你的生命值-15";player.increaseren();player.increaseren();player.increaseren();rr-=15;}if (jb/4==3){cout<<"生命值不變";}}}if (rr>=80){system("cls");cout<<"你贏了!";player.print(); }if (rr<80){system("cls");cout<<"你輸了!";player.print(); cout<<endl<<"按下a再來一局";int a =_getch();if (a==97){goto start;}}return 0; }總結
- 上一篇: js模拟京东搜索框
- 下一篇: ps插件cutterman安装与使用