Exemple #1
0
    private void SetupStatemachine()
    {
        sm = new StateMachine();
        sm.Add(new State("Start", "Idle", () => {
            return(true);
        }));

        sm.Add(new State("Idle", "Chase", () => {
            return(CanSeePlayer());
        }));

        sm.Add(new State("Chase", "Idle", () => {
            return(!CanSeePlayer() && currentPosition == lastSeenPlayerAt);
        }));

        sm.Add(new State("Any", "Attack", () => {
            return(CanSeePlayer() && currentPosition.IsAdjacentTo(GameManagerScript.stage.Player.Position));
        }));

        sm.Add(new State("Attack", "Idle", () => {
            return(!currentPosition.IsAdjacentTo(GameManagerScript.stage.Player.Position));
        }));

        sm.StateChanged += OnStateChanged;
    }
Exemple #2
0
        public void TestBasicFunctionality()
        {
            MessageQueue q       = new MessageQueue();
            var          machine = new StateMachine <States, Messages, object>(q, States.A, "");

            machine.Add(States.A, Messages.a, States.B);
            machine.Add(States.B, Messages.b, States.C);
            machine.Add(States.C, Messages.c, States.D);
            machine.Add(States.D, Messages.d, States.E);
            machine.Add(States.E, Messages.e, States.A);

            machine.PostMessage(Messages.a);
            Assert.AreEqual(machine.State, States.B);

            machine.PostMessage(Messages.b);
            Assert.AreEqual(machine.State, States.C);

            machine.PostMessage(Messages.c);
            Assert.AreEqual(machine.State, States.D);

            machine.PostMessage(Messages.d);
            Assert.AreEqual(machine.State, States.E);

            machine.PostMessage(Messages.e);
            Assert.AreEqual(machine.State, States.A);
        }
        // TODO: C# "Method" to sort List of T. Comparable, Comparator etc.
        //public static bool SortByTime(CombatAction a, CombatAction b)
        //{
        //    return a.TimeRemaining() > b.TimeRemaining();
        //}
        #endregion

        public BattleState(SpriteBatch spriteBatch, Texture2D background, int backgroundWidth, int backgroundHeight) : base(spriteBatch, background, backgroundWidth, backgroundHeight)
        {
            // Add States necessary for combat to StateMachine.

            _battleStates.Add(EState.BattleTick, new BattleTick(_battleStates, _actions));
            _battleStates.Add(EState.BattleExecute, new BattleExecute(_battleStates, _actions));
        }
Exemple #4
0
    public override void _Ready()
    {
        NumSpawned++;
        stateMachine.Add(nameof(EmptyState), new EmptyState());
        stateMachine.Add(nameof(EnemyMoveSteady), new EnemyMoveSteady(this, stateMachine, MoveSpeed));
        stateMachine.Add(nameof(EnemyMoveUp), new EnemyMoveUp(this, stateMachine, MoveSpeed));
        stateMachine.Add(nameof(CrazyMode), new CrazyMode(this, 4 * MoveSpeed));
        stateMachine.ChangeState(nameof(EnemyMoveSteady));

        BelowArea   = GetNode <Area2D>("Area2D");
        FollowNode  = GetFollowingPoint();
        SideChecker = new SideChecker(GetNode <Node2D>("SideChecker"));

        scene = GetNode <MainScene>("../..");
        audio = scene.GetNode <AudioManager>("AudioManager");

        animation  = GetNode <AnimationPlayer>("AnimationPlayer");
        triangle   = GetNode <Sprite>("Triangle");
        square     = GetNode <Sprite>("Square");
        folded     = GetNode <Sprite>("Folded");
        origami    = GetNode <Sprite>("Origami");
        animations = new Dictionary <string, Sprite>()
        {
            { nameof(triangle), triangle },
            { nameof(square), square },
            { nameof(folded), folded },
            { nameof(origami), origami },
        };
        animations[EnemyType].Visible = true;
        animation.Play(EnemyType);

        PauseMode = PauseModeEnum.Stop;
    }
