Exemplo n.º 1
0
        public void NotifyUIDepthChanged(AbstractUI ui, StateContext state, int index = -1)
        {
            if (m_uiToNode.TryGetValue(ui, out Node value))
            {
                value.uis.Remove(ui);
                m_uiToNode.Remove(ui);
            }
            else
            {
                ui.canvas.set_worldCamera(m_cameraPrefab);
            }
            Node orCreateNode = GetOrCreateNode(state);

            if (index == -1)
            {
                orCreateNode.uis.Add(ui);
            }
            else
            {
                orCreateNode.uis.Insert(index, ui);
            }
            m_uiToNode.Add(ui, orCreateNode);
            if (ui.get_gameObject().get_activeInHierarchy())
            {
                m_updateOrder = true;
            }
        }
Exemplo n.º 2
0
        public void CacheContext(IUpdateContext updateContext)
        {
            var chatId = updateContext.Update.GetChatId();

            if (chatId.HasValue)
            {
                StateContext currentState = _stateCache.GetState(chatId.Value);
                if (updateContext.Update.CallbackQuery != null)
                {
                    string[] parts = updateContext.Update.CallbackQuery.Data.Split("::");

                    if (parts.Length == 0)
                    {
                        throw new ArgumentException("Invalid CallbackQuery state - button must contain data with state id ended with ::");
                    }

                    currentState.ApplyCommand(parts[0]);

                    if (parts.Length > 1)
                    {
                        updateContext.Items.Add("Data", parts[1]);
                    }
                }
                updateContext.Items.Add("History", currentState.HistoryAsList());
                updateContext.Items.Add("State", currentState.TopCommand);
            }
        }
Exemplo n.º 3
0
        private IEnumerator StartGame(FightInfo fightInfo)
        {
            StatesUtility.ClearOptionLayer();
            yield return(ApplyFightInfos(fightInfo));

            yield return(m_ui.GotoVersusAnim());

            yield return((object)new WaitForTime(2f));

            StateLayer   defaultLayer = StateManager.GetDefaultLayer();
            StateContext currentState = defaultLayer.GetChildState();

            if (currentState != null)
            {
                defaultLayer.ClearChildState(0);
                while ((int)currentState.get_loadState() == 8)
                {
                    yield return(null);
                }
            }
            FightState fightState = new FightState(fightInfo);

            defaultLayer.SetChildState(fightState, 0);
            VersusState versusState = new VersusState(m_ui, fightState);

            this.SetChildState(versusState, 0);
        }
Exemplo n.º 4
0
 public void Do(StateContext ctx, string str)
 {
     if (str == "tick")
     {
         ctx.ChangeState(TitleState.Instance);
     }
 }
Exemplo n.º 5
0
 public void Do(StateContext ctx, string str)
 {
     if (str == "monster")
     {
         ctx.ChangeState(GameOverState.Instance);
     }
 }
        private static bool DoSegement(ref StateContext context, int position, Action <string> complete, Action <string> error)
        {
            switch (context.Character)
            {
            case '@':
            case '[':
                context.State = State.Exit;
                complete(context.Accept(1));
                return(true);

            case '/':
            case '\\':
                context.State = State.Slash;
                complete(context.Accept(1));
                return(true);
            }

            if (Validate(context.Character))
            {
                return(true);
            }

            error(GetIllegalCharacterExceptionMessage(context.Character, position));
            return(false);
        }
Exemplo n.º 7
0
 private void OnCurrentTargetUnavailable(object sender, EventArgs args)
 {
     if (StateContext.CurrentState == this)
     {
         StateContext.ChangeState(this, targetingState);
     }
 }
Exemplo n.º 8
0
        public MainMenuState(StateContext context, ITinyMessengerHub messengerHub, ILogger logger, IRubiksCubeFactory rubiksCubeFactory)
            : base(context, messengerHub, logger)
        {
            this.rubiksCubeFactory = rubiksCubeFactory;

            screen = new MainMenuScreen(AdvanceToGame, QuitGame);
        }
Exemplo n.º 9
0
 public void HandleInput(E_Input input, StateContext stateCon)
 {
     if (input == E_Input.DetectedPlayer)
     {
         stateCon.CurrentState = EnemyStates.Chase;
     }
 }
