C++#include<bits/stdc++.h>
#include<windows.h>
#include<time.h>
#include<ctime>
#include<conio.h>
using namespace std;
int ren;
struct shuxing{
string name;
int mxhealth;
int nowhealth;
int gong;
int fang;
int su;
int mo;
}play[10005];
bool cmp(shuxing x, shuxing y){
if(x.su != y.su) return x.su > y.su;
else return x.gong > y.gong;
}
int Rand(int n, int fan){ // 随机函数 n:平均值 fan:浮动范围 n-fan~n+fan
srand((unsigned)time(NULL));
if(rand() % 2 == 0){
srand((unsigned)time(NULL));
return n - rand()%(fan+1);
}else{
srand((unsigned)time(NULL));
return n + rand()%(fan+1);
}
}
void qing(){ system("cls"); } //清屏
void jixu(){ //见输出文字
cout << "按随机键继续......";
char ch=_getch();
}
void chongshu(string s, int k, int sl){ //重复输出k次s,等待sl毫秒
for(int i = 1; i <= k; i++){
cout << s;
if(sl != 0) Sleep(sl);
}
}
void C(string s, int sl){ //输出字符串s,字符间隔sl毫秒
for(int i = 0; i < s.size(); i++){
if(s[i] == '`') cout << "\n";
else{
cout << s[i];
Sleep(sl);
}
}
}
bool over(){
int huo = 0;
for(int i = 1; i <= ren; i++) if(play[i].nowhealth > 0) huo++;
return (huo <= 1);
}
void kai(){
chongshu("\n", 10, 0);
chongshu("=", 40, 20);
cout << "\n";
chongshu(" ", 10, 0);
C("欢迎游玩名字竞技场", 30);
cout << "\n";
chongshu("=", 40, 20);
Sleep(1000);
for(int i = 10; i >= 0; i--){
qing();
chongshu("\n", i, 0);
chongshu("=", 40, 0);
cout << "\n";
chongshu(" ", 10, 0);
C("欢迎游玩名字竞技场", 0);
cout << "\n";
chongshu("=", 40, 0);
}
qing();
}
void shuren(){
string s;
while(1){
qing();
C("请输入人名(输入-1停止输入)`", 10);
cin >> s;
if(s == "-1") break;
else ren++, play[ren].name += s;
play[ren].mxhealth = Rand(800, 200);
play[ren].nowhealth = play[ren].mxhealth;
play[ren].gong = Rand(75, 15);
play[ren].fang = Rand(30, 10);
play[ren].su = Rand(15, 5);
play[ren].mo = Rand(75, 15);
}
C("加载中", 0);
chongshu(".", 3, 500);
Sleep(1000);
qing();
C("按随机键查看人物", 10);
char ch=_getch();
for(int i = 1; i <= ren; i++){
qing();
cout << play[i].name << "\n" << "maxHP:" << play[i].mxhealth << "\n攻击:" << play[i].gong << "\n防御:" << play[i].fang << "\n速度:" << play[i].su << "\n魔力:" << play[i].mo << "\n";
jixu();
}
qing();
}
void cshuxing(){
for(int i = 1; i <= ren; i++){
cout << play[i].name << "maxHP:" << play[i].mxhealth << " 攻击:" << play[i].gong << " 防御:" << play[i].fang << " 速度:" << play[i].su << " 魔力:" << play[i].mo << "\n";
}
chongshu("_", 50, 0);
cout << "\n";
for(int i = 1; i <= ren; i++){
cout << play[i].name << "HP:" << play[i].nowhealth << "\n";
}
chongshu("_", 50, 0);
cout << "\n";
}
void zhandou(){
while(over() == false){
sort(play+1, play+ren+1, cmp);
for(int i = 1; i <= ren && over() == false; i++){
if(play[i].nowhealth <= 0) continue;
cshuxing();
int t = i;
while(t == i || play[t].nowhealth <= 0){
t = rand()%ren+1;
}
if(rand()%100+1 <= play[i].mo/10+10){
int jineng = rand()%100+1;
if(jineng >= 1 && jineng <= 20){
cout << play[i].name << "发动雷击术!";
while(t == i || play[t].nowhealth <= 0){
t = rand()%ren+1;
}
int shu = rand()%3+3;
for(int i = 1; i <= shu; i++){
cout << "\n ";
if(rand()%100+1 <= play[t].su){
cout << play[t].name << "回避了攻击";
}else{
int shang = max(0, play[i].gong/2-play[t].fang);
cout << play[t].name << "受到" << shang << "伤害";
play[t].nowhealth -= shang;
}
}
}
if(jineng >= 21 && jineng <= 30){
cout << play[i].name << "发起吸血攻击,";
if(rand()%100+1 <= play[t].su){
cout << play[t].name << "回避了攻击";
}else{
int shang = max(0.0, play[i].mo*1.15-play[t].fang+Rand(0, 10));
cout << play[t].name << "受到" << shang << "伤害," << play[i].name << "回复血量" << shang/2 << "点";
play[t].nowhealth -= shang, play[i].nowhealth += shang/2;
}
}
if(jineng >= 31 && jineng <= 50){
cout << play[i].name << "会心一击,";
if(rand()%100+1 <= play[t].su/1.5){
cout << play[t].name << "回避了攻击";
}else{
int shang = max(0.0, play[i].gong*1.5-play[t].fang*0.8);
cout << play[t].name << "受到" << shang << "伤害";
play[t].nowhealth -= shang;
}
}
if(jineng >= 51 && jineng <= 55){
cout << play[i].name << "使用瘟疫,";
if(rand()%100+1 <= play[t].su){
cout << play[t].name << "回避了攻击";
}else{
int jian = rand()%50+25;
cout << play[t].name << "体力减少" << jian << "%";
play[t].nowhealth = play[t].nowhealth-play[t].nowhealth*jian/100;
}
}
if(jineng >= 56 && jineng <= 65){
cout << play[i].name << "使用火球术,";
if(rand()%100+1 <= play[t].su){
cout << play[t].name << "回避了攻击";
}else{
int shang = max(0.0, play[i].mo*1.37+Rand(0, 10)-play[t].fang);
cout << play[i].name << "受到" << shang << "伤害";
play[t].nowhealth -= shang;
}
}
if(jineng >= 66 && jineng <= 70){
cout << play[i].name << "蓄力,攻击小幅度上升";
play[i].gong *= 1.2;
}
if(jineng >= 71 && jineng <= 78){
cout << play[i].name << "使用生命之轮" << "与" << play[t].name << "血量调换";
swap(play[i].nowhealth, play[t].nowhealth);
}
if(jineng >= 79 && jineng <= 86){
int jia = play[i].mo * Rand(10, 2) / 10;
cout << play[i].name << "使用治愈魔法," << play[i].name << "回复" << jia << "滴血";
play[i].nowhealth += jia;
}
if(jineng >= 87){
cout << play[t].name << "使用强化药水,所有属性小幅度增加";
play[i].fang += 5, play[i].gong += 5, play[i].su += 5, play[i].mo += 5;
}
}else{
cout << play[i].name << "发起攻击,";
if(rand()%100+1 <= play[t].su){
cout << play[t].name << "回避了攻击";
}else{
int shang = max(0, play[i].gong+Rand(0, 10)-play[t].fang);
cout << play[t].name << "受到" << shang << "伤害";
play[t].nowhealth -= shang;
}
}
if(play[t].nowhealth <= 0) cout << "," << play[t].name << "被击倒了";
if(play[t].nowhealth < 20 && play[t].nowhealth > 0 && rand()%101<=play[t].mo/5){
cout << "," << play[t].name << "垂死挣扎,所有属性大幅度上升'o'!";
play[t].fang = play[t].fang / 2 * 3 + 1, play[t].gong = play[t].gong / 2 * 3 + 1, play[t].su = play[t].su / 2 * 3 + 1, play[t].mo = play[t].mo / 2 * 3 + 1;
}else if(play[t].nowhealth <= 0 && rand()%101<=play[t].mo/5){
cout << ", " << play[t].name << "在死前自爆,";
int shang = max(0, play[t].mo*2-play[i].fang+Rand(0, 10));
cout << play[i].name << "受到" << shang << "伤害";
play[i].nowhealth -= shang;
if(play[i].nowhealth <= 0) cout << "," << play[i].name << "被炸死了";
}
cout << "\n";
jixu();
qing();
}
}
}
int main(){
kai();
srand((unsigned)time(NULL));
shuren();
zhandou();
qing();
for(int i = 1; i <= ren; i++){
if(play[i].nowhealth > 0){
cout << play[i].name << "赢了";
return 0;
}
}
cout << "全部人同归于尽!!!";
return 0;
}