Exemple #5
0
    public bool Init(string[] args)
    {
        if (args.Length < 2)
        {
            return(false);
        }

        m_LevelName    = args[0];
        m_ScenarioName = args[1];

        PerformanceTest.StartRun();
        PerformanceTest.StartTest("A2 " + m_LevelName + " " + m_ScenarioName);
        m_StartTicks = Stopwatch.GetTimestamp();

        m_StateMachine = new StateMachine <State>();
        m_StateMachine.Add(State.Loading, null, UpdateLoadingState, null);
        m_StateMachine.Add(State.Active, EnterActiveState, UpdateActiveState, LeaveActiveState);

        Console.SetOpen(false);

        if (m_LevelName != ".")
        {
            Game.game.levelManager.LoadLevel(args[0]);
            m_StateMachine.SwitchTo(State.Loading);
        }
        else
        {
            m_StateMachine.SwitchTo(State.Active);
        }

        RenderSettings.rVSync.Value = "0";

        return(true);
    }
Exemple #6
0
    public bool Init(string[] args)
    {
        m_StateMachine = new StateMachine <PreviewState>();
        m_StateMachine.Add(PreviewState.Loading, null, UpdateLoadingState, null);
        m_StateMachine.Add(PreviewState.Active, EnterActiveState, UpdateStateActive, LeaveActiveState);

        Console.AddCommand("nextchar", CmdNextHero, "Select next character", GetHashCode());
        Console.AddCommand("nextteam", CmdNextTeam, "Select next character", GetHashCode());
        Console.AddCommand("spectator", CmdSpectatorCam, "Select spectator cam", GetHashCode());
        Console.AddCommand("respawn", CmdRespawn, "Force a respawn. Optional argument defines now many seconds untill respawn", this.GetHashCode());

        Console.SetOpen(false);

        m_GameWorld = new GameWorld("World[PreviewGameLoop]");

        if (args.Length > 0)
        {
            Game.game.levelManager.LoadLevel(args[0]);
            m_StateMachine.SwitchTo(PreviewState.Loading);
        }
        else
        {
            m_StateMachine.SwitchTo(PreviewState.Active);
        }

        GameDebug.Log("Preview initialized");
        return(true);
    }
    public ThinClient()
    {
        m_StateMachine = new StateMachine <ClientState>();
        m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState);
        m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null);
        m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null);
        m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState);
        m_StateMachine.SwitchTo(ClientState.Browsing);

        m_GameWorld = new GameWorld("ClientWorld");

        m_Transport = new SocketTransport();

        m_NetworkClient = new NetworkClient(m_Transport);

        if (Application.isEditor || Game.game.buildId == "AutoBuild")
        {
            NetworkClient.clientVerifyProtocol.Value = "0";
        }

        m_NetworkClient.UpdateClientConfig();
        m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient);
        m_ChatSystem        = new ChatSystemClient(m_NetworkClient);

        GameDebug.Log("Network client initialized");

        m_requestedPlayerSettings.playerName = ClientGameLoop.clientPlayerName.Value;
        m_requestedPlayerSettings.teamId     = -1;
    }
Exemple #8
0
        private void Start()
        {
            // populate state machine with states & switch to inactive state
            stateMachine = new StateMachine <GameState>();
            stateMachine.Add(GameState.Shuffle, EnterShuffleState, UpdateShuffleState, null);
            stateMachine.Add(GameState.Betting, EnterBettingState, UpdateBettingState, ExitBettingState);
            stateMachine.Add(GameState.Dealing, EnterDealingState, UpdateDealingState, null);
            stateMachine.Add(GameState.Playing, EnterPlayingState, UpdatePlayingState, null);
            stateMachine.Add(GameState.Result, EnterResultState, null, ExitResultState);

            // try to load a game session from a previous time played
            bool sessionLoaded = LoadSession();

            if (sessionLoaded)
            {
                LoadPlayerData(gameSession.playerDatas);
            }
            else
            {
                // create a session since one could not be loaded
                gameSession = new GameSession(seed, minimumBetAmount.Value, startingPlayerCash.Value);
            }

            stateMachine.SwitchTo(GameState.Shuffle);
        }