Exemplo n.º 10
0
 private void AttackDecidedCallback()
 {
     if (StateContext.CurrentState == this)
     {
         StateContext.ChangeState(this, attackingState);
     }
 }
Exemplo n.º 11
0
        private ReturnValue ProcessStateStopStartOutput(StateContext context)
        {
            string state = context.Output.SplitAndTrim(Environment.NewLine)
                           .Where(x => x.StartsWith("STATE"))
                           .Select(x => x.EverythingAfterLast(" "))
                           .FirstOrDefault();

            ReturnValue returnValue = ReturnValue.Ok();

            if (context.CommandType == CommandType.Start)
            {
                returnValue = CheckOutputForErrors(context.Output, 1056);
            }
            else if (context.CommandType == CommandType.Stop)
            {
                returnValue = CheckOutputForErrors(context.Output, 1062);
            }
            else if (context.CommandType == CommandType.State && state == null)
            {
                returnValue = ReturnValue.Error(ErrorType.ServiceStateNotFound, "Failed to find the state");
            }

            return(returnValue.IsSuccess
                ? ReturnValue.Ok(state)
                : returnValue);
        }
Exemplo n.º 12
0
 public override void Enter()
 {
     base.Enter();
     StateContext.RegisterTickListener(StateContext.CurrentCombatStrategy);
     StateContext.PursueTargetedEnemy();
     StateContext.SelectPerformedAttack();
 }
Exemplo n.º 13
0
 public void endGame()
 {
     userCount              = 0;
     characterCount         = 0;
     observer               = new ConcreteSubject();
     givenWord              = "";
     xpRate                 = 1;
     abilityXpRate          = 1;
     lastAbilityUser        = "";
     playerList             = new List <Player>();
     lastWord               = new WordPrototype("empty");
     usedClone              = false;
     target                 = new Adapter();
     pointsColorAbstraction = new PointsColorRefinedAbstraction();
     skinAbstraction        = new SkinAbstraction();
     facade                 = new Facade();
     collection             = new Collection();
     iterator               = collection.CreateIterator();
     firstLevel             = new FirstLevelWord();
     secondLevel            = new SecondLevelWord();
     thirdLevel             = new ThirdLevelWord();
     h1              = new ReverseWordHandler();
     h2              = new FullWordHandler();
     h3              = new PartWordHandler();
     h4              = new LengthWordHandler();
     _stateContext   = new StateContext(new WinterState());
     chatroom        = new Chatroom();
     originator      = new Originator();
     caretaker       = new Caretaker();
     parametersGroup = new ParametersGroup();
 }
Exemplo n.º 14
0
        /// <summary>
        /// This method runs the server by continually executing state transitions.
        /// </summary>
        private void Run()
        {
            try
            {
                stream = client.GetStream();
                StateContext context = new StateContext(this);

                while (true)
                {
                    context.Next();
                }
            }
            catch (Exception e)
            {
                //IOExceptions and TimeoutExceptions have the same behavior
                Console.WriteLine(e.Message);
                client.Close();


                Player updatedPlayer = new Player(player);
                updatedPlayer.LoggedIn = false;
                if (player != null && player.LoggedIn)
                {
                    if (!players.TryUpdate(player.Name, updatedPlayer, player))
                    {
                        throw new Exception("F**k you");
                    }
                }

                //if (player != null && player.LoggedIn)
                //	player.LoggedIn = false;
                closeServer(this);
                return;
            }
        }
Exemplo n.º 15
0
 public void Do(StateContext ctx, string str)
 {
     if (str == "startbutton")
     {
         ctx.ChangeState(GameState.Instance);
     }
 }
Exemplo n.º 16
0
 public MenuButtonIdIndex(StateContext context) : base()
 {
     groupToWatch = context.GetGroup(Matcher <StateEntity> .AllOf(StateMatcher.MenuButtonId));
     groupToWatch.OnEntityAdded   += Added;
     groupToWatch.OnEntityUpdated += Updated;
     groupToWatch.OnEntityRemoved += Removed;
 }
