练习——对战游戏

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 对战
{
    class Program
    {
        static void Main(string[] args)
        {
            role rol1 = new role();
            role rol2 = new role();
            skill s1 = new skill();
            skill s2 = new skill();
            skill s3 = new skill();
            skill s4 = new skill();
            Random ran= new Random();
            Console.WriteLine("1、格罗姆  2、吉安娜  3、乌瑟尔  4、安度因");
            int r1 = 0;
            int r2 = 0;
            for (; ; )//选择角色
            {
                try
                {
                    Console.Write("请选择第一个角色(输入序号):");
                    int rr1 = int.Parse(Console.ReadLine());
                    if (rr1 >= 1 && rr1 <= 4)
                    {
                        r1 = rr1;
                    }
                    else
                    {
                        Console.WriteLine("请从以上四个角色之中选择!");
                        continue;
                    }
                    Console.Write("请选择第二个角色(输入序号):");
                    int rr2 = int.Parse(Console.ReadLine());
                    if (rr2 >= 1 && rr2 <= 4)
                    {
                        r2 = rr2;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("请从以上四个角色之中选择!");
                        continue;
                    }
                }
                catch
                {
                    Console.WriteLine("操作有误,请正确输入角色序号!");
                    continue;
                }
            }
            //录入第一个角色信息
            if(r1==1)
            {
                rol1.Name = "格罗姆";
                rol1.Blood = 3000;
                rol1.Str = 100;
                s1.Name = "冲锋";
                s1.Str = 200;
                rol1.Smlski = s1;
                s2.Name = "风车";
                s2.Str = 500;
                rol1.Bigski = s2;
            }
            else if (r1 == 2)
            {
                rol1.Name = "吉安娜";
                rol1.Blood = 1500;
                rol1.Str = 200;
                s1.Name = "火球术";
                s1.Str = 400;
                rol1.Smlski = s1;
                s2.Name = "暴风雪";
                s2.Str = 1000;
                rol1.Bigski = s2;
            }
            else if (r1 == 3)
            {
                rol1.Name = "乌瑟尔";
                rol1.Blood = 2500;
                rol1.Str = 90;
                s1.Name = "圣光术";
                s1.Str = 300;
                rol1.Smlski = s1;
                s2.Name = "圣疗术";
                s2.Str = -600;
                rol1.Bigski = s2;
            }
            else
            {
                rol1.Name = "安度因";
                rol1.Blood = 2000;
                rol1.Str = 80;
                s1.Name = "治疗术";
                s1.Str = -200;
                rol1.Smlski = s1;
                s2.Name = "医疗波";
                s2.Str = -800;
                rol1.Bigski = s2;
            }
            //录入第二个角色信息
            if (r2 == 1)
            {
                rol2.Name = "格罗姆";
                rol2.Blood = 3000;
                rol2.Str = 100;
                s3.Name = "冲锋";
                s3.Str = 200;
                rol2.Smlski = s3;
                s4.Name = "风车";
                s4.Str = 500;
                rol2.Bigski = s4;
            }
            else if (r2 == 2)
            {
                rol2.Name = "吉安娜";
                rol2.Blood = 1500;
                rol2.Str = 200;
                s3.Name = "火球术";
                s3.Str = 400;
                rol2.Smlski = s3;
                s4.Name = "暴风雪";
                s4.Str = 1000;
                rol2.Bigski = s4;
            }
            else if (r2 == 3)
            {
                rol2.Name = "乌瑟尔";
                rol2.Blood = 2500;
                rol2.Str = 90;
                s3.Name = "圣光术";
                s3.Str = 300;
                rol2.Smlski = s3;
                s4.Name = "圣疗术";
                s4.Str = -600;
                rol2.Bigski = s4;
            }
            else
            {
                rol2.Name = "安度因";
                rol2.Blood = 2000;
                rol2.Str = 80;
                s3.Name = "治疗术";
                s3.Str = -200;
                rol2.Smlski = s3;
                s4.Name = "医疗波";
                s4.Str = -800;
                rol2.Bigski = s4;
            }
            if(rol1.Name==rol2.Name)
            {
                rol1.Name = rol1.Name + "1";
                rol2.Name = rol2.Name + "2";
            }
            Console.WriteLine("==========================================================");
            Console.WriteLine("角色"+"\t"+"生命值"+"\t"+"攻击力"+"\t"+"技能1"+"\t"+"技能2");
            Console.WriteLine(rol1.Name + "\t" + rol1.Blood + "\t" + rol1.Str + "\t" + rol1.Smlski.Name + "\t" + rol1.Bigski.Name);
            Console.WriteLine(rol2.Name + "\t" + rol2.Blood + "\t" + rol2.Str + "\t" + rol2.Smlski.Name + "\t" + rol2.Bigski.Name);
            Console.WriteLine("选择完毕,请按任意键开始战斗!");
            Console.ReadKey();
            //开始战斗
            for (; ; )
            {
                //默认角色1先手攻击
                int ran1 = ran.Next(1, 101);//判断是否释放技能
                if(ran1<=5)//释放大技能
                {
                    int bigstr=0;//记录大技能数值
                    //判断是否是治疗技能
                    if (rol1.Bigski.Str > 0)
                    {
                        bigstr = ran.Next(((rol1.Bigski.Str) / 10) * 8, ((rol1.Bigski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol1.Name, rol1.Bigski.Name, rol2.Name, bigstr, rol2.Name, (rol2.Blood - bigstr));
                        rol2.Blood -= bigstr;
                    }
                    else
                    {
                        bigstr = ran.Next((Math.Abs(rol1.Bigski.Str) / 10) * 8, (Math.Abs(rol1.Bigski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol1.Name, rol1.Bigski.Name, bigstr, rol1.Name, (rol1.Blood + bigstr));
                        rol1.Blood += bigstr;
                    }
                }
                else if (ran1<= 20)//释放小技能
                {
                    int smlstr = 0;
                    if (rol1.Smlski.Str > 0)
                    {
                        smlstr = ran.Next(((rol1.Smlski.Str) / 10) * 8, ((rol1.Smlski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆{1}☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol1.Name, rol1.Smlski.Name, rol2.Name, smlstr, rol2.Name, (rol2.Blood - smlstr));
                        rol2.Blood -= smlstr;
                    }
                    else
                    {
                        smlstr = ran.Next((Math.Abs(rol1.Smlski.Str) / 10) * 8, (Math.Abs(rol1.Smlski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆{1}☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol1.Name, rol1.Smlski.Name, smlstr, rol1.Name, (rol1.Blood + smlstr));
                        rol1.Blood += smlstr;
                    }
                }
                else//不释放技能,普通攻击
                {
                    int str = ran.Next(((rol1.Str) / 10) * 8, ((rol1.Str) / 10) * 12);
                    Console.WriteLine("【{0}】攻击了【{1}】,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}",rol1.Name,rol2.Name,rol2.Name,str,rol2.Name,(rol2.Blood-str));
                    rol2.Blood -= str;
                }
                Console.WriteLine();
                if(rol2.Blood<=0)//判断是否阵亡
                {
                    Console.WriteLine("【{0}】阵亡,【{1}】获得了胜利。",rol2.Name,rol1.Name);
                    break;
                }
                System.Threading.Thread.Sleep(1500);

                //角色2进行攻击
                int ran2 = ran.Next(1, 101);
                if (ran2 <= 5)
                {
                    int bigstr = 0;
                    if (rol2.Bigski.Str > 0)
                    {
                        bigstr = ran.Next(((rol2.Bigski.Str) / 10) * 8, ((rol2.Bigski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol2.Name, rol2.Bigski.Name, rol1.Name, bigstr, rol1.Name, (rol1.Blood - bigstr));
                        rol1.Blood -= bigstr;
                    }
                    else
                    {
                        bigstr = ran.Next((Math.Abs(rol2.Bigski.Str) / 10) * 8, (Math.Abs(rol2.Bigski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol2.Name, rol2.Bigski.Name, bigstr, rol2.Name, (rol2.Blood + bigstr));
                        rol2.Blood += bigstr;
                    }
                }
                else if (ran2 <= 20)
                {
                    int smlstr = 0;
                    if (rol2.Smlski.Str > 0)
                    {
                        smlstr = ran.Next(((rol2.Smlski.Str) / 10) * 8, ((rol2.Smlski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆{1}☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol2.Name, rol2.Smlski.Name, rol1.Name, smlstr, rol1.Name, (rol1.Blood - smlstr));
                        rol1.Blood -= smlstr;
                    }
                    else
                    {
                        smlstr = ran.Next((Math.Abs(rol2.Smlski.Str) / 10) * 8, (Math.Abs(rol2.Smlski.Str) / 10) * 12);
                        Console.WriteLine("【{0}】释放了☆{1}☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol2.Name, rol2.Smlski.Name, smlstr, rol2.Name, (rol2.Blood + smlstr));
                        rol2.Blood += smlstr;
                    }
                }
                else
                {
                    int str = ran.Next(((rol2.Str) / 10) * 8, ((rol2.Str) / 10) * 12);
                    Console.WriteLine("【{0}】攻击了【{1}】,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol2.Name, rol1.Name, rol1.Name, str, rol1.Name, (rol1.Blood - str));
                    rol1.Blood -= str;
                }
                Console.WriteLine();
                if (rol1.Blood <= 0)
                {
                    Console.WriteLine("【{0}】阵亡,【{1}】获得了胜利。", rol1.Name, rol2.Name);
                    break;
                }
                System.Threading.Thread.Sleep(1500);
            }

            Console.ReadKey();
        }
    }
}

时间: 2024-10-28 15:50:52

练习——对战游戏的相关文章

模拟德州扑克对战游戏

================================================================ 注意:本文参考"巧妙的Python数据结构玩法|实战德州扑克"的相关内容,并在此基础之上完成模拟扑克对战游戏. 原文网址:http://mp.weixin.qq.com/s/JQ0zJGf7Tz49Xn78x7Z40g ================================================================ 我们写了两

对战游戏

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); Soldier s1 = new Soldier(); Console.Write(

封装练习 对战游戏

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); //战士,名字,生命值,攻击力,招式 Soldier s1 = new Soldier(); Console.Write("请输入第一个战士的姓

结构体、枚举类型及其练习题,最后的对战游戏(基础版)

结构体:在内存中临时存储数据的方式1.变量.常量2.数组,可以存储固定长度统一类型的数据3.集合4.结构体 学生信息:姓名,性别,年龄,系别 结构体含义:就是将生活中的一些个体,封装成一个特殊的类型 结构体是:用户自定义数据类型 创建:创建的位置:main函数之外struct Student{ public int Code; public string Name; public string Sex; public int Old; public DateTime Birthday;} 定义:

第十二天学习内容 综合应用 推箱子和对战游戏

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace day12{    class Program    {        static void Main(string[] args)        { //推箱子游戏            int x = 1, y = 1, i = 0;        

对战游戏1.0

//主函数using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 作业_对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); //战士,名字,生命值,攻击力,招式,闪躲 Soldier S1 = new Soldier(); Console.Write(

ADO.NET 扩展属性、配置文件 和 对战游戏

扩展属性 有外键关系时将信息处理成用户可看懂的 利用扩展属性 如:Info表中的民族列显示的是民族代号处理成Nation表中的民族名称 需要在Info类里面扩展一个显示nation名称的属性 例:先前在NationDA里面已经下好了一个代号换成名称的方法 public class Info { //扩展的名族名称属性 public string NationName { get { NationDA da = new NationDA(); return da.NationName(this.n

函数 及对战游戏

//对战游戏 struct duizhan { public string name; public int  xue; public int  gongji; public int  fangyu; public int  mingzhong; public int  shengfa; } static void Main(string[] args) { duizhan[] a = new duizhan[5];//定义结构体,并建立数组 int i = 0; for (; i < 5;i+

【经典】C++&amp;RPG对战游戏

博文背景: 还记大二上学期的时候看的这个C++&RPG游戏(博主大一下学期自学的php,涵盖oop内容),一个外校的同学他们大一学的C++,大二初期C++实训要求做一个程序填空,就是这个 RPG 对战游戏,有几处空需要填上,问我可以不,我就信誓旦旦的说OK,最后“万般无奈多方考究”才给将程序补充完整.最近在做毕业设计,用到C++&QT oop部分,重新温习了下C++ oop,就想起来大二的时候还“捣鼓”过这么个游戏,现重新看了下,进行整理总结,写下该博文. ----------------

VS 游戏:推箱子&amp;对战游戏

推箱子 //只做了两关 class Program { static void Main(string[] args) { int x = 1; int y = 8; int z = 0; int end1x = 6; int end1y = 3; int end2x = 6; int end2y = 3; #region 地图绘制 string[,,] map = new string[3, 10, 10] { { {"●", "●", "●"