Exemple #9
0
 public void Set_state()
 {
     state = new StateMachine <int>();
     state.Add((int)State_idNum.MOVE, Move_State);
     state.Add((int)State_idNum.ATTACK, Attack_State);
     state.Add((int)State_idNum.CLIMBING, Climbing_State);
 }
Exemple #10
0
    static GameManager()
    {
        ItemLibrary itemLibrary = new ItemLibrary();

        MoveManager move = new MoveManager();

        SpaceContoroler space = new SpaceContoroler();

        SkillControler skill = new SkillControler();

        PlayerObjectManager player = new PlayerObjectManager();

        EnemyManager enemy = new EnemyManager();
        MapManager   map   = new MapManager();

        ///////セットアップ
        SeanState.Add(States.MakePlayerObj, new MakePlayerObj(move, player));
        SeanState.Add(States.CameraSetUp, new CameraMoveSetState(move));
        SeanState.Add(States.SetEnemyLibrary, new SetEnemyLibrary(enemy));



        ////////メインシーン
        SeanState.Add(States.Main, new MainState(move, space));
        SeanState.Add(States.MapMove, new MapMoveState(move, enemy, map));
        SeanState.Add(States.AtackState, new AtackState(skill, player, move));
        SeanState.Add(States.EnemyDamage, new EnemyDamageState(skill, player));
        SeanState.Add(States.ChargeSet, new ChargeSetState(skill, player));
        SeanState.Add(States.PlayerFind, new PlayerFindState(move));
        SeanState.Add(States.DethCheck, new DethCheckState(move, enemy));
    }
Exemple #11
0
    private void InitStates()
    {
        _stateMachine = new StateMachine();
        _stateMachine.Add("ActiveState", ActiveState);
        _stateMachine.Add("InactiveState", InactiveState);

        _stateMachine.Goto("ActiveState");
    }
Exemple #12
0
 void Awake()
 {
     stateMachine.Add(State.IDEL, IdelInit, IdelUpdate, IdelEnd);
     stateMachine.Add(State.WALK, WalkInit, WalkUpdate, WalkEnd);
     stateMachine.Add(State.SLIDER, SliderInit, SliderUpdate, SliderEnd);
     stateMachine.Add(State.DROWNED, DrownedInit, DrownedUpdate, DrownedEnd);
     stateMachine.Add(State.SERACH, SearchInit, SearchUpdate, SearchEnd);
     stateMachine.SetState(State.IDEL);
 }
Exemple #13
0
    void ITestCase.Init()
    {
        m_StateMachine.Add(StateFlag.Browsing, OnBrowsing);
        m_StateMachine.Add(StateFlag.Connecting, OnConnecting);
        m_StateMachine.Add(StateFlag.Connected, OnConnected);
        m_StateMachine.Add(StateFlag.Shutdown, OnShutdown);

        m_StateMachine.SwitchTo(StateFlag.Browsing);
    }
    private void InitStates()
    {
        _stateMachine = new StateMachine();
        _stateMachine.Add("InitState", InitState);
        _stateMachine.Add("GameplayState", GameplayState);
        _stateMachine.Add("TransitionState", TransitionState);

        _stateMachine.Goto("InitState");
    }
Exemple #15
0
    public bool Init(string[] args)
    {
        m_StateMachine = new StateMachine <ClientState>();
        m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState);
        m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null);
        m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null);
        m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState);

#if UNITY_EDITOR
        Game.game.levelManager.UnloadLevel();
        World.DisposeAllWorlds();
