行为型/状态模式/MarioSample/MarioStateMachine2.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace DesignModeConsole.行为型.状态模式.MarioSample;

/// <summary>
/// 查表法
/// </summary>
public class MarioStateMachine2
{
    private static readonly StateEnum[][] _transitionTable =
    {
        // 第一层:small  super cape fire
        new[] { StateEnum.Super, StateEnum.Cape, StateEnum.Fire, StateEnum.Small },
        new[] { StateEnum.Super, StateEnum.Cape, StateEnum.Fire, StateEnum.Small },
        new[] { StateEnum.Cape, StateEnum.Cape, StateEnum.Cape, StateEnum.Small },
        new[] { StateEnum.Fire, StateEnum.Fire, StateEnum.Fire, StateEnum.Small }
    };

    private static readonly List<List<int>> _actionTable = new()
    {
        new List<int> { +100, +200, +300, 0 },
        new List<int> { 0, 200, 300, -100 },
        new List<int> { 0, 0, 0, -200 },
        new List<int> { 0, 0, 0, -300 }
    };

    public MarioStateMachine2()
    {
        Score = 0;
        State = StateEnum.Small;
    }

    public int Score { get; private set; }

    public StateEnum State { get; private set; }

    /// <summary>
    /// 得到蘑菇
    /// </summary>
    public void ObtainMushRoom()
    {
        ExecuteEvent(EventEnum.GotMushRoom);
    }


    /// <summary>
    /// 得到斗篷
    /// </summary>
    public void ObtainCape()
    {
        ExecuteEvent(EventEnum.GotCape);
    }

    /// <summary>
    /// 得到火焰
    /// </summary>
    public void ObtainFireFlower()
    {
        ExecuteEvent(EventEnum.GotFire);
    }

    /// <summary>
后面还有 38 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。