#include<bits/stdc++.h> #include<windows.h> #include<conio.h> #define rep(A,B) for(int i = A; i <= B; ++ i) #define Rep(A,B) for(int j = A; j < B; ++j) #define zhangqixuan return #define wrong_input cout << “输入有误,请重新输入” << endl; #define code 0 #define nothing int NOTHING using namespace std; #define N 20 #define WAIT_TIME 39 void color(int x) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); } void slowput(string s, int _color, int __T, bool isenter) { color(_color);
if (isenter) s += "\n";
rep(0, s.size()) {
cout << s[i];
Sleep(__T);
}
color(0x0F);} bool dead[N]; int playernum; struct player { string name; int leftnum, rightnum; int blood; } players[N][2];
void win() { rep(1, playernum) { if (!dead[i]) { system(“cls”); system(“color 6D”); cout << players[i][1].name << “赢了!\nCongratulations!\n”; while (1); } } } void xiaoguo(int mubiao,int zhu, int fu,int attcker) { int hurt = 0; if(zhu == 0) hurt = 2; if(zhu == 6) { if(fu == 6) hurt = 2; else hurt = 1; } if(zhu == 8) { if(fu == 8) hurt = 4; else hurt = 2; } if(hurt == 9) { players[attcker][1].blood++; hurt = 1; } if(players[mubiao][1].leftnum == 5 || players[mubiao][1].rightnum == 5 ) hurt = min(hurt,1); players[mubiao][1].blood -= hurt; } int main() { color(0x03); cout << ” /------------- A + B problem -------------\\n”; PLAYERNUM_IN: color(0x0F); slowput(“请输入玩家数量:”, 0x0b, WAIT_TIME, 0); { string IN_STR; cin >> IN_STR; Rep(0, IN_STR.size()) { if ((!isdigit(IN_STR[j])) || j >= 3) { color(0x0C); cout << “玩家数量有误,请重新输入\n”; goto PLAYERNUM_IN; } } playernum = stoi(IN_STR); } if (playernum < 2 || playernum >= 20) { color(0x0C); cout << “玩家数量有误,请重新输入\n”; goto PLAYERNUM_IN; } printf(“\n”); rep(1, playernum) { string OUTP = “玩家” + to_string(i) + “号,请输入你的姓名: ”; slowput(OUTP, 0x0E, WAIT_TIME, 0); cin >> players[i][1].name; players[i][1].leftnum = players[i][1].rightnum = players[i][0].leftnum = players[i][0].rightnum = 1; players[i][1].blood = players[i][0].blood = 10;
}
for (int now_p = 1;; now_p++) {
{
int alive = 0;
for (int i = 1; i <= playernum; ++i) {
if (!dead[i]) alive++;
}
if (alive == 1) win();
}
if (now_p == playernum + 1) now_p = 1;
while (players[now_p][1].blood <= 0) {
now_p++;
if (now_p == playernum + 1) now_p = 1;
}
system("cls");
cout << "玩家" << now_p << "号" << players[now_p][1].name << ",现在是你的回合" << endl << endl;
cout << "场上现状是:" << endl << endl;
for (int i = 1; i <= playernum; ++i) {
if (i == now_p || dead[i]) continue;
printf("第%d号玩家", i);
cout << players[i][1].name << ":\n";
printf("左手:%d 右手:%d\n血量:%d\n\n", players[i][1].leftnum, players[i][1].rightnum, players[i][1].blood);
}
printf("\n你的现状是:左手:%d 右手:%d\n血量:%d\n", players[now_p][1].leftnum, players[now_p][1].rightnum, players[now_p][1].blood);
cout << "你要攻击几号玩家?" << endl;ATTACK_IN: string AT; cin >> AT; if (AT.size() > 3) { cout << “输入有误,请重新输入”; goto ATTACK_IN; } for (int JIA = 0; JIA < AT.size(); JIA++) if (!isdigit(AT[JIA])) { cout << “输入有误,请重新输入” << endl; goto ATTACK_IN; } int he = stoi(AT); if(he == now_p || he > playernum) { wrong_input goto ATTACK_IN; } cout << “你要用你的什么手攻击他的什么手?依次输入手的编号。(左手L,右手R)” << endl; char yourhand, hishand;; cin >> yourhand >> hishand; yourhand = toupper(yourhand), hishand = toupper(hishand); if ((yourhand == ‘L’ || yourhand == ‘R’) && (hishand == ‘L’ || hishand == ‘R’)) nothing; else { wrong_input goto ATTACK_IN; } int attack_hand = (yourhand == ‘L’ ? 1 : 0), bei_at_hand = (hishand == ‘L’ ? 1 : 0); players[now_p][0] = players[now_p][1]; if (attack_hand) { if (bei_at_hand) players[now_p][1].leftnum += players[he][1].leftnum; else players[now_p][1].leftnum += players[he][1].rightnum; players[now_p][1].leftnum %= 10; xiaoguo(he,players[now_p][1].leftnum,players[now_p][1].rightnum,now_p); if(players[now_p][0].leftnum == 5) players[now_p][1].blood++;
} else {
if (bei_at_hand) players[now_p][1].rightnum += players[he][1].rightnum;
else players[now_p][1].rightnum += players[he][1].rightnum;
players[now_p][1].rightnum %= 10;
xiaoguo(he,players[now_p][1].rightnum,players[now_p][1].leftnum,now_p);
if(players[now_p][0].rightnum == 5) players[now_p][1].blood++;
}
}
zhangqixuan code;}