#endif
        m_GameWorld = new GameWorld("ClientWorld");

        m_NetworkTransport = new SocketTransport();
        m_NetworkClient    = new NetworkClient(m_NetworkTransport);

        if (Application.isEditor || Game.game.buildId == "AutoBuild")
        {
            NetworkClient.clientVerifyProtocol.Value = "0";
        }

        m_NetworkClient.UpdateClientConfig();
        m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient);
        m_ChatSystem        = new ChatSystemClient(m_NetworkClient);

        GameDebug.Log("Network client initialized");

        m_requestedPlayerSettings.playerName = clientPlayerName.Value;
        m_requestedPlayerSettings.teamId     = -1;

        Console.AddCommand("disconnect", CmdDisconnect, "Disconnect from server if connected", this.GetHashCode());
        Console.AddCommand("prediction", CmdTogglePrediction, "Toggle prediction", this.GetHashCode());
        Console.AddCommand("runatserver", CmdRunAtServer, "Run command at server", this.GetHashCode());
        Console.AddCommand("respawn", CmdRespawn, "Force a respawn", this.GetHashCode());
        Console.AddCommand("nextchar", CmdNextChar, "Select next character", this.GetHashCode());
        Console.AddCommand("nc", CmdNextChar, "short version of nextchar", this.GetHashCode());
        Console.AddCommand("nextteam", CmdNextTeam, "Select next team", this.GetHashCode());
        Console.AddCommand("spectator", CmdSpectator, "Select spectator cam", this.GetHashCode());
        Console.AddCommand("matchmake", CmdMatchmake, "matchmake <hostname[:port]/{projectid}>: Find and join a server", this.GetHashCode());

        if (args.Length > 0)
        {
            targetServer = args[0];
            m_StateMachine.SwitchTo(ClientState.Connecting);
        }
        else
        {
            m_StateMachine.SwitchTo(ClientState.Browsing);
        }

        GameDebug.Log("Client initialized");

        return(true);
    }
Exemple #16
0
    public Client()
    {
        instance      = this;
        clientWorld   = new ClientWorld();
        networkClient = new NetworkClient(clientWorld);

        StateMachine = new StateMachine <ClientState>();
        StateMachine.Add(ClientState.Browsing, EnterBrowsingState, null, null);
        StateMachine.Add(ClientState.Connecting, EnterConnectingState, null, null);
        StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, null);
    }
Exemple #17
0
    void Awake()
    {
        sm_battlestate = new StateMachine <BattleState>();
        sm_battlestate.Add(BattleState.First, FirstInit, FirstUpdate);
        sm_battlestate.Add(BattleState.Main, MainInit, MainUpdate, MainEnd);

        sm_battlestate.Add(BattleState.GameOver, GameOverInit, GameOverUpdate, GameOverEnd);
        sm_battlestate.Add(BattleState.GameClear, GameClearInit);

        sm_battlestate.Add(BattleState.Pause, PoseInit, null, PoseEnd);
    }
Exemple #18
0
    /// <summary>
    /// 開始
    /// </summary>
    void Start()
    {
        // 各ステートの関数をセット
        stateMachine.Add(PlayState.ActiveSceneToTitle, EnterActiveSceneToTitle, UpdateActiveSceneToTitle);
        stateMachine.Add(PlayState.JumpChargeStay, null, UpdateJumpChargeStay);
        stateMachine.Add(PlayState.JumpChargeing, null, UpdateJumpChargeing);
        stateMachine.Add(PlayState.PlayerJumping, EnterPlayerJumping, UpdatePlayerJumping);
        stateMachine.Add(PlayState.ActiveSceneToResult, EnterActiveSceneToResult, UpdateActiveSceneToResult);

        // 最初のステートを設定
        stateMachine.SetState(PlayState.ActiveSceneToTitle);
    }
    /// <summary>
    /// Initialize the menu
    /// </summary>
    void Start()
    {
        Player = transform.parent.GetComponent<PlayerController>();
        _stateMachine = new StateMachine<MenuController> ();

        craftingState.Start ();
        var presentationState = new PresentationState (this);

        _stateMachine.Add (craftingState);
        _stateMachine.Add (presentationState);
        _stateMachine.Set ("PresentationState");
    }
