using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Weituoshijian
{
//英雄类
class Hero
{
//属性……
//private int hp;
public delegate void AttackHandler();
//攻击方法1
public void Attack(AttackHandler method)
{
method();
}
//攻击方法2
public void Attack(int index)
{
//这样写不灵活,扩展型太差
if (index==0)
{
//ToDo……
//SF.Skill_Q(); 回调
Skill_Q();
}
else if (index==1)
{
Skill_W();
}
else
{
Console.WriteLine("普通攻击" );
}
}
//一堆技能
public void Skill_Q()
{
Console.WriteLine("我正在使用Q技能" );
}
public void Skill_W()
{
Console.WriteLine("我正在使用W技能" );
}
}
//学生,玩游戏,让班长盯梢,老师来了告诉我一声
class Student
{
//接受消息
public void ReceiveMsg(string msg)
{
Console.WriteLine("我接收到消息:" + msg);
}
//让班长盯梢
public void WatchDog(Master master)
{
//老师来了回调那个方法
master.action += ReceiveMsg;
//告诉你啥?
master.msg = "老师来了" ;
}
}
class Master
{
//可以接活:事件绑定
//事件就是委托的封装,外面绑定,不能调用
public event Action< string> action;
//暗号
public string msg;
//挣钱
public void EarnMoney()
{
action(msg);
}
//盯梢
public void WatchTeacher()
{
while (true )
{
int num = int .Parse(Console.ReadLine());
if (num == 10)
{
EarnMoney();
break;
}
}
}
}
class Program
{
static void Main(string[] args)
{
////创建一个对象
//Hero SF = new Hero();
////调用攻击方法
//SF.Attack(SF.Skill_Q);
Student s = new Student();
Master m = new Master();
s.WatchDog(m);
m.WatchTeacher();
Console.ReadKey();
}
}
}