行为型/状态模式/MarioSample/MarioStateMachine1.cs
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace DesignModeConsole.行为型.状态模式.MarioSample;
/// <summary>
/// 分支逻辑法
/// </summary>
public class MarioStateMachine1
{
public int Score { get; private set; }
public StateEnum CurrentState { get; private set; }
public MarioStateMachine1()
{
Score = 0;
CurrentState = StateEnum.Small;
}
/// <summary>
/// 得到蘑菇
/// </summary>
public void ObtainMushRoom()
{
if (CurrentState == StateEnum.Small)
{
CurrentState = StateEnum.Super;
Score += 100;
}
}
/// <summary>
/// 得到斗篷
/// </summary>
public void ObtainCape()
{
if (CurrentState is StateEnum.Small or StateEnum.Super)
{
CurrentState = StateEnum.Cape;
Score += 200;
}
}
/// <summary>
/// 得到火焰
/// </summary>
public void ObtainFireFlower()
{
if (CurrentState is StateEnum.Small or StateEnum.Super)
{
CurrentState = StateEnum.Fire;
Score += 300;
}
}
/// <summary>
/// 遇到怪物
/// </summary>
public void MeetMonster()
{
if (CurrentState == StateEnum.Super)
{
后面还有 19 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。