Exemple #20
0
    /// <summary>
    /// ゲーム開始時にステートを追加
    /// </summary>
    void Awake()
    {
        //Application.targetFrameRate = 60;

        stateMachine.Add(State.First, FirstInit, FirstUpdate, FirstEnd);
        stateMachine.Add(State.Game, GameInit, GameUpdate, GameEnd);
        stateMachine.Add(State.End, EndInit, null, null);
        stateMachine.Add(State.GameOver, GameOverInit, null, null);
        stateMachine.SetState(State.First);

        ScoreManager.Instance.Reset();
    }
Exemple #21
0
        private void SetupStateInit()
        {
            var    state  = State.Init;
            Action enter  = () => {
            };
            Action update = () => {
            };
            Action exit   = () => {
            };

            _StateMachine.Add(state, enter, update, exit);
        }
Exemple #22
0
    // Use this for initialization
    void Start()
    {
        idleState = new IdleState();
        walkState = new WalkState();
        jumpState = new JumpState();

        currentState = State_Player.IDLE;
        oldState     = State_Player.NONE;

        //add
        stateMachine.Add(State_Player.IDLE, idleState.PlayerEnter, idleState.PlayerUpdate, idleState.PlayerExit);
        stateMachine.Add(State_Player.WALK, walkState.PlayerEnter, walkState.PlayerUpdate, walkState.PlayerExit);
        stateMachine.Add(State_Player.JUMP, jumpState.PlayerEnter, jumpState.PlayerUpdate, jumpState.PlayerExit);
    }
Exemple #23
0
        private void InitGameStates()
        {
            // Create States
            States = new StateMachine <GameStates, GameView>(this);
            States.Add(GameStates.Loading, new GameState());
            States.Add(GameStates.Intro, new GameStateTransition(GameStates.RoundIntro));
            States.Add(GameStates.RoundIntro, new GameStateTransition(GameStates.Run));
            States.Add(GameStates.Run, new GameState());
            States.Add(GameStates.Pause, new GameStateTransition(GameStates.Run));
            States.Add(GameStates.RoundResult, new GameStateTransition(GameStates.RoundIntro));
            States.Add(GameStates.GameResult, new GameStateTransition(GameStates.Next));
            States.Add(GameStates.Next, new GameState());

            // Loading
            States.States[GameStates.Loading].StateEnter += (sender, arg) => LoadingBegin();
            States.States[GameStates.Loading].StateExit  += (sender, arg) => LoadingEnd();

            // Time
            Time.timeScale = 0;
            States.States[GameStates.Run].StateEnter += (sender, arg) => DOTween.To(() => Time.timeScale, x => Time.timeScale = x, 1, 1f).SetEase(Ease.InOutQuad).SetUpdate(true);
            States.States[GameStates.Run].StateExit  += (sender, arg) => DOTween.To(() => Time.timeScale, x => Time.timeScale = x, 0, 1f).SetEase(Ease.InOutQuad).SetUpdate(true);

            // Animated Transition
            (States.States[GameStates.Pause] as GameState)?.SetEnterTransitionAuto(false);
            (States.States[GameStates.Pause] as GameState)?.SetExitTransitionAuto(false);

            // New Round
            States.States[GameStates.RoundIntro].StateEnter += (sender, args) => InitNewRound();

            // Result Screen Finish
            States.States[GameStates.Next].StateEnter += (sender, args) => LoadNextScene();

            States.StateChanged += (sender, args) => this.Publish(EventTopics.GameStatesChanged, this);
            States.Start();
        }
        public void DeferTest()
        {
            var ctx          = new TestStateCtx();
            var stateMachine = new StateMachine <TestState, TestEvent, TestStateCtx, string>();

            stateMachine.Add(new StateA());
            stateMachine.Add(new StateB());
            stateMachine.RegisterCtx(ctx);
            ctx.Add(TestEvent.G, "hel");
            ctx.Add(TestEvent.E, "hi");
            Thread.Sleep(15);
            Assert.AreEqual(TestState.B, ctx.CurrentState);
            Assert.IsTrue(ctx.RanG);
        }
