https://picdl.sunbangyan.cn/2023/11/23/43d6808e0a13263f35cffcfc5a4641bb.jpeg
#include<bits/stdc++.h> using namespace std; int upjy=100; long long sum=0,cnt=0; //怪兽 class monster { public: int x,y; int hp,zdl; monster(){ hp=rand()%1000+1; zdl=rand()%1000+1; x=rand()%20+1; y=rand()%20+1; } void die(){ x=-114514; y=-114514; } };
class hero{//英雄 public: int lvl; int hp,high_hp; int x,y; int zdl; int jy; hero(){ lvl=1; high_hp=100; hp=100; x=0,y=0; zdl=100; jy=0; } void walk(char op){ if(op==‘W’){//up if(y+1<=20){ y++; }else cout<<“不行”<<endl; } if(op==‘S’){//down if(y-1>=0){ y—; }else cout<<“不行”<<endl; } if(op==‘A’){//left if(x-1>=0){ x—; }else cout<<“不行”<<endl; } if(op==‘D’){//right if(x+1<=20){ x++; }else cout<<“不行”<<endl; } } void lvl_up(){ if(jy>=upjy){ jy-=upjy; lvl++; high_hp+=rand()%100+1; hp=high_hp; zdl+=rand()%100+1; upjy*=2; cout<<“升级!下一次需要”<<upjy<<endl; } } bool die(){ if(hp==0)return 1; return 0; } void hp_up(){ if(x==0&&y==0){ hp=high_hp; cout<<“血量加满!\n”; } } bool operator>(monster mt){//attack if(x==mt.x&&y==mt.y){ cout<<“碰到怪兽,0逃跑,1战斗\n”; printf(“怪兽属性:血量%d 战斗力%d”,mt.hp,mt.zdl); int op; cin>>op; if(op){ hp-=(mt.zdl/zdl)*mt.hp; jy+=mt.zdl; lvl_up(); mt.die(); cnt++; sum+=(mt.hp+mt.zdl); } else{ hp-=mt.zdl/10; } return 1; } return 0; } void print(){ printf(“level%d 血量%d/%d 战斗力%d 经验%d xy%d,%d\n”,lvl,hp,high_hp,zdl,jy,x,y); } }; //公主 class queen { public: bool win(hero g){ if(g.x==20&&g.y==20)return 1; else return 0; } };
class boss{ public: int zdl=rand()%(sum+1); }; int main(){ srand(time(0)); queen gz; hero my; monster mons[100]; while(1){ my.print(); if(my.die()){ cout<<“你死了”;return 0; } if(cnt==5||(my.x==20&&my.y==20)){ cout<<“BOSS出现!\n”; boss BOSS; my.hp-=BOSS.zdl; my.jy+=BOSS.zdl; my.lvl_up(); if(my.die()){ cout<<“你死了”;return 0; } if(gz.win(my)){ cout<<“胜利!“;return 0; } } char w; cout<<“你往哪边走W/A/S/D(9升级)\n”; cin>>w; my.walk(w); my.hp_up(); if(w==‘9’)my.lvl_up(); for(int i=0;i<100;i++){ if(my>mons[i])continue; } } }