namespace 对战游戏
{
class Program
{
#region
public struct JueSe //创建一个角色对象
{
public string XingMing;//这个对象中有这些属性
public int GongJi;
public int ShengMing;
public int HuJiaZhi;
}
public struct JiNeng //创建技能对象
{
public string JiNengMingCheng;
public int JiNengShangHai;
}
public struct WuQi //创建武器对象
{
public string MingCheng;
public int GongJiLi;
}
public struct HuJia //创建护甲对象
{
public string MingZi;
public int HuJiaZhi;
}
#endregion
static void Main(string[] args)
{
#region 生成武器库
WuQi wq1 = new WuQi(); //新建武器1
wq1.MingCheng = "大剑";
wq1.GongJiLi = 100;
WuQi wq2 = new WuQi();
wq2.MingCheng = "小刀";
wq2.GongJiLi = 50;
WuQi wq3 = new WuQi();
wq3.MingCheng = "火枪";
wq3.GongJiLi = 200;
WuQi wq4 = new WuQi();
wq4.MingCheng = "火柴";
wq4.GongJiLi = -10;
#endregion
#region 生成护甲
HuJia FY1 = new HuJia(); //新建护甲1
FY1.MingZi = "草甲";
FY1.HuJiaZhi = 20;
HuJia FY2 = new HuJia();
FY2.MingZi = "木甲";
FY2.HuJiaZhi = 40;
HuJia FY3 = new HuJia();
FY3.MingZi = "铁甲";
FY3.HuJiaZhi = 60;
#endregion
#region 创建角色
Random SuiJi = new Random(); // 创建随机数
JueSe JS1 = new JueSe(); //创建一个角色1.
Console.Write("请输入第一个角色的姓名:");//在前端让用户输入字符.
JS1.XingMing = Console.ReadLine();//输入的内容赋值给角色1的姓名.
JS1.GongJi = SuiJi.Next(80, 120);//设定角色1攻击
JS1.HuJiaZhi = 0; //设定角色护甲
JS1.ShengMing = SuiJi.Next(8000, 12000);//设定色1生命时1000
Random HQSuiJi = new Random(); // 创建随机数
int HuoDewuqi = HQSuiJi.Next(0, 101); //创建获取武器的几率
if (HuoDewuqi <= 30)
{
Console.WriteLine("获得武器" + wq1.MingCheng);
JS1.GongJi += wq1.GongJiLi;
}
else if (HuoDewuqi <= 70)
{
Console.WriteLine("获得武器" + wq2.MingCheng);
JS1.GongJi += wq2.GongJiLi;
}
else if (HuoDewuqi <= 80)
{
Console.WriteLine("获得武器" + wq1.MingCheng);
JS1.GongJi += wq3.GongJiLi;
}
else
{
Console.WriteLine("获得武器" + wq1.MingCheng);
JS1.GongJi += wq4.GongJiLi;
}
Random FangYu = new Random(); // 创建护甲随机数
int HQFangYu = HQSuiJi.Next(0, 101); //创建获取护甲的几率
if (HQFangYu <= 50)
{
Console.WriteLine("获得护甲" + FY1.MingZi);
JS1.HuJiaZhi += FY1.HuJiaZhi;
}
else if (HQFangYu <= 80)
{
Console.WriteLine("获得护甲" + FY2.MingZi);
JS1.HuJiaZhi += FY2.HuJiaZhi;
}
else
{
Console.WriteLine("获得护甲" + FY3.MingZi);
JS1.HuJiaZhi += FY3.HuJiaZhi;
}
Console.WriteLine("第一个角色,攻击力" + JS1.GongJi + ",生命值" + JS1.ShengMing +"护甲"+JS1.HuJiaZhi); //输出角色的基本属性 新建角色完成
JueSe JS2 = new JueSe();//同上
Console.Write("请输入第二个角色的姓名:");
JS2.XingMing = Console.ReadLine();
JS2.GongJi = SuiJi.Next(80, 120); ;
JS2.ShengMing = SuiJi.Next(8000, 12000);
JS2.HuJiaZhi = 0;
Random HQSuiJi1 = new Random(); // 创建随机数
int HuoDewuqi1 = HQSuiJi.Next(0, 101);
if (HuoDewuqi1 <= 30)
{
Console.WriteLine("获得武器" + wq1.MingCheng);
JS2.GongJi += wq1.GongJiLi;
}
else if (HuoDewuqi1 <= 70)
{
Console.WriteLine("获得武器" + wq2.MingCheng);
JS2.GongJi += wq2.GongJiLi;
}
else if (HuoDewuqi1 <= 80)
{
Console.WriteLine("获得武器" + wq1.MingCheng);
JS2.GongJi += wq3.GongJiLi;
}
else
{
Console.WriteLine("获得武器" + wq1.MingCheng);
JS2.GongJi += wq4.GongJiLi;
}
Random FangYu1 = new Random(); // 创建护甲随机数
int HQFangYu1 = HQSuiJi.Next(0, 101); //创建获取护甲的几率
if (HQFangYu1 <= 50)
{
Console.WriteLine("获得护甲" + FY1.MingZi);
JS2.HuJiaZhi += FY1.HuJiaZhi;
}
else if (HQFangYu1 <= 80)
{
Console.WriteLine("获得护甲" + FY2.MingZi);
JS2.HuJiaZhi += FY2.HuJiaZhi;
}
else
{
Console.WriteLine("获得护甲" + FY3.MingZi);
JS2.HuJiaZhi += FY3.HuJiaZhi;
}
Console.WriteLine("第一个角色,攻击力" + JS2.GongJi + ",生命值" + JS2.ShengMing+"护甲" + JS2.HuJiaZhi);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("点击任意键开始");
Console.ReadKey();
#endregion
#region 技能生成
ArrayList JiNengMen = new ArrayList(); //新建放技能的集合 只能放一个
JiNeng jn1 = new JiNeng(); //新建技能1
jn1.JiNengMingCheng = "大招";
jn1.JiNengShangHai = 4;
JiNeng jn2 = new JiNeng();
jn2.JiNengMingCheng = "中招";
jn2.JiNengShangHai = 3;
JiNeng jn3 = new JiNeng();
jn3.JiNengMingCheng = "小招";
jn3.JiNengShangHai = 2;
JiNengMen.Add(jn1); //集合
JiNengMen.Add(jn2);
JiNengMen.Add(jn3);
#endregion
#region 对战部分
Console.ForegroundColor = ConsoleColor.White; //改变前景颜色
while (true)
{
Random fudong = new Random(); // 创建浮动攻击随机数
int fudonggongji = fudong.Next(0,30);
Random JNjilv = new Random(); //创建角色1使用技能几率
int JNfadongjilv = fudong.Next(1, 11);
Random JNjilv2 = new Random(); //创建角色2使用技能几率
int JNfadongjilv2 = fudong.Next(1, 11);
#region 角色1攻击
if (JNfadongjilv <= 3) //<=3时使用技能
{
Console.ForegroundColor = ConsoleColor.Yellow; //设置下一条内容的颜色
JiNeng jn = (JiNeng)JiNengMen[fudong.Next(0, 3)]; //设置使用哪一个技能
int shanghai11 = Convert.ToInt32(JS1.GongJi - fudonggongji) * jn.JiNengShangHai; //设置伤害 = 角色攻击加浮动值成技能伤害
JS2.ShengMing = JS2.ShengMing - (shanghai11-JS2.HuJiaZhi); //设置剩余生命值=初始生命-(伤害-护甲)
Console.WriteLine(JS1.XingMing+"发动技能"+jn.JiNengMingCheng + "对" + JS2.XingMing + "造成了" + shanghai11 + "点伤害-"+ JS2.HuJiaZhi+"护甲值"+ JS2.XingMing + "剩余" + JS2.ShengMing + "血量");
}
else
{
Console.ForegroundColor = ConsoleColor.White; //颜色
int shanghai1 = JS1.GongJi - fudonggongji; //伤害
JS2.ShengMing = JS2.ShengMing - shanghai1; //生命
Console.WriteLine(JS1.XingMing + "对" + JS2.XingMing + "造成了" + shanghai1 + "点伤害-" + JS2.HuJiaZhi + "护甲值" + JS2.XingMing + "剩余" + JS2.ShengMing + "血量");
System.Threading.Thread.Sleep(500); //延迟500毫秒进行下一步
}
#endregion
#region 角色2攻击
if (JNfadongjilv2 <= 3)
{
Console.ForegroundColor = ConsoleColor.Yellow;
JiNeng jn = (JiNeng)JiNengMen[fudong.Next(0, 3)];
int shanghai11 = Convert.ToInt32(JS2.GongJi - fudonggongji) * jn.JiNengShangHai;
JS1.ShengMing = JS1.ShengMing - shanghai11;
Console.WriteLine(JS2.XingMing + "发动技能" + jn.JiNengMingCheng + "对" + JS1.XingMing + "造成了" + shanghai11 + "点伤害-" + JS1.HuJiaZhi + "护甲值" + JS1.XingMing + "剩余" + JS1.ShengMing + "血量");
}
else
{
Console.ForegroundColor = ConsoleColor.White;
int shanghai1 = JS2.GongJi - fudonggongji;
JS1.ShengMing = JS1.ShengMing - shanghai1;
Console.WriteLine(JS2.XingMing + "对" + JS1.XingMing + "造成了" + shanghai1 + "点伤害-" + JS1.HuJiaZhi + "护甲值" + JS1.XingMing + "剩余" + JS1.ShengMing + "血量");
System.Threading.Thread.Sleep(500);
}
#endregion
#region 判断胜负
if (JS1.ShengMing <= 0 || JS2.ShengMing <= 0) // 判断生命为0时
{
if (JS1.ShengMing <= 0 && JS2.ShengMing <= 0) //判断角色几生命为0
{
Console.WriteLine("二位同归于尽了!!!");
}
else
{
if (JS1.ShengMing <= 1)
{
Console.WriteLine(JS2.XingMing + "获得了最终胜利!!!");
}
else
{
Console.WriteLine(JS1.XingMing + "获得了最终胜利!!!");
}
}
break;
}
#endregion
}
#endregion
}
}
}
转载于:https://www.cnblogs.com/buzhiheyan/p/7808110.html