Exemplo n.º 17
0
 public ChannelIndex(StateContext context) : base()
 {
     groupToWatch = context.GetGroup(Matcher <StateEntity> .AllOf(StateMatcher.Channel));
     groupToWatch.OnEntityAdded   += Added;
     groupToWatch.OnEntityUpdated += Updated;
     groupToWatch.OnEntityRemoved += Removed;
 }
Exemplo n.º 18
0
    public override void Enter(StateContext context)
    {
        base.Enter(context);
        SetMenuPanel(context.manager.elementsPanel);
        tweener      = pageMap.body.GetComponentInChildren <UITweener>();
        tweenerTrans = tweener.transform;
        tweenerTrans.localPosition = Vector3.zero;
        playset = context.playset;
        var title = pageMap.AddLabel(pageMap.head, context.manager.prefabs.styledLabel);

        title.text        = playset.name;
        title.effectStyle = UILabel.Effect.Outline;
        title.color       = Color.red;
        title.fontSize    = 26;
        var grid = pageMap.body.GetComponentInChildren <UIGrid>();

        grid.cellWidth = Screen.width;
        subPages       = new List <PlaysetElementsSubPage>(grid.GetComponentsInChildren <PlaysetElementsSubPage>());
        while (subPages.Count < 4)
        {
            subPages.Add(
                NGUITools.AddChild(grid.gameObject, context.manager.prefabs.elementsSubPage).GetComponent <PlaysetElementsSubPage>());
        }
        grid.Reposition();
        SetUpButtons();
        SetUpContents();
    }
Exemplo n.º 19
0
        private static bool DoString(ref StateContext context, int position)
        {
            if (context.Flags.IsEscaping())
            {
                context.Accept(Escape(context.Character));
                context.Flags.IsEscaping(false);
            }
            else
            {
                if (context.Character == '\\')
                {
                    context.Flags.IsEscaping(true);
                }
                else if (context.Character == context.Flags.GetStringQuote())
                {
                    context.State = State.Parameter;
                    context.AppendParameterConstant(context.Stack.Peek());
                }
                else
                {
                    context.Accept();
                }
            }

            return(true);
        }
Exemplo n.º 20
0
        private void OnReturnClick()
        {
            m_ui.returnButton.set_interactable(false);
            StateContext childState = this.GetChildState();

            GotoPreviousState(childState);
        }
Exemplo n.º 21
0
 public SoLongAndThanksForAllTheFish(
     StateContext stateContext,
     IQueryHandler <GetYourQuestion, string> getYourQuestionIQueryHandler)
 {
     _stateContext = stateContext;
     _getYourQuestionIQueryHandler = getYourQuestionIQueryHandler;
 }
Exemplo n.º 22
0
 public void HandleInput(E_Input input, StateContext stateCon)
 {
     if (input == E_Input.OutOfRange)
     {
         stateCon.CurrentState = EnemyStates.Chase;
     }
 }
Exemplo n.º 23
0
    public override void Enter(StateContext context)
    {
        base.Enter(context);
//		menuPanel = context.manager.logoPanel;
//		menuPanel.SetActive(true);
        context.manager.WaitForIt(1f, new EventDelegate(GoToBrowsePlaysets));
    }
Exemplo n.º 24
0
        public CameraController(UnityEngine.Camera camera, ITinyMessengerHub messengerHub, ILogger logger, IStore store)
        {
            this.camera       = camera;
            this.messengerHub = messengerHub;
            this.logger       = PrefixedLogger.ForType <CameraController>(logger);

            var transform = camera.transform;

            cameraPivot = transform.parent;

            defaultPosition = transform.position;
            defaultRotation = transform.rotation.eulerAngles;

            context = new StateContext(this.logger, store);

            context.TransitionTo(
                new WaitingForDragState(context,
                                        messengerHub,
                                        this.logger,
                                        camera));

            context.Disable();

            spinSubscriptionToken = messengerHub.Subscribe <SpinCamera360Message>(OnSpinRequested);

            enableDisableSubscriptionToken = messengerHub.Subscribe <EnableCameraControlMessage>(EnableControl);

            resetPositionSubscriptionToken = messengerHub.Subscribe <ResetCameraMessage>(Reset);

            orbitSubscriptionToken = messengerHub.Subscribe <CameraOrbitRequestMessage>(Orbit);
        }
