C++#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
struct node1 {
string name;
int x, y;
} a;
struct node2 {
string name;
int x, y;
} b;
string str1, str2;
int main() {
printf("------------------星际战舰-----------------\n");
printf("建造战舰,请为你的战舰取名......\n");
Sleep(100);
cin >> str1;
srand(time(NULL));
node1 *p1 = new node1({str1, rand() % 100, rand() % 1000});
printf("建造成功,攻击/生命:%d / %d\n", p1->x, p1->y);
Sleep(300);
while (1) {
printf("报告舰长,怪兽来袭,请为怪兽命名......\n");
cin >> str2;
Sleep(100);
node2 *p2 = new node2({str2, rand() % 100, rand() % 1000});
printf("命名完成,怪兽攻击/生命:%d/%d\n", p2->x, p2->y);
Sleep(300);
if (p1->x > p2->x) {
p1->y = p1->x - (p2->x / p1->x) * p2->y;
delete p2;
printf("恭喜,你的战舰胜利了,剩余血量%d\n", a.y);
} else {
printf("很遗憾,你失败了");
delete p1;
return 0;
}
}
return 0;
}