zoukankan      html  css  js  c++  java
  • 对战游戏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("请输入第一个战士的名字:"); S1.Name = Console.ReadLine(); S1.Blood = r.Next(2000,3001); int s1startblood = S1.Blood; S1.Attack = r.Next(50,101); Movements SM1 = new Movements(); Console.Write("请输入小招的名字:"); SM1.Name = Console.ReadLine(); SM1.Attack = r.Next(200,301); S1.Smallmove = SM1; Movements BM1 = new Movements(); Console.Write("请输入大招的名字:"); BM1.Name = Console.ReadLine(); BM1.Attack = r.Next(300, 401); S1.Smallmove = BM1; S1.Dodge = r.Next(0,50); S1.Restor = r.Next(100,301); Soldier S2 = new Soldier(); Console.Write("请输入第二个战士的名字:"); S2.Name = Console.ReadLine(); S2.Blood = r.Next(2000, 3001); int s2startblood = S2.Blood; S2.Attack = r.Next(50, 101); Movements SM2 = new Movements(); Console.Write("请输入小招的名字:"); SM2.Name = Console.ReadLine(); SM2.Attack = r.Next(200, 301); S2.Smallmove = SM2; Movements BM2= new Movements(); Console.Write("请输入大招的名字:"); BM2.Name = Console.ReadLine(); BM2.Attack = r.Next(300, 401); S2.Smallmove = BM2; S2.Dodge = r.Next(0, 50); S2.Restor = r.Next(100, 301); Console.Clear(); Console.WriteLine("=======================战士信息展示======================="); Console.WriteLine("名字 生命值 攻击力 小招 小招攻击力 大招 大招攻击力 闪躲 恢复值"); Console.WriteLine(S1.Name + " " + S1.Blood + " " + S1.Attack + " " + SM1.Name + " " + SM1.Attack + " " + BM1.Name + " " + BM1.Attack + " " + S1.Dodge + " " + S1.Restor); Console.WriteLine(S2.Name + " " + S2.Blood + " " + S2.Attack + " " + SM2.Name + " " + SM2.Attack + " " + BM2.Name + " " + BM2.Attack + " " + S2.Dodge + " " + S2.Restor); Console.ReadKey(); //开始战斗,不死不休 int whostart = r.Next(1,3); //战士一先开始攻击 if (whostart == 1) { int count = 1; while (true) { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("=======================第"+count+"回合======================="); //战士一开始攻击 System.Threading.Thread.Sleep(2000); //闪躲 if (r.Next(0, 101) < S1.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S2.Name + "躲掉了" + S1.Name + "的攻击!"); } else { //发大招 if(r.Next(1,101)>95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S1.Name + "" + S2.Name + "发出了卐卐卐卐卐" + BM1.Name + "卐卐卐卐卐,攻击力为" + BM1.Attack + "" + S2.Name + "剩余生命值" + (S2.Blood - BM1.Attack) + "!"); S2.Blood -= BM1.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S1.Name + "" + S2.Name + "发出了卐卐" + SM1.Name + "卐卐,攻击力为" + SM1.Attack + "" + S2.Name + "剩余生命值" + (S2.Blood - SM1.Attack) + "!"); S2.Blood -= SM1.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S1.Name + "" + S2.Name + "发出了普通攻击,攻击力为" + S1.Attack + "" + S2.Name + "剩余生命值" + (S2.Blood - S1.Attack) + "!"); S2.Blood -= S1.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if(S2.Blood<=0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S1.Name + "获胜," + S2.Name + "阵亡!"); break; } } //战士二开始攻击 System.Threading.Thread.Sleep(2000); //闪躲 Console.ForegroundColor = ConsoleColor.Black; if (r.Next(0, 101) < S2.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S1.Name + "躲掉了" + S2.Name + "的攻击!"); } else { //发大招 if(r.Next(1,101)>95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S2.Name + "" + S1.Name + "发出了卐卐卐卐卐" + BM2.Name + "卐卐卐卐卐,攻击力为" + BM2.Attack + "" + S1.Name + "剩余生命值" + (S1.Blood - BM2.Attack) + "!"); S1.Blood -= BM2.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S2.Name + "" + S2.Name + "发出了卐卐" + SM2.Name + "卐卐,攻击力为" + SM2.Attack + "" + S1.Name + "剩余生命值" + (S1.Blood - SM2.Attack) + "!"); S1.Blood -= SM2.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S2.Name + "" + S1.Name + "发出了普通攻击,攻击力为" + S2.Attack + "" + S1.Name + "剩余生命值" + (S1.Blood - S2.Attack) + "!"); S1.Blood -= S2.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if(S1.Blood<=0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S2.Name + "获胜," + S1.Name + "阵亡!"); break; } } if (S1.Blood > 0 && S2.Blood > 0) { if (r.Next(1, 11) == 1) { S1.Blood += S1.Restor; if (S1.Blood > s1startblood) { S1.Blood = s1startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S1.Name + "拣到仙豆,生命值恢复到:" + S1.Blood); } if (r.Next(1, 11) == 2) { S2.Blood += S2.Restor; if (S2.Blood > s2startblood) { S2.Blood = s2startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S2.Name + "拣到仙豆,生命值恢复到:" + S2.Blood); } } count++; } } //战士二先开始攻击 else { int count = 1; while (true) { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("=======================第"+count+"回合======================="); //战士二开始攻击 System.Threading.Thread.Sleep(2000); //闪躲 if (r.Next(0, 101) < S2.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S1.Name + "躲掉了" + S2.Name + "的攻击!"); } else { //发大招 if (r.Next(1, 101) > 95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S2.Name + "" + S1.Name + "发出了卐卐卐卐卐" + BM2.Name + "卐卐卐卐卐,攻击力为" + BM2.Attack + "" + S1.Name + "剩余生命值" + (S1.Blood - BM2.Attack) + "!"); S1.Blood -= BM2.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S2.Name + "" + S2.Name + "发出了卐卐" + SM2.Name + "卐卐,攻击力为" + SM2.Attack + "" + S1.Name + "剩余生命值" + (S1.Blood - SM2.Attack) + "!"); S1.Blood -= SM2.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S2.Name + "" + S1.Name + "发出了普通攻击,攻击力为" + S2.Attack + "" + S1.Name + "剩余生命值" + (S1.Blood - S2.Attack) + "!"); S1.Blood -= S2.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if (S1.Blood <= 0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S2.Name + "获胜," + S1.Name + "阵亡!"); break; } } //战士一开始攻击 System.Threading.Thread.Sleep(2000); Console.ForegroundColor = ConsoleColor.Black; //闪躲 if (r.Next(0, 101) < S1.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S2.Name + "躲掉了" + S1.Name + "的攻击!"); } else { //发大招 if (r.Next(1, 101) > 95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S1.Name + "" + S2.Name + "发出了卐卐卐卐卐" + BM1.Name + "卐卐卐卐卐,攻击力为" + BM1.Attack + "" + S2.Name + "剩余生命值" + (S2.Blood - BM1.Attack) + "!"); S2.Blood -= BM1.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S1.Name + "" + S2.Name + "发出了卐卐" + SM1.Name + "卐卐,攻击力为" + SM1.Attack + "" + S2.Name + "剩余生命值" + (S2.Blood - SM1.Attack) + "!"); S2.Blood -= SM1.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S1.Name + "" + S2.Name + "发出了普通攻击,攻击力为" + S1.Attack + "" + S2.Name + "剩余生命值" + (S2.Blood - S1.Attack) + "!"); S2.Blood -= S1.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if (S2.Blood <= 0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S1.Name + "获胜," + S2.Name + "阵亡!"); break; } } if(S1.Blood>0&&S2.Blood>0) { if(r.Next(1,11)==1) { S1.Blood += S1.Restor; if(S1.Blood>s1startblood) { S1.Blood = s1startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S1.Name+"拣到仙豆,生命值恢复到:"+S1.Blood); } if (r.Next(1, 11) == 2) { S2.Blood += S2.Restor; if (S2.Blood > s2startblood) { S2.Blood = s2startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S2.Name + "拣到仙豆,生命值恢复到:" + S2.Blood); } } count++; } } Console.ReadKey(); } } }
    //Soldier类
    using
    System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 作业_对战游戏 { public class Soldier { //名字,生命值,攻击力,招式,闪躲,恢复 private string _name; /// <summary> /// 战士姓名 /// </summary> public string Name { get { return _name; } set { _name = value; } } private int _blood; /// <summary> /// 战士生命值 /// </summary> public int Blood { get { return _blood; } set { _blood = value; } } private int _attack; /// <summary> /// 战士攻击力 /// </summary> public int Attack { get { return _attack; } set { _attack = value; } } private Movements _smallmove; /// <summary> /// 战士招式:小招 /// </summary> public Movements Smallmove { get { return _smallmove; } set { _smallmove = value; } } private Movements _bigmove; /// <summary> /// 战士招式:大招 /// </summary> public Movements Bigmove { get { return _bigmove; } set { _bigmove = value; } } private int _dodge; /// <summary> /// 战士闪躲攻击值 /// </summary> public int Dodge { get { return _dodge; } set { _dodge = value; } } private int _restor; /// <summary> /// 战士生命恢复值 /// </summary> public int Restor { get { return _restor; } set { _restor = value; } } } }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 作业_对战游戏
    {
        public class Movements
        {
            private string _name;
            /// <summary>
            /// 招式名字
            /// </summary>
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            private int _attack;
            /// <summary>
            /// 招式攻击力
            /// </summary>
            public int Attack
            {
                get { return _attack; }
                set { _attack = value; }
            }
            
        }
    }

  • 相关阅读:
    电梯设计需求调研报告
    返回一个整数数组中最大子数组的和。
    返回一个整数数组中最大子数组的和
    四则运算2程序及运行结果
    四则运算2
    上半学期读软件工程方面著作的读书计划
    写输出30道小学生四则运算程序的解题思路及未在规定时间内完成程序的原因
    《人月神话》读后感
    阅读《软件工程—理论方法与实践》第十一章心得体会
    java常见排序方法
  • 原文地址:https://www.cnblogs.com/maxin991025-/p/6106685.html
Copyright © 2011-2022 走看看