Exemplo n.º 25
0
        static void StateTester()
        {
            #region sample 1
            // Setup context in a state
            var c = new StateContext(new ConcreteStateA());

            // Issue requests, which toggles state
            c.Request();
            c.Request();
            c.Request();
            c.Request();
            #endregion

            #region sample 2
            // Open a new account
            var account = new Account("Jim Johnson");

            // Apply financial transactions
            account.Deposit(500.0);
            account.Deposit(300.0);
            account.Deposit(550.0);
            account.PayInterest();
            account.Withdraw(2000.00);
            account.Withdraw(1100.00);
            #endregion
        }
Exemplo n.º 26
0
        public static TransitionState DoTransition([NotNull] StateContext nextState, [CanBeNull] StateContext previousState, [CanBeNull] StateContext parentState = null)
        {
            TransitionState transitionState = new TransitionState(nextState, previousState);

            (parentState ?? ((object)((previousState != null) ? previousState.get_parent() : null)) ?? ((object)StateManager.GetDefaultLayer())).SetChildState(transitionState, 0);
            return(transitionState);
        }
Exemplo n.º 27
0
        public OptionsState(StateContext context) : base(context)
        {
            InputMap.AddMapping(Terminal.TK_UP, ActionType.MoveUp);
            InputMap.AddMapping(Terminal.TK_DOWN, ActionType.MoveDown);
            InputMap.AddMapping(Terminal.TK_LEFT, ActionType.MoveLeft);
            InputMap.AddMapping(Terminal.TK_RIGHT, ActionType.MoveRight);
            InputMap.AddMapping(Terminal.TK_ENTER, ActionType.Activate);

            var speedPicker = new Picker <GameSpeed>("Speed", HandleChangeSpeed);

            speedPicker.AddOption("Slow", GameSpeed.Slow);
            speedPicker.AddOption("Medium", GameSpeed.Medium);
            speedPicker.AddOption("Fast", GameSpeed.Fast);
            speedPicker.SelectOption(Context.Settings.Speed);

            var themePicker = new Picker <PaletteId>("Palette", HandleChangeTheme);

            themePicker.AddOption("Default", PaletteId.Default);
            themePicker.AddOption("Monochrome", PaletteId.Monochrome);
            themePicker.SelectOption(Context.Settings.PaletteId);

            Menu = new Menu();
            Menu.AddItem(themePicker);
            Menu.AddItem(speedPicker);
            Menu.AddItem(new Button("Return", () => RequestPopState()));
        }
Exemplo n.º 28
0
        private static bool DoNone(ref StateContext context)
        {
            if (context.IsWhitespace())
            {
                return(true);
            }

            switch (context.Character)
            {
            case '*':
                context.State = State.Asterisk;
                return(true);

            case '!':
                context.State = State.Exclude;
                return(true);

            case '}':
                return(context.Pop() != null);

            case ',':
                return(true);

            default:
                if (context.IsLetterOrUnderscore())
                {
                    context.Accept();
                    context.State = State.Include;
                    return(true);
                }

                context.OnError($"SyntaxError: Contains the illegal character '{context.Character}' in the data schema.");
                return(false);
            }
        }
Exemplo n.º 29
0
        private static bool DoAsterisk(ref StateContext context)
        {
            if (context.IsWhitespace())
            {
                return(true);
            }

            switch (context.Character)
            {
            case ',':
                context.Include("*");
                context.State = State.None;
                return(true);

            case '}':
                context.Include("*");
                context.Pop();
                context.State = State.None;
                return(true);

            default:
                context.OnError($"SyntaxError: Contains the illegal character '{context.Character}' in the data schema.");
                return(false);
            }
        }
Exemplo n.º 30
0
        private static bool DoGutter(ref StateContext context, int position)
        {
            switch (context.Character)
            {
            case '.':
                context.State = State.Separator;
                return(true);

            case '[':
                context.State = State.Indexer;

                //追加索引器表达式,并将索引器加入到递归栈中
                context.AppendIndexer();

                return(true);

            default:
                if (context.IsWhitespace())
                {
                    return(true);
                }

                context.OnError(GetIllegalCharacterExceptionMessage(context.Character, position));
                return(false);
            }
        }