Exemple #25
0
    // Use this for initialization
    void Start()
    {
        enterEffectState = new EnterEffectState();
        playState        = new PlayState();
        deadState        = new DeadState();
        clearState       = new ClearState();

        currentState = State_StageSequence.ENTER;
        //oldState = currentState;
        oldState = State_StageSequence.START;

        stateMachine.Add(State_StageSequence.ENTER, enterEffectState.StageEnter, enterEffectState.StageUpdate, enterEffectState.StageExit);
        stateMachine.Add(State_StageSequence.PLAY, playState.StageEnter, playState.StageUpdate, playState.StageExit);
        stateMachine.Add(State_StageSequence.DEAD, deadState.StageEnter, deadState.StageUpdate, deadState.StageExit);
        stateMachine.Add(State_StageSequence.EXIT, clearState.StageEnter, clearState.StageUpdate, clearState.StageExit);
    }
Exemple #26
0
    public bool Init(string[] args)
    {
        _gameWorld         = new GameWorld("ServerWorld");
        _networkServer     = new NetworkServer(new ServerPhotonNetworkTransport());
        _networkStatistics = new NetworkStatisticsServer(_networkServer);

        _stateMachine = new StateMachine <ServerState>();
        _stateMachine.Add(ServerState.Connecting, EnterConnectingState, UpdateConnectingState, null);
        _stateMachine.Add(ServerState.Loading, EnterLoadingState, UpdateLoadingState, null);
        _stateMachine.Add(ServerState.Active, EnterActiveState, UpdateActiveState, LeaveActiveState);

        _networkServer.UpdateClientInfo();

        _stateMachine.SwitchTo(ServerState.Connecting);

        return(true);
    }
Exemple #27
0
    public bool Init(string[] args)
    {
        _stateMachine = new StateMachine <ClientState>();
        _stateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null);
        _stateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null);
        _stateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, null);
        _stateMachine.Add(ClientState.Leaving, EnterLeavingState, UpdateLeavingState, null);

        _networkClient           = new NetworkClient(new ClientPhotonNetworkTransport());
        _networkStatisticsClient = new NetworkStatisticsClient(_networkClient);

        _networkClient.UpdateClientConfig();

        _stateMachine.SwitchTo(ClientState.Connecting);

        return(true);
    }
        private static void BuildFaderStateMachine()
        {
            var fader = new StateMachine("Fader");
            var show  = fader.Add(new CallbackState {
                Name = "Fade Out", WhenEnter = Events.OnFadeOut.Raise
            });
            var hide = fader.Add(new CallbackState {
                Name = "Fade In", WhenEnter = Events.OnFadeIn.Raise
            });

            show.Permit(hide, Events.FadeIn);
            hide.Permit(show, Events.FadeOut);

            fader.SetInitialState(hide);

            Services.Add(fader, "FaderStateMachine");
        }
        private static void BuildLoadingScreenStateMachine()
        {
            var loading = new StateMachine("Loading Screen");
            var show    = loading.Add(new CallbackState {
                Name = "Show", WhenEnter = Events.OnShowLoadingScreen.Raise
            });
            var hide = loading.Add(new CallbackState {
                Name = "Hide", WhenEnter = Events.OnHideLoadingScreen.Raise
            });

            show.Permit(hide, Events.HideLoadingScreen);
            hide.Permit(show, Events.ShowLoadingScreen);

            loading.SetInitialState(hide);

            Services.Add(loading, "LoadingScreenStateMachine");
        }
