5V5游戏,初始化完毕后首先己方攻击,每次攻击随机从对方阵营筛选一个敌人进行攻击.
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Demo
{
class Hero
{
public String name; //英雄名字
public int hp; //血量
public int mp; // 魔法值
public int physicsAttack; // 物理攻击力
public int magicAttack; //魔法攻击力
public String position; //位置
public String DaZhao; //大招
public int count; //次数
//无参构造
public Hero() { }
public Hero(String name, int hp, int mp, int physicsAttack, int magicAttack, String position, String DaZhao, int count)
{
this.name = name;
this.hp = hp;
this.mp = mp;
this.physicsAttack = physicsAttack;
this.magicAttack = magicAttack;
this.position = position;
this.DaZhao = DaZhao;
this.count = count;
}
}
//战斗管理类
class BattleControl
{
public List ours; //存储五个英雄
public List enemy; //类型
public int round; //回合数记录
private float gameTime; //回合时间
public BattleControl() { }
public BattleControl(List ours, List enemy, int round)
{
this.ours = ours;
this.enemy = enemy;
this.round = round;
}
//遍历 输出还在场的英雄
public void foreh(List a)
{
Console.WriteLine();
for (int t = 0; t < a.Count; t++)
{
Console.WriteLine(" 英雄姓名{0},剩余血量:{1} 剩余魔法值:{2}", a[t].name, a[t].hp, a[t].mp);
}
}
//杀人剑及其杀人书
public void book(List a, int i)
{
a[i].mp += 20;
a[i].physicsAttack += 20;
Console.WriteLine(" {0}击杀了英雄,获得了增益!目前物理攻击为:{1},魔法值为:{2}", a[i].name, a[i].physicsAttack, a[i].mp);
}
public void Dazhao(List a, List b, int i, int j)
{
b[j].hp -= 30;
Console.WriteLine(" {0}对{2}使用了--{1}--,造成了30点伤害!", a[i].name, a[i].DaZhao, b[j].name);
}
//开局加强属性
public void Boss(List a)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\n 选择一个你要加强的角色,该角色属性会大幅增加!!\n");
Console.WriteLine(" [0]:{0} [1]:{1} [2]:{2} [3]:{3} [4]:{4}",a[0].name,a[1].name,a[2].name,a[3].name,a[4].name);
int i;
i = Convert.ToInt32(Console.ReadLine());
while (i > 4 || i < 0) {
Console.WriteLine("输入有误!请重新输入!");
i = Convert.ToInt32(Console.ReadLine());
}
a[i].mp += 100;
a[i].physicsAttack += 100;
Console.WriteLine(" {0}开局获得了BOSS之力!目前物理攻击为:{1},魔法值为:{2}", a[i].name, a[i].physicsAttack, a[i].mp);
}
//全局buff加成!
public void Buff(List a) {
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine(" 选择全员buff![0]:加血! [1]加蓝! [2]:加攻击!");
int num2;
num2 = Convert.ToInt32(Console.ReadLine());
while (num2 > 2 || num2 < 0)
{
Console.WriteLine("输入有误!请重新输入!");
num2 = Convert.ToInt32(Console.ReadLine());
}
switch (num2) {
case 0:
//加血
for (int i = 0; i < a.Count; i++)
{
a[i].hp += 50;
}
Console.WriteLine("你选择了加血BUFF!全员加血50滴!");
break;
case 1:
//加蓝
for (int i = 0; i < a.Count; i++)
{
a[i].mp += 50;
}
Console.WriteLine("你选择了加蓝buff!全员加蓝50!");
break;
case 2:
for (int i = 0; i < a.Count; i++)
{
a[i].physicsAttack += 50;
}
Console.WriteLine("你选择了加攻击力buff!全员加攻击力50!");
break;
}
}
}
class Program
{
static void Main(string[] args)
{
BattleControl battle = new BattleControl();
List h1 = new List(); //红色
List h2 = new List(); //蓝色
#region 添加英雄对象
Hero A1 = new Hero("程咬金", 300, 100, 20, 10, "上单", "正义潜能", 0);
Hero A2 = new Hero("公孙离", 200, 100, 50, 10, "射手", "孤鹜断霞", 0);
Hero A3 = new Hero("明世隐", 200, 100, 10, 10, "辅助", "泰卦长生", 0);
Hero A4 = new Hero("橘右京", 200, 100, 40, 10, "打野", "秘剑脉刀", 0);
Hero A5 = new Hero("王昭君", 200, 100, 10, 50, "中单", "寒冬之力", 0);
h1.Add(A1);
h1.Add(A2);
h1.Add(A3);
h1.Add(A4);
h1.Add(A5);
Hero B1 = new Hero("东方耀", 300, 100, 20, 10, "上单", "归尘之心", 0);
Hero B2 = new Hero("孙尚香", 200, 100, 50, 10, "射手", "弩炮射击", 0);
Hero B3 = new Hero("牛魔王", 200, 100, 10, 10, "辅助", "镇山怒吼", 0);
Hero B4 = new Hero("孙悟空", 200, 100, 40, 10, "打野", "大闹天宫", 0);
Hero B5 = new Hero("武则天", 200, 100, 10, 50, "中单", "女帝魂辉", 0);
h2.Add(B1);
h2.Add(B2);
h2.Add(B3);
h2.Add(B4);
h2.Add(B5);
#endregion
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n 欢迎来到王者荣耀\n\n\n");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("红色方阵容:\n");
battle.foreh(h1);
battle.Boss(h1);
battle.Buff(h1);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("蓝色方阵容:\n");
battle.foreh(h2);
battle.Boss(h2);
battle.Buff(h2);
#region 攻击
int round = 0;
int huihe = 0;
while (h1.Count != 0 && h2.Count != 0)
{
++round;
if (round % 2 != 0)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine();
Console.WriteLine(" ========================第" + (++huihe) + "回合=====================\n");
for (int i = 0; i < h1.Count; i++)
{
h1[i].count++;
Console.ForegroundColor = ConsoleColor.Red;
int random2 = new Random((int)DateTime.Now.Ticks).Next(h2.Count); //使用计时周期数ticks作为时间种子
if (h2.Count == 0 || h1.Count == 0)
{
break;
}
if (h2[random2].hp > 0)
{
//判断蓝耗
if (h1[i].mp >= h1[i].magicAttack)
{
h2[random2].hp = h2[random2].hp - (h1[i].physicsAttack + h1[i].magicAttack);
h1[i].mp -= h1[i].magicAttack;
}
else
{
h2[random2].hp -= h1[i].physicsAttack;
}
if (h1[i].count > 3)
{
battle.Dazhao(h1, h2, i, random2);
}
}
if (h2[random2].hp == 0 || h2[random2].hp < 0)
{
int n = h1[i].physicsAttack + h1[i].magicAttack;
h2[random2].hp = 0;
Console.WriteLine(" {0}击杀了{1}", h1[i].name, h2[random2].name);
battle.book(h1, i);
h2.Remove(h2[random2]);
continue;
}
Thread.Sleep(50); //触发间隔时间太短 随机数一样。 因此加了延迟,防止产生太快。
Console.WriteLine(" {0}攻击了{1},剩余血量为{2}。", h1[i].name, h2[random2].name, h2[random2].hp);
}
}
else
{
Console.WriteLine(" \n");
for (int i = 0; i < h2.Count; i++)
{
h2[i].count++;
Console.ForegroundColor = ConsoleColor.Blue;
int random1 = new Random((int)DateTime.Now.Ticks).Next(h1.Count);
//基于三个if判断 第一个:判断是否为空。 第二个 去进行判断mp蓝量。 第三个 判断hp血量。
if (h2.Count == 0 || h1.Count == 0)
{
break;
}
if (h1[random1].hp > 0)
{
if (h2[i].mp >= h2[i].magicAttack)
{
h1[random1].hp = h1[random1].hp - (h2[i].physicsAttack + h2[i].magicAttack);
h2[i].mp -= h2[i].magicAttack;
}
else
{
h1[random1].hp -= h2[i].physicsAttack;
}
if (h2[i].count > 3)
{
battle.Dazhao(h2, h1, i, random1);
}
}
if (h1[random1].hp <= 0)
{
h1[random1].hp = 0;
Console.WriteLine(" {0}击杀了{1}", h2[i].name, h1[random1].name);
battle.book(h2, i);
h1.Remove(h1[random1]);
continue;
}
Thread.Sleep(50);
Console.WriteLine(" {0}攻击了{1},剩余血量为{2}。", h2[i].name, h1[random1].name, h1[random1].hp);
}
}
}
#endregion
#region 胜利判断
if (h2.Count == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" 蓝色方全部阵亡!红色方胜利!\n");
Console.WriteLine(" 获胜方英雄:");
battle.foreh(h1);
}
else
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(" 红色方全部阵亡!蓝色方胜利!\n");
Console.WriteLine(" 获胜方英雄:");
battle.foreh(h2);
}
#endregion
Console.ReadKey();
}
}
}