static void Main(string[] args) { Monster m1 = new Monster("小怪", 30); Monster m3 = new Monster("中怪", 50); Monster m4 = new Monster("Boss", 1000); Roles role = new Roles(); role.Weapon = WeaponType.WoodenSword; RolesServices rs = new RolesServices(role); rs.AttackMonster(m1); rs.AttackMonster(m1); rs.AttackMonster(m1); role.Weapon = WeaponType.IconSword; rs.AttackMonster(m3); rs.AttackMonster(m3); rs.AttackMonster(m3); role.Weapon = WeaponType.MagicSword; rs.AttackMonster(m4); rs.AttackMonster(m4); rs.AttackMonster(m4); rs.AttackMonster(m4); rs.AttackMonster(m4); Console.ReadKey(); }
public void AttackMonster(Monster model) { //Output(model.Name, model.HP); //Console.WriteLine("开始攻击"); if (model.HP <= 0) { Console.WriteLine("怪物" + model.Name + "已死亡"); return; } switch (roles.Weapon) { case WeaponType.WoodenSword: { model.HP -= 20; Output(model.Name, 20); break; } case WeaponType.IconSword: { model.HP -= 30; Output(model.Name, 30); break; } case WeaponType.MagicSword: { int loss = _random.NextDouble() < 0.5 ? 100 : 200; model.HP -= loss; if (200 == loss) { Console.WriteLine("出现暴击"); } Output(model.Name, loss); break; } default: break; } if (model.HP <= 0) { Console.WriteLine("怪物" + model.Name + "已死亡"); return; } }