Skip to content

Commit 61be027

Browse files
committed
添加在酒馆的苍蝇 - 有 BUG,后续再调试
1 parent f35c897 commit 61be027

13 files changed

+702
-4
lines changed

StateMachineLearn/Program.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
}
1313
};
1414

15+
var fly = new Fly(EntityName.EntityFly, FlyGlobalState.Instance, FlyGlobalState.Instance)
16+
{
17+
FSM = { GlobalState = FlyGlobalState.Instance }
18+
};
19+
1520
GameEntityManger.Instance.TryAddNewEntity(miner);
1621
GameEntityManger.Instance.TryAddNewEntity(wife);
22+
GameEntityManger.Instance.TryAddNewEntity(fly);
1723

1824
var gameEntities = new List<BaseGameEntity>
1925
{
2026
miner,
21-
wife
27+
wife,
28+
fly
2229
};
2330

2431

StateMachineLearn/WestWord/ConstDefine.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,27 @@ public enum MessageType
121121
/// <summary>
122122
/// 炖肉好了,准备开恰⑧
123123
/// </summary>
124-
StewReady
124+
StewReady,
125+
126+
/// <summary>
127+
/// 苍蝇,老子现在在酒馆!
128+
/// </summary>
129+
FlyImSaloon,
130+
131+
/// <summary>
132+
/// 矿工,你洗干净脖子吧
133+
/// </summary>
134+
MinerImFlyAttackU,
135+
136+
/// <summary>
137+
/// 小样,就凭你?
138+
/// </summary>
139+
FlyBeAttacked,
140+
141+
/// <summary>
142+
/// 大爷,放过小人吧
143+
/// </summary>
144+
FlySurrender,
125145
}
126146

127147
}

StateMachineLearn/WestWord/EntityNames.cs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public enum EntityName
44
{
55
EntityMinerBob,
66
EntityElsa,
7+
EntityFly,
78
}
89

910
public static class EnumExtensions
@@ -14,6 +15,7 @@ public static string GetName(this EntityName entityName)
1415
{
1516
EntityName.EntityMinerBob => "Miner Bob",
1617
EntityName.EntityElsa => "Elsa",
18+
EntityName.EntityFly => "Fly",
1719
_ => "Unknown"
1820
};
1921
}

StateMachineLearn/WestWord/Fly.cs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace StateMachineLearn;
2+
using Location = ConstDefine.Location.LocationType;
3+
4+
/// <summary>
5+
/// 苍蝇接口
6+
/// </summary>
7+
public interface IFly : IBaseGameEntity
8+
{
9+
/// <summary>
10+
/// 当前位置
11+
/// </summary>
12+
public ConstDefine.Location.LocationType CurrentLocation { get; set; }
13+
14+
/// <summary>
15+
/// 状态机
16+
/// </summary>
17+
public StateMachine<Fly> FSM { get; }
18+
}
19+
20+
/// <summary>
21+
/// 苍蝇对象
22+
/// </summary>
23+
public class Fly : BaseGameEntity, IFly
24+
{
25+
/// <summary>
26+
/// 防止外部绕过 Builder 创建对象
27+
/// </summary>
28+
public Fly(EntityName name, IState<Fly> currentState, IState<Fly> preState) : base(name)
29+
{
30+
FSM = new StateMachine<Fly>(this, currentState, preState);
31+
}
32+
33+
#region Implementation of IFly
34+
35+
/// <summary>
36+
/// 当前位置
37+
/// </summary>
38+
public Location CurrentLocation { get; set; }
39+
40+
#region Overrides of BaseGameEntity
41+
42+
/// <summary>
43+
/// 处理信息
44+
/// </summary>
45+
/// <param name="msg"></param>
46+
public override void HandleMessage(in Telegram msg)
47+
{
48+
FSM.HandleMessage(msg);
49+
}
50+
51+
#endregion
52+
53+
#region Implementation of IBaseGameEntity
54+
55+
public override void Update()
56+
{
57+
FSM.Update();
58+
}
59+
60+
#endregion
61+
62+
/// <summary>
63+
/// 状态机
64+
/// </summary>
65+
public StateMachine<Fly> FSM { get; }
66+
67+
#endregion
68+
}

0 commit comments

Comments
 (0)