Exemple #30
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Font = this.Content.Load <SpriteFont>("Arial");

            Texture2D normalTexture = Content.Load <Texture2D>("buttonbignormal");
            Texture2D hoverTexture  = Content.Load <Texture2D>("buttonbighovered");

            UIManager = new UI.Manager(normalTexture, hoverTexture, Font);

            StateMachine = new StateMachine(this);
            StateMachine.Add("MENU", new States.Menu(StateMachine));
            StateMachine.Add("GAME", new States.GameInProgress(StateMachine));
            StateMachine.Add("STATS", new States.Stats(StateMachine));
            StateMachine.Change("MENU");

            base.Initialize();
        }
Exemple #31
0
        public override void Start()
        {
            // 实例化一个玩家
            L_PlayerManager.It.CreatePlayer <L_Player_User>();

            // 创建一个UI
            GameEventMachine.SendEvent(GameEventID.Event_UI_Create, UIType.UIPlay);

            // 注册事件
            // ...

            // 注册所有状态
            m_stateMachine = new StateMachine <L_System_Play>(this);
            m_stateMachine.Add(PlayState.PS_Initialize, new PlayState_Initilize());
            m_stateMachine.Add(PlayState.PS_Business, new PlayState_Business());
            // ...
            m_stateMachine.SetCurrentState(PlayState.PS_Initialize);             // 设置默认状态
        }
Exemple #32
0
        protected static void Run()
        {
            gGameMode = new StateMachine();

            // A state for each game mode
            gGameMode.Add(States.MainMenu, new MainMenuState(gGameMode))
                .Add(States.Battle, new BattleState(gGameMode));
            //.Add("localmap",   new LocalMapState(gGameMode))
            //.Add("worldmap",   new WorldMapState(gGameMode))
            //.Add("ingamemenu", new InGameMenuState(gGameMode))

            gGameMode.Change(States.MainMenu);
            while (true)
            {
                Update();
            }
        }
Exemple #33
0
        internal void Init()
        {
            DR = IPAddress.GetDefault();
            BDR = IPAddress.GetDefault();
            _stateMachine = new StateMachine<InterfaceState, InterfaceEventType>();
            _stateMachine.Add(InterfaceState.Down, InterfaceEventType.InterfaceUp, InterfaceUp);
            _stateMachine.Add(InterfaceState.Waiting, InterfaceEventType.BackupSeen, BackupSeen);
            _stateMachine.Add(InterfaceState.Waiting, InterfaceEventType.WaitTimer, WaitTimer);
            _stateMachine.Add(InterfaceState.DROther, InterfaceEventType.NeighborChange, NeighborChange);
            _stateMachine.Add(InterfaceState.DR, InterfaceEventType.NeighborChange, NeighborChange);
            _stateMachine.Add(InterfaceState.Backup, InterfaceEventType.NeighborChange, NeighborChange);
            _stateMachine.Add(InterfaceEventType.InterfaceDown, InterfaceDown);
            _stateMachine.Add(InterfaceEventType.LoopInd, LoopInd, Ospf.InterfaceState.Loopback);
            _stateMachine.Add(InterfaceState.Loopback, InterfaceEventType.UnloopInd, UnloopInd, Ospf.InterfaceState.Down);

            Device device = _controller.DeviceConfigurationMap[DeviceID];
            if (device.IsEnabled && device.InterfaceState == Routing.InterfaceState.L2UpL3Up)
            {
                RaiseEvent(InterfaceEventType.InterfaceUp);
            }
        }
    void Start()
    {
        //Find child object with the name "Neck"
        _neck = FindTransform (transform, "Neck");
        if (_neck == null)
            throw new UnityException ("NPC: " + name + " has no neck attached");
        //Find child object with name "Center"
        _center = FindTransform (transform, "Center");
        if (_center == null)
            throw new UnityException ("NPC: " + name + " has no center attached");

        _NPCAnim = GetComponent<Animation> ();

        _forward = _center.transform.forward;
        _stateMachine = new StateMachine<NPCController> ();

        _stateMachine.Add (new TownState (this, 8));
        _stateMachine.Add (new CrowdState (this));
        _stateMachine.Add (new TravelState (this));
        if (!_stateMachine.Set ("TownState"))
        {
            Debug.Log ("Failed to set state.");
            throw new UnityException();
        }

        Switches = new Dictionary<string, bool> ();
        Variables = new Dictionary<string, float> ();

        _originalPosition = transform.position;

        switch (PersonalityName)
        {
        case "HappyFisher":
            _personality = new HappyFisher(this);
            break;
        case "Smith":
            _personality = new Smith(this);
            break;
        case "Guard":
            _personality = new Guard(this);
            break;
        case "Bland":
            _personality = new Bland(this);
            break;
        default:
            throw new UnityException("Chosen personality for NPC: \"" + name + "\" not found");
        }
    }