Exemplo n.º 31
0
 public int MoveDown(StateContext stateContext)
 {
     if (stateContext.Counter < StateContext.limit)
     {
         stateContext.State = new NormalState();
         Console.Write("||");
     }
     stateContext.Counter -= 5;
     return stateContext.Counter;
 }
Exemplo n.º 32
0
 public void Main()
 {
     var stateContext = new StateContext();
     stateContext.State = new NormalState();
     var r = new Random(37);
     for (var i = 5; i <= 25; i++)
     {
         var command = r.Next(3);
         Console.Write(stateContext.Request(command) + " ");
     }
     Console.WriteLine();
 }
Exemplo n.º 33
0
 protected override void ChangeState(StateContext context) {
     switch (context.stateMark) {
         case StateMark.Figure:
             Figure figure = (Figure) context.contextObject;
             if (figure.CanMove) {
                 GameManager.TheFigureManager.SelectedFigure = figure;
                 GameManager.TheBoardController.HighlightPossibleMoves(figure);
                 GameManager.GM.GameState = new MoveFigureState();
                 StateChanged();
             }
             break;
     }
 }
Exemplo n.º 34
0
 protected override void ChangeState(StateContext context) {
     switch (context.stateMark) {
         case StateMark.MoveCard: 
             GameManager.TheFigureManager.ActivateFigures();
             GameManager.GM.GameState = new SelectFigureState();
             StateChanged();
             break;
         case StateMark.GroundCard:
             GameManager.GM.GameState = new PlaceGroundState();
             StateChanged();
             break;
     }
 }
Exemplo n.º 35
0
 protected override void ChangeState(StateContext context) {
     switch (context.stateMark) {
         case StateMark.Figure:
             Figure figure = (Figure) context.contextObject;
             Tile destTile = GameManager.TheBoardController.GetTile(figure.Coordinates);
             if (!figure.IsEnemy()) {
                 break;
             }
             GameManager.TheFigureManager.Move(destTile);
             DetermineNextState();
             break;
         case StateMark.Tile:
             Tile destination = (Tile) context.contextObject;
             if (destination.PossibleMove) {
                 GameManager.TheFigureManager.Move(destination);
                 DetermineNextState();
             }
             break;
     }
 }
Exemplo n.º 36
0
        public string CreateInState(
            Job job,
            IDictionary<string, string> parameters,
            State state)
        {
            if (job == null) throw new ArgumentNullException("job");
            if (parameters == null) throw new ArgumentNullException("parameters");
            if (state == null) throw new ArgumentNullException("state");

            var invocationData = job.MethodData.Serialize();

            var jobId = _connection.CreateExpiredJob(
                invocationData, 
                job.Arguments.ToArray(),
                parameters,
                TimeSpan.FromHours(1));

            var context = new StateContext(jobId, job.MethodData);
            ChangeState(context, state, null);

            return jobId;
        }
Exemplo n.º 37
0
 protected abstract void ChangeState (StateContext context);
Exemplo n.º 38
0
        public bool TryToChangeState(
            string jobId, State toState, string[] fromStates)
        {
            if (jobId == null) throw new ArgumentNullException("jobId");
            if (toState == null) throw new ArgumentNullException("toState");
            if (fromStates == null) throw new ArgumentNullException("fromStates");

            // To ensure that job state will be changed only from one of the
            // specified states, we need to ensure that other users/workers
            // are not able to change the state of the job during the
            // execution of this method. To guarantee this behavior, we are
            // using distributed application locks and rely on fact, that
            // any state transitions will be made only within a such lock.
            using (_connection.AcquireJobLock(jobId))
            {
                var jobData = _connection.GetJobStateAndInvocationData(jobId);

                if (jobData == null)
                {
                    // The job does not exist. This may happen, because not
                    // all storage backends support foreign keys. 
                    return false;
                }

                if (!fromStates.Contains(jobData.State, StringComparer.OrdinalIgnoreCase))
                {
                    return false;
                }

                MethodData methodData = null;
                bool loadSucceeded = true;

                try
                {
                    methodData = MethodData.Deserialize(jobData.InvocationData);
                }
                catch (JobLoadException ex)
                {
                    // If the job type could not be loaded, we are unable to
                    // load corresponding filters, unable to process the job
                    // and sometimes unable to change its state (the enqueued
                    // state depends on the type of a job).

                    toState = new FailedState(ex)
                    {
                        Reason = String.Format(
                            "Could not change the state of the job '{0}' to the '{1}'. See the inner exception for details.",
                            toState.Name, jobId)
                    };

                    loadSucceeded = false;
                }

                var context = new StateContext(jobId, methodData);
                var stateChanged = ChangeState(context, toState, jobData.State);

                return loadSucceeded && stateChanged;
            }
        }
