乱七八糟的栗子
using System;
using System.Diagnostics;
namespace ConsoleApp2
{
public interface ICharacter
{
int ID { get; set; }
int teamID { get; set; }
bool PrintTeamID(string str);
}
public abstract class Role : ICharacter
{
public Role(int id)
{
this.ID = id;
Console.WriteLine("抽象类Role的有参构造函数被调用!");
}
public abstract int ID { get; set; }
public abstract int teamID { get; set; }
public abstract bool PrintTeamID(string str);
private int blood;
public int Blood
{
get
{
return blood;
}
set
{
if (value < 0)
{
blood = 0;
}
else
{
blood = value;
}
}
}
public virtual void ShowBlood()
{
Console.WriteLine("血量是{0}", Blood);
}
}
public sealed class Monster : ICharacter
{
public int ID { get; set; }
public int teamID { get; set; }
public bool PrintTeamID(string str)
{
Console.WriteLine("class monster");
return true;
}
public int monsterBlood;
}
public class Player : Role
{
public Player(int id, int team_id) : base(id)
{
this.ID = id;
this.teamID = team_id;
}
public override int ID { get; set; }
public override int teamID { get; set; }
public override bool PrintTeamID(string str)
{
Console.WriteLine(teamID);
return true;
}
public sealed override void ShowBlood()
{
base.ShowBlood();
}
}
public class Test : Player
{
public Test():base(1,1001)
{
}
public override bool PrintTeamID(string str)
{
Console.WriteLine("class test "+ str);
return true;
}
}
class Program
{
static void Main(string[] args)
{
Player player1 = new Player(1, 1001);
player1.ShowBlood();
Console.WriteLine(player1.ID);
Player player2 = new Test();
player2.PrintTeamID("player 类型 的 test实例");
player2.ShowBlood();
Monster monster1 = new Monster();
monster1.teamID = 1002;
monster1.PrintTeamID("");
Console.ReadKey();
}
}
}