C#Lesson06Homework

using System;


namespace Lesson06Homework
{
class MainClass
{
public static void Main (string[] args)
{
Weapon w1 = new Weapon ();
Weapon w2 = new Weapon ();
Weapon w3 = new Weapon ();
Weapon w4 = new Weapon ();
Weapon w5 = new Weapon ();
Weapon w6 = new Weapon ();
w1.Init ("超大陆", 20, 400, 400, 500, WeaponType.防御);
w2.Init ("深渊恶魔", 20,500, 500, 100, WeaponType.防御);
w3.Init ("恍惚", 100, 350, 350, 400, WeaponType.首饰);
w4.Init ("三神器", 40, 300, 300, 100, WeaponType.首饰);
w5.Init ("圣耀救赎太刀", 300, 100, 100, 300, WeaponType.攻击);
w6.Init ("妖刀村正+10", 450, 100, 100, 200, WeaponType.攻击);
Hero h1 = new Hero ();
Hero h2 = new Hero ();
Hero h3 = new Hero ();
Hero h4 = new Hero ();
Hero h5 = new Hero ();
Hero h6 = new Hero ();
h1.Init (500, 100, "大暗黑天", 100, 50, 0);
h2.Init (500, 100, "剑魂", 100, 50, 0);
h3.Init (500, 100, "极武皇", 100, 50, 0);
h1.WearableEquipment (w6);
h2.WearableEquipment (w5);
h1.WearableEquipment (w2);
h1.WearableEquipment (w4);
h2.WearableEquipment (w1);
h3.WearableEquipment (w3);
Random ran = new Random ();
bool f = true;
while (f == true) {
int rand = ran.Next (1, 6);
switch (rand) {
case 1:
{
h1.Attack (h2);}
break;
case 2:
{
h1.Attack (h3);}
break;
case 3:
{
h2.Attack (h1);}
break;
case 4:
{
h2.Attack (h3);}
break;
case 5:
{
h3.Attack (h1);}
break;
case 6:
{
h3.Attack (h2);}
break;
}
if (h1.hp <= 0 && h2.hp <= 0) {
f = false;
Console.WriteLine ("幸存者为{0}",h3.name);
}else if(h1.hp <= 0 && h3.hp<= 0){
f = false;
Console.WriteLine ("幸存者为{0}",h2.name);
}else if(h2.hp <= 0 && h3.hp <= 0){
f = false;
Console.WriteLine ("幸存者为{0}",h1.name);
}


}
}
}

}

------------------------------------------------------------------------------------------------------------------

using System;


namespace Lesson06Homework
{
public enum WeaponType
{
攻击,
防御,
法术,
移动,
打野,
首饰
}
public class Weapon
{
public string name;
public int addATK;
public int addHp;
public int addDefense;
public int addSpeed;
public WeaponType type;


public void Init(string name,int atk,int ahp,int adf,int asp,WeaponType tp){
this.name = name;
addATK = atk;
addHp = ahp;
addDefense = adf;
addSpeed = asp;
type = tp;
}
}
}

--------------------------------------------------------------------------------------------------------------------------

using System;


namespace Lesson06Homework
{
public class Hero
{
public int hp;
int ATK;
public string name;
int defense;
int speed;
int grade;


public void Init(int hp,int ATK, string name, int defense,int speed,int grade){
this.hp = hp;
this.ATK = ATK + 100 * grade;
this.name = name;
this.defense = defense;
this.speed = speed;
this.grade = grade;
}


public void WearableEquipment(Weapon w){
this.hp += w.addHp;
this.ATK += w.addATK;
this.defense += w.addDefense;
this.speed += w.addSpeed;
Console.WriteLine ("你穿戴了{0}装备,获得了属性值提升",w.name);
}


public void UnloadTheEquipment(Weapon w){
this.hp -= w.addHp;
this.ATK -= w.addATK;
this.defense -= w.addDefense;
this.speed -= w.addSpeed;
Console.WriteLine ("你卸下了{0}装备,属性值减少",w.name);
}
public void Attack(Hero p){
if (p.hp <= 0) {
Console.WriteLine ("攻击无效,该玩家已死亡");
} else {
Console.WriteLine ("你对{0}造成了{1}伤害",p.name,this.ATK-p.defense);
if (this.ATK >= p.hp + p.defense / 10) {
this.AddGrade (this);
}
p.Injured (this.ATK);
}
}
public void Injured(int x){
this.hp -= (x - this.defense / 10);
if (hp <= 0) {
Console.WriteLine ("玩家{0}阵亡",this.name);
}
}
public void AddGrade(Hero p){
p.grade++;
p.ATK += 200;
Console.WriteLine ("英雄{0}升级了",p.name);
}


}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值