看看我这个代码,你有能借鉴的地方没- using System;
- namespace Game
- {
- class Program
- {
- static void Main(string[] args)
- {
- Hero h = new Hero();
- bool bselect;
- do
- {
- bselect = false;
- Console.WriteLine("请选择职业:1.法师 2.战士");
- string sinputhero = Console.ReadLine();
- switch(sinputhero)
- {
- case "1":
- h = (Mage)new Mage();
- break;
- case "2":
- h = (Warrior)new Warrior();
- break;
- default:
- Console.WriteLine("输入错误,请重新输入!");
- bselect = true;
- break;
- }
- }while(bselect);
- //报告
- Console.WriteLine("角色创建成功!");
- while(h.hp>0)
- {
- Console.WriteLine("你现在想做什么?1.打怪 2.休息 3.属性报告");
- string sinputhero = Console.ReadLine();
- switch(sinputhero)
- {
- case "1":
- //h.Fight(); 自动匹配同等级的怪物
- Random r = new Random();
- int ir = r.Next(h.level-2,h.level+3);
- h.Fight(new Boss(ir));
-
- break;
- case "2":
- h.hp+=20;
- break;
- case "3":
- h.Showme();
- break;
- default:
- Console.WriteLine("输入错误,请重新输入!");
- bselect = true;
- break;
- }
- }
- Console.WriteLine("你的角色已死亡,游戏结束!");
- //PK();
- //Raid();
- //m.Showme();
- //w.Showme();
- Console.ReadKey();
- }
- }
-
- //定义一个Boss类
- class Boss
- {
- public int hp;
- public int ap;
- public int level;
- public Boss(int level)
- {
- this.ap = 2*level;
- this.hp = 50*level;
- this.level = level;
- }
- }
- //定义一个英雄类,英雄类有一个PK()和一个Raid() PK(Hero h1,Hero h2) Raid(Hero h,Boss b)
- class Hero
- {
- public virtual void Fight(Boss b)
- {
- }
- public virtual void Showme()
- {
- Console.WriteLine("属性:");
- Console.WriteLine("等级:{0}",this.level);
- Console.WriteLine("当前经验/升级经验:{0}/{1}",this.exp,this.maxexp);
- Console.WriteLine("生命值:{0}",this.hp);
- Console.WriteLine("攻击强度:{0}",this.ap);
- Console.WriteLine("护甲值:{0}",this.hujia);
- }
- //等级
- public int level = 1;
- //最大经验值
- protected int maxexp = 100;
- //当前经验值
- protected int exp = 0;
- //攻击强度 生命值 护甲值
- protected int ap = 10;
- public int hp = 100;
- protected int hujia = 1;
- //升级的动作
- protected virtual void Levelup()
- {
- this.level++;
- this.maxexp = 100 * level;
- this.ap += 10;
- this.hp += 100;
- this.hujia++;
- }
- //升级的动作用于调试
- public void Levelup(int i1)
- {
- for(int i=0;i<i1;i++)
- {
- this.Levelup();
- }
- }
-
- //获取经验
- public void Getexp(int i)
- {
- if(i>=this.maxexp)
- {
- Console.WriteLine("经验值太多,无法吸收");
- }
- else
- {
- this.exp += i;
- while(this.exp>=this.maxexp)
- {
- this.exp -= this.maxexp;
- this.Levelup();
- }
- }
- }
- }
- //定义两个类继承英雄:法师、战士
- class Mage:Hero
- {
- public override void Fight(Boss b)
- {
- int itemp = 0;
- while(this.hp>0 && b.hp>0)
- {
- itemp++;
- Console.WriteLine("第{0}战斗回合:",itemp);
- this.hp -= b.ap;
- b.hp -= this.fp;
- }
- if(this.hp>=0)
- {
- Console.WriteLine("Exp++!!!!!!!!!!!");
- this.Getexp(20);
- }
- }
- protected int fp = 10;
- protected int mp = 100;
- public override void Showme()
- {
- Console.WriteLine("属性:");
- Console.WriteLine("等级:{0}",this.level);
- Console.WriteLine("当前经验/升级经验:{0}/{1}",this.exp,this.maxexp);
- Console.WriteLine("生命值:{0}",this.hp);
- Console.WriteLine("魔法值:{0}",this.mp);
- Console.WriteLine("攻击强度:{0}",this.ap);
- Console.WriteLine("法术强度:{0}",this.fp);
- Console.WriteLine("护甲值:{0}",this.hujia);
- }
- protected override void Levelup()
- {
- this.level++;
- this.maxexp = 100 * level;
- this.ap += 6;
- this.hp += 80;
- this.hujia ++;
- }
- }
- class Warrior:Hero
- {
- public override void Fight(Boss b)
- {
- int itemp = 0;
- while(this.hp>0 && b.hp>0)
- {
- itemp++;
- Console.WriteLine("第{0}战斗回合:",itemp);
- this.hp -= b.ap;
- b.hp -= this.ap;
- }
- if(this.hp>=0)
- {
- this.Getexp(20);
- }
- }
- protected override void Levelup()
- {
- this.level++;
- this.maxexp = 100 * level;
- this.ap += 12;
- this.hp += 120;
- this.hujia +=2;
- }
- }
- }
复制代码 |