Exemple #35
0
 private void Init()
 {
     _sendTimer = new Timer(100);
     _inactivityTimer = new Timer();
     InitListData();
     _stateMachine = new StateMachine<OspfNeighborState, NeighborEventType>();
     ////++ NBMA
     ////_stateMachine.Add(OspfNeighborState.Down, NeighborEventType.Start, Start);
     ////_stateMachine.Add(OspfNeighborState.Attempt, NeighborEventType.HelloReceived, HelloReceived);
     _stateMachine.Add(OspfNeighborState.Down, NeighborEventType.HelloReceived, HelloReceived, nextState: OspfNeighborState.Init);
     _stateMachine.Add(OspfNeighborState.Init, NeighborEventType.HelloReceived, HelloReceived, StateEntryMode.AtLeast, nextStateMode: NextStateMode.NoAction);
     _stateMachine.Add(OspfNeighborState.Init, NeighborEventType.TwoWayReceived, TwoWayReceived);
     _stateMachine.Add(OspfNeighborState.ExStart, NeighborEventType.NegotiationDone, NegotiationDone);
     _stateMachine.Add(OspfNeighborState.Exchange, NeighborEventType.ExchangeDone, ExchangeDone);
     //_stateMachine.Add(OspfNeighborState.Loading, NeighborEventType.LoadingDone, LoadingDone);
     _stateMachine.Add(OspfNeighborState.TwoWay, NeighborEventType.AdjOK, AdjOK);
     _stateMachine.Add(OspfNeighborState.ExStart, NeighborEventType.AdjOK, AdjOK, StateEntryMode.AtLeast);
     _stateMachine.Add(OspfNeighborState.Exchange, NeighborEventType.SeqNumberMismatch, SeqNumberMismatch, StateEntryMode.AtLeast);
     //_stateMachine.Add(OspfNeighborState.Exchange, NeighborEventType.BadLSReq, BadLSReq, StateEntryMode.AtLeast);
     _stateMachine.Add(NeighborEventType.KillNbr, (s, e, o) =>
     {
         InitListData();
         _inactivityTimer.Stop();
     }, OspfNeighborState.Down);
     _stateMachine.Add(NeighborEventType.LLDown, (s, e, o) =>
     {
         InitListData();
         _inactivityTimer.Stop();
     }, OspfNeighborState.Down);
     _stateMachine.Add(NeighborEventType.InactivityTimer, (s, e, o) => InitListData(), OspfNeighborState.Down);
     _stateMachine.Add(OspfNeighborState.TwoWay, NeighborEventType.OneWayReceived, (s, e, o) => InitListData(), StateEntryMode.AtLeast, OspfNeighborState.Init);
     _stateMachine.Add(OspfNeighborState.TwoWay, NeighborEventType.TwoWayReceived, StateEntryMode.AtLeast, NextStateMode.NoAction);
     _stateMachine.Add(OspfNeighborState.Init, NeighborEventType.OneWayReceived, NextStateMode.NoAction);
     _sendTimer.Elapsed += (s, e) =>
     {
         SendDBDReady();
     };
     _sendTimer.Start();
 }