Exemplo n.º 39
0
        internal virtual void ApplyState(
            StateContext stateContext, 
            State electedState,
            string oldStateName,
            IEnumerable<IApplyStateFilter> filters)
        {
            var context = new ApplyStateContext(
                _connection, stateContext, electedState, oldStateName);

            context.ApplyState(GetHandlers(), filters);
        }
Exemplo n.º 40
0
        internal virtual State ElectState(
            StateContext stateContext, 
            State toState,
            string fromStateName,
            IEnumerable<IElectStateFilter> filters)
        {
            var context = new ElectStateContext(
                stateContext, toState, fromStateName, _connection);

            return context.ElectState(filters);
        }
 public DragAndDropMessageState(SpriteFont font, StateContext context)
     : base(font, context)
 {
     _font = font;
 }
Exemplo n.º 42
0
        public void ChangeState_AppliesState_AndReturnsTrue()
        {
            var stateMachine = CreateStateMachineMock();
            var context = new StateContext("1", MethodData.FromExpression(() => Console.WriteLine()));
            
            var result = stateMachine.Object.ChangeState(
                context, _state.Object, OldStateName);

            stateMachine.Verify(x => x.ApplyState(
                context, _state.Object, OldStateName, It.IsNotNull<IEnumerable<IApplyStateFilter>>()));
            Assert.True(result);
        }
Exemplo n.º 43
0
        public void ChangeState_AppliesOnlyElectedState()
        {
            var stateMachine = CreateStateMachineMock();
            var context = new StateContext("1", MethodData.FromExpression(() => Console.WriteLine()));
            var electedState = new Mock<State>();

            stateMachine
                .Setup(x => x.ElectState(
                    context, _state.Object, OldStateName, It.IsNotNull<IEnumerable<IElectStateFilter>>()))
                .Returns(electedState.Object);

            stateMachine.Object.ChangeState(context, _state.Object, OldStateName);

            stateMachine.Verify(x => x.ApplyState(
                context, electedState.Object, OldStateName, It.IsAny<IEnumerable<IApplyStateFilter>>()));
        }
Exemplo n.º 44
0
	void OnMouseDown () {
        StateContext context = new StateContext(this, StateMark.Tile);
        GameManager.GM.HandleActionByState(context);			
	}
Exemplo n.º 45
0
        public void ChangeState_AppliesFailedState_WhenThereIsAnException()
        {
            var stateMachine = CreateStateMachineMock();
            var context = new StateContext("1", MethodData.FromExpression(() => Console.WriteLine()));
            var exception = new NotSupportedException();

            stateMachine.Setup(x => x.ApplyState(
                context, _state.Object, OldStateName, It.IsAny<IEnumerable<IApplyStateFilter>>()))
                .Throws(exception);

            var result = stateMachine.Object.ChangeState(
                context, _state.Object, OldStateName);

            stateMachine.Verify(x => x.ApplyState(
                context, 
                It.Is<FailedState>(s => s.Exception == exception), 
                OldStateName,
                It.Is<IEnumerable<IApplyStateFilter>>(f => !f.Any())));
            Assert.False(result);
        }
