Skip to content

Commit

Permalink
添加在酒馆的苍蝇 - 有 BUG,后续再调试
Browse files Browse the repository at this point in the history
  • Loading branch information
floatval committed Jul 8, 2022
1 parent f35c897 commit 61be027
Show file tree
Hide file tree
Showing 13 changed files with 702 additions and 4 deletions.
9 changes: 8 additions & 1 deletion StateMachineLearn/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
}
};

var fly = new Fly(EntityName.EntityFly, FlyGlobalState.Instance, FlyGlobalState.Instance)
{
FSM = { GlobalState = FlyGlobalState.Instance }
};

GameEntityManger.Instance.TryAddNewEntity(miner);
GameEntityManger.Instance.TryAddNewEntity(wife);
GameEntityManger.Instance.TryAddNewEntity(fly);

var gameEntities = new List<BaseGameEntity>
{
miner,
wife
wife,
fly
};


Expand Down
22 changes: 21 additions & 1 deletion StateMachineLearn/WestWord/ConstDefine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,27 @@ public enum MessageType
/// <summary>
/// 炖肉好了,准备开恰⑧
/// </summary>
StewReady
StewReady,

/// <summary>
/// 苍蝇,老子现在在酒馆!
/// </summary>
FlyImSaloon,

/// <summary>
/// 矿工,你洗干净脖子吧
/// </summary>
MinerImFlyAttackU,

/// <summary>
/// 小样,就凭你?
/// </summary>
FlyBeAttacked,

/// <summary>
/// 大爷,放过小人吧
/// </summary>
FlySurrender,
}

}
2 changes: 2 additions & 0 deletions StateMachineLearn/WestWord/EntityNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum EntityName
{
EntityMinerBob,
EntityElsa,
EntityFly,
}

public static class EnumExtensions
Expand All @@ -14,6 +15,7 @@ public static string GetName(this EntityName entityName)
{
EntityName.EntityMinerBob => "Miner Bob",
EntityName.EntityElsa => "Elsa",
EntityName.EntityFly => "Fly",
_ => "Unknown"
};
}
Expand Down
68 changes: 68 additions & 0 deletions StateMachineLearn/WestWord/Fly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace StateMachineLearn;
using Location = ConstDefine.Location.LocationType;

/// <summary>
/// 苍蝇接口
/// </summary>
public interface IFly : IBaseGameEntity
{
/// <summary>
/// 当前位置
/// </summary>
public ConstDefine.Location.LocationType CurrentLocation { get; set; }

/// <summary>
/// 状态机
/// </summary>
public StateMachine<Fly> FSM { get; }
}

/// <summary>
/// 苍蝇对象
/// </summary>
public class Fly : BaseGameEntity, IFly
{
/// <summary>
/// 防止外部绕过 Builder 创建对象
/// </summary>
public Fly(EntityName name, IState<Fly> currentState, IState<Fly> preState) : base(name)
{
FSM = new StateMachine<Fly>(this, currentState, preState);
}

#region Implementation of IFly

/// <summary>
/// 当前位置
/// </summary>
public Location CurrentLocation { get; set; }

#region Overrides of BaseGameEntity

/// <summary>
/// 处理信息
/// </summary>
/// <param name="msg"></param>
public override void HandleMessage(in Telegram msg)
{
FSM.HandleMessage(msg);
}

#endregion

#region Implementation of IBaseGameEntity

public override void Update()
{
FSM.Update();
}

#endregion

/// <summary>
/// 状态机
/// </summary>
public StateMachine<Fly> FSM { get; }

#endregion
}
Loading

0 comments on commit 61be027

Please sign in to comment.