using System.Collections.Specialized;
using System.Xml.Linq;
namespace 结构体
{
struct Player
{
public string name;
public E_occupation occupation;
public Player(string name,E_occupation occupation )
{
this.name = name;
this.occupation = occupation;
}
public void Skill()
{
switch (occupation)
{
case E_occupation.Warrior:
Console.WriteLine("玩家名称{0},职业战士 ,技能冲锋", name);
break;
case E_occupation.Hunter:
Console.WriteLine("玩家名称{0},职业猎人 ,技能假死", name);
break;
case E_occupation.Master:
Console.WriteLine("玩家名称{0},职业法师 ,技能奥术冲击", name);
break;
}
}
}
enum E_occupation
{
Warrior,
Hunter,
Master,
}
class Program {
static void Main(String[] args)
{
string name;
Console.WriteLine("请输入您的姓名");
name = Console.ReadLine();
Console.WriteLine("请选择您的职业0战士 1猎人 2法师");
Player player=new Player();
try
{
player.occupation = (E_occupation)int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("请输入数字");
}
player.name = name;
player.Skill();
}
}
}
第二个 小怪兽练习~ ( ~ v ~ )~
using System.Collections.Specialized;
using System.Xml.Linq;
namespace 结构体
{
struct Monster
{
public int atk;
public string name;
public Monster( string name)
{
this.name = name;
Random random = new Random();
atk = random.Next(1, 3);
}
public void Atk()
{
Console.WriteLine("{0}攻击力{1}",name,atk);
}
}
class Program {
static void Main(String[] args)
{
Monster[] monsters= new Monster[10];
for(int i = 0; i < monsters.Length; i++)
{
monsters[i] = new Monster("小怪兽" + i);
monsters[i].Atk();
}
}
}
}
第三个 奥特曼打怪兽练习(^ v ^)
using System.Collections.Specialized;
using System.Threading;
using System.Xml.Linq;
namespace 结构体
{
struct OutMan
{
public string name;
public int atk;
public int def;
public int hp;
public OutMan(string name,int atk, int def, int hp)
{
this.name = name;
this.def = def;
this.hp = hp;
this.atk = atk;
}
public void Atk( ref Monster monster)
{
monster.hp -= atk - monster.def;
Console.WriteLine("{0}攻击了{1}造成了{2},{3}剩余HP{4}", name, monster.name, atk - monster.def, monster.name, monster.hp);
}
}
struct Monster
{
public int atk;
public int def;
public int hp;
public string name;
public Monster( string name,int atk ,int def,int hp)
{
this .name = name;
this .def = def;
this .hp = hp;
this .atk = atk;
}
public void Atk(ref OutMan outMan)
{
outMan.hp -= atk - outMan.def;
Console.WriteLine("{0}攻击了{1}造成了{2},{3}剩余HP{4}", name, outMan.name, atk - outMan.def, outMan.name, outMan.hp);
}
}
class Program {
static void Main(String[] args)
{
OutMan outMan = new OutMan("泰罗奥特曼",8,5,100);
Monster monster = new Monster("老怪兽", 7, 5, 100);
while (outMan.hp> 0 && monster.hp>0)
{
outMan.Atk(ref monster);
monster.Atk(ref outMan);
}
if (outMan.hp > 0)
{
Console.WriteLine("泰罗奥特曼胜利");
}
else
{
Console.WriteLine("老怪兽胜利");
}
}
}
}