Exemplo n.º 46
0
        public void ApplyState_RunsAllHandlers()
        {
            // Arrange
            var handler1 = new Mock<StateHandler>();
            handler1.Setup(x => x.StateName).Returns(StateName);

            var handler2 = new Mock<StateHandler>();
            handler2.Setup(x => x.StateName).Returns(StateName);

            _handlers.Add(handler1.Object);
            _handlers.Add(handler2.Object);

            var stateMachine = CreateStateMachine();
            var context = new StateContext("1", MethodData.FromExpression(() => Console.WriteLine()));

            // Act
            stateMachine.ApplyState(
                context, _state.Object, OldStateName, Enumerable.Empty<IApplyStateFilter>());

            // Assert
            handler1.Verify(x => x.Apply(
                It.Is<ApplyStateContext>(c => 
                    c.JobId == context.JobId 
                    && c.MethodData == context.MethodData 
                    && c.NewState == _state.Object 
                    && c.OldStateName == OldStateName),
                It.IsAny<IWriteOnlyTransaction>()));
        }
Exemplo n.º 47
0
 public void HandleActionByState(StateContext context) {
     GameState.HandleAction(context);
 }
Exemplo n.º 48
0
 public virtual void HandleAction(StateContext context) {
     ChangeState(context);
     Messenger.Broadcast("StateChanged");
 }
Exemplo n.º 49
0
 public int MoveUp(StateContext stateContext)
 {
     stateContext.Counter += 5;
     return stateContext.Counter;
 }
Exemplo n.º 50
0
        internal virtual bool ChangeState(StateContext context, State toState, string oldStateName)
        {
            try
            {
                var filterInfo = GetFilters(context.MethodData);

                var electedState = ElectState(context, toState, oldStateName, filterInfo.ElectStateFilters);
                ApplyState(context, electedState, oldStateName, filterInfo.ApplyStateFilters);

                // State transition was succeeded.
                return true;
            }
            catch (Exception ex)
            {
                var failedState = new FailedState(ex)
                {
                    Reason = "An exception occurred during the transition of job's state"
                };

                // We should not use any state changed filters, because
                // some of the could cause an exception.
                ApplyState(context, failedState, oldStateName, Enumerable.Empty<IApplyStateFilter>());

                // State transition was failed due to exception.
                return false;
            }
        }
Exemplo n.º 51
0
 protected override void ActivateCard() {
     StateContext contex = new StateContext(this, StateMark.GroundCard);
     GameManager.GM.HandleActionByState(contex);
 } 
Exemplo n.º 52
0
        public void HandlingExitActionException()
        {
            const string StateMachineName = "test machine";
            const States CurrentStateId = States.A;
            var stateMachineInformationMock = this.CreateStateMachineInformation(StateMachineName, CurrentStateId);
            var stateMock = this.CreateStateMock(CurrentStateId);
            var stateContext = new StateContext<States, Events>();
            var exception = new Exception("test exception");

            this.testee.HandlingExitActionException(stateMachineInformationMock.Object, stateMock.Object, stateContext, ref exception);

            this.log4Net.LogContains(
                Level.Error,
                "Exception in exit action of state A of state machine test machine: System.Exception: test exception");
        }
Exemplo n.º 53
0
        /// <summary>
        /// This method runs the server by continually executing state transitions.
        /// </summary>
        private void Run()
        {
            try
            {
                stream = client.GetStream();
                StateContext context = new StateContext(this);

                while (true)
                    context.Next();
            }
            catch (Exception e)
            {
                //IOExceptions and TimeoutExceptions have the same behavior
                Console.WriteLine(e.Message);
                client.Close();

                Player updatedPlayer = new Player(player);
                updatedPlayer.LoggedIn = false;
                if (player != null && player.LoggedIn)
                    if (!players.TryUpdate(player.Name, updatedPlayer, player))
                        throw new Exception("F**k you");

                //if (player != null && player.LoggedIn)
                //	player.LoggedIn = false;
                closeServer(this);
                return;
            }
        }
Exemplo n.º 54
0
 public MessageState(SpriteFont font, StateContext context)
     : base(context)
 {
     _font = font;
 }
Exemplo n.º 55
0
 public LoadingMessageState(SpriteFont font, StateContext context)
     : base(font, context)
 {
     _font = font;
 }
Exemplo n.º 56
0
 protected CheckState(StateContext context)
 {
     Context = context;
 }