你好,我正在尝试做一个控制台游戏,我试图做一些算法,有利于一些敌人的产卵,例如:我有三个敌人单位,他们是“小巨魔”,“大滚动”,“战争滚动”,小巨魔是最弱的,我希望他比其他人更多,而大巨魔在中间,而战争巨魔是最后,我想让他一个罕见的事件。我做了一个简单的算法,从数组中选择一个随机元素。
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
int main(){
srand(time(0));
string PickRand[3] = {"Small Troll" , "Big Troll" , "War Troll"};
int i;
i = rand() %3;
cout <<PickRand[i] + " Approaches You!"<<endl;
if (i == 0){
cout <<"It has 35 Health"<<endl;
}else if (i == 1){
cout <<"It Has 75 Health"<<endl;
}else if (i == 2){
cout <<"It Has 200 Health"<<endl;
}
return 0;
}
发布于 2022-01-07 06:15:51
没关系,我自己修的,这是代码
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
int main(){
srand(time(0));
int WarTroll[9] = {1,2,3,4,5,6,7,8,9};
int WarTrollChance = 0;
for(int i = 0;i<50;i++){
int WarTrollRandom = rand()%9;
if (WarTrollRandom == 1){
WarTrollChance++;
if (WarTrollChance == 1){
cout <<"War Troll Approaches You!"<<endl;
}
}
}
https://stackoverflow.com/questions/70610872
复制相似问题