一道大力模拟题。
凡是模拟题都可以考虑面向对象。
当然面向对象在速度上有劣势,但是显然是更清晰的。
#include<iostream>
#include<cstdio>
using namespace std;
#define Max(_A,_B) ((_A)>(_B)?(_A):(_B))
struct Ans{
int HP,STR,DEF;
};
char MAP[105][105];
int enemyHP,enemySTR,enemyDEF;
class Player{
private:
int HP;
int STR;
int DEF;
int X;
int Y;
public:
inline void playerReset(int _X,int _Y,int _STR,int _DEF){
X=_X,Y=_Y,STR=_STR,DEF=_DEF;
HP=0;
}
inline Ans playerQuery(){
return (Ans){HP,STR,DEF};
}
inline void eventQ(){
STR+=5;
}
inline void eventY(){
DEF+=5;
}
inline void eventR(){
HP=(HP>10)?(HP-10):0;
}
inline void eventM(){
int monsterDamage;
monsterDamage=Max(1,((enemyHP+Max(1,STR-enemyDEF)-1)/(Max(1,STR-enemyDEF)))*(Max(1,enemySTR-DEF)));
HP+=monsterDamage;
}
inline void playerGetEvent(){
switch(MAP[X][Y]){
case '.':{
return;
break;
}
case 'M':{
eventM();
break;
}
case 'R':{
eventR();
break;
}
case 'Q':{
eventQ();
break;
}
case 'Y':{
eventY();
break;
}
}
}
inline void playerMove(char moveOperator){
int _DX,_DY;
switch(moveOperator){
case 'W':{
_DX=0;
_DY=-1;
break;
}
case 'E':{
_DX=0;
_DY=1;
break;
}
case 'N':{
_DX=-1;
_DY=0;
break;
}
case 'S':{
_DX=1;
_DY=0;
break;
}
}
X+=_DX,Y+=_DY;
playerGetEvent();
}
};
int n,m,q;
Player player;
void init(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
cin>>MAP[i]+1;
}
scanf("%d%d%d",&enemyHP,&enemySTR,&enemyDEF);
int x,y,d,e;
scanf("%d%d%d%d%d",&x,&y,&d,&e,&q);
player.playerReset(x,y,d,e);
char ch[5];
Ans nw;
for(int i=1;i<=q;++i){
cin>>ch;
if(ch[0]=='M'){
cin>>ch;
player.playerMove(ch[0]);
}else if(ch[0]=='Q'){
nw=player.playerQuery();
printf("%d %d %d\n",nw.HP,nw.STR,nw.DEF);
}
}
}
int main(){
init();
return 0;
}