// Use this for initialization void Start() { god = this; // 静态状态初始化 prepareState = new PrepareState(); emptyState = new EmptyState(); roundExchangeState = new RoundExchangeState(); attackPrepareState = new AttackPrepareState(); attackCompletedState = new AttackCompletedState(); cardSelectedState = new CardSelectedState(); targetSelectedState = new TargetSelectedState(); cardCastedState = new CardCastedState(); gameOverState = new GameOverState(); //UI实例 UI = GameObject.Find("Canvas").GetComponent <UserInterface>(); UI.next_round.onClick.AddListener(delegate() { ExchangeRound(); }); // 设置初始状态 currentState = prepareState; isFree = true; init(); }
static public EmptyState GetInstance() { if (instance == null) { instance = new EmptyState(); } return(instance); }
public Lexer() { EmptyState = new EmptyState(this); NumberState = new NumberState(this); OperatorState = new OperatorState(this); CurrentState = EmptyState; }
// Use this for initialization void Start() { rBody = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); playerMovementState = EmptyState.GetInstance(); playerColl = GetComponent <BoxCollider2D>(); baseMovementSpeed = originalMovementSpeed; speed = baseMovementSpeed; }
public void ShouldCreateNewStateInstanceEverytime() { var initialState = new EmptyState(); var reducer = new AggregateReducer <EmptyState>(new Dictionary <string, object>()); var newState = reducer.Reduce(initialState, new EmptyAction()); newState.Should().NotBeNull(); newState.Should().NotBeSameAs(initialState); }
public StateMachine() { entryState = new EmptyState(); stateId = -1; registeredMaxStateId = -1; id2State = new Dictionary <int, State>(); RegisterState(entryState); currentState = entryState; previousState = entryState; }
static void Main(string[] args) { Init(); MyStopWatch timer = new MyStopWatch(); Context context = new Context(); IRaspberryPiStates emptyState = new EmptyState(); IRaspberryPiStates fullState = new FullState(); IRaspberryPiStates notDoneState = new NotDoneState(); //Bluetooth bt = new Bluetooth(); //bt.Init(); JsonWriter writer = new JsonWriter(); context.setState(emptyState); writer.JsonWriterFunc("Emptystate", "0", "Start"); //bt.SendData("EmptyState"); while (ReferenceEquals(context.getState(), emptyState) || ReferenceEquals(context.getState(), fullState) || ReferenceEquals(context.getState(), notDoneState)) { try { context.IsFull(timer, context, emptyState, fullState, notDoneState); } catch (ArgumentException) { //bt.SendData("ErrorFullStateGoEmptyState"); writer.JsonWriterFunc("Emptystate", "0", "Fullstate error"); context.setState(emptyState); } catch (InvalidOperationException) { //bt.SendData("TimeoutGoEmptyState"); writer.JsonWriterFunc("Emptystate", "0", "Timeout"); context.setState(emptyState); } catch (Exception) { //bt.SendData("ErrorGoEmptyState"); writer.JsonWriterFunc("Emptystate", "0", "ProgramCrash"); context.setState(emptyState); } } void Init() { MagnetSensor Magnet = new MagnetSensor(); LaserSensorBottom LaserBot = new LaserSensorBottom(); LaserSensorTop LaserTop = new LaserSensorTop(); Magnet.Initiate(); LaserTop.Initiate(); LaserBot.Initiate(); } }
public async Task ShouldExecuteAsyncActionWithParameters() { var parameter = new EmptyState(); var actionMock = new Mock <IAsyncAction <EmptyState> >(); _actionResolver.Setup(r => r.Resolve <EmptyAsyncActionWithParameter>()) .Returns(new EmptyAsyncActionWithParameter(actionMock.Object)); await _store.Dispatch <EmptyAsyncActionWithParameter, EmptyState>(parameter); actionMock.Verify(a => a.Execute(_store, parameter), Times.Once()); }
public async Task ShouldReactToHistoricalDebugging() { var state = new EmptyState(); var stateJson = JsonConvert.SerializeObject(state); await _store.Initialize(); await _store.InitializeDevTools(); _devToolsMock.Raise(d => d.OnJumpToStateChanged += null, new JumpToStateEventArgs(stateJson)); _store.State.Should().NotBeNull(); _navigationMock.Verify(n => n.Navigate(It.IsAny <EmptyState>()), Times.Exactly(2)); }
public DrinkMachine(int canCount) { readyState = new ReadyState(this); emptyState = new EmptyState(this); this.canCount = canCount; if (canCount > 0) { state = readyState; } else { state = emptyState; } }
public ShoppingCart <TItem> Remove(TItem item) { var newItems = new List <TItem>(Items); newItems.Remove(item); if (newItems.Count > 0) { var newState = new ActiveState(newItems); return(FromState(newState)); } else { var newState = new EmptyState(); return(FromState(newState)); } }
public void DispatchShouldTriggerReducerFlowAndUpdateState() { var initialState = new EmptyState(); var newState = new EmptyState(); var action = new EmptyAction(); _rootReducer.Setup(r => r.Reduce(It.IsAny <EmptyState>(), It.IsAny <IAction>())) .Returns(newState); _store.Dispatch(action); _store.State.Should().BeSameAs(newState); _rootReducer.Verify(r => r.Reduce(It.IsAny <EmptyState>(), It.IsAny <IAction>()), Times.Once()); _storageMock.Verify(s => s.Save(newState), Times.Once()); _devToolsMock.Verify(s => s.Send(action, newState), Times.Once()); }
public async Task ShouldInitializeOnlyOnce() { var state = new EmptyState(); _storageMock.Setup(s => s.Get <EmptyState>()) .ReturnsAsync(state); using var monitoredStore = _store.Monitor(); await _store.Initialize(); await _store.Initialize(); _store.State.Should().BeSameAs(state); monitoredStore.Should().Raise(nameof(_store.OnStateChanged)); monitoredStore.OccurredEvents.Should().HaveCount(1); _navigationMock.Verify(n => n.Start(_store), Times.Once()); _navigationMock.Verify(n => n.Navigate(state), Times.Once()); _storageMock.Verify(s => s.Get <EmptyState>(), Times.Once()); }
public void PieceIsAddedToWinController() { int piecePlaceInGrid = 2; (pieceDataSorter as StubPieceDataSorter).pieceData = new StubPieceData(piecePlaceInGrid); int maximumPiecesToPlace = 1; WinEventController winEventController = CreateWinEventController(); List <PiecePlaceInGrid> correctlyPositionedPieces = new List <PiecePlaceInGrid>(); WinController winController = CreateWinController(correctlyPositionedPieces, winEventController, maximumPiecesToPlace); EmptyState emptyState = CreateEmptyState(); PieceDestinationController movableSlot = CreateSlot(winController, 1, 0, 1); PieceDestinationController emptySlot = CreateSlot(winController, 2, 0, 2); bool wasEventTriggered = false; winEventController.AddListener(() => wasEventTriggered = true); emptyState.ReceivePiece(emptySlot, movableSlot); Assert.IsTrue(wasEventTriggered); }
// Use this for initialization void Start() { god = this; // 静态状态初始化 prepareState = new PrepareState(); emptyState = new EmptyState(); roundExchangeState = new RoundExchangeState(); attackPrepareState = new AttackPrepareState(); attackCompletedState = new AttackCompletedState(); cardSelectedState = new CardSelectedState(); targetSelectedState = new TargetSelectedState(); cardCastedState = new CardCastedState(); gameOverState = new GameOverState(); // 设置初始状态 currentState = prepareState; isFree = true; init(); }
private void AddStates <TState, TTrigger>(HierarchicalStateMachine <TState, TTrigger> stateMachine) { if (_states.Count > 0) { for (int i = 0; i < _states.Count; i++) { var current = _states[i]; TState stateId = (TState)current.StateId; IState stateObject; if (current.StateObject != null) { if (current.StateObject.InstantiateThis) { stateObject = Instantiate(current.StateObject); } else { stateObject = current.StateObject; } } else { stateObject = new EmptyState(); } stateMachine.AddState(stateId, stateObject); if (stateObject is IStateEventHandler eventHandler) { stateMachine.SubscribeEventHandlerTo(stateId, eventHandler); } } stateMachine.InitialState = (TState)InitialStateId; } }
public static CellState GetEmptyState() => EmptyState.GetInstance();
/// <summary> /// Create a new empty cart /// </summary> public static ShoppingCart <TItem> NewCart() { var newState = new EmptyState(); return(FromState(newState)); }
public static ShoppingCart <TItem> FromState(EmptyState state) { return(new ShoppingCart <TItem>(Tag.Empty, state)); }
private void ConstructStateMachine() { sm = new StateMachine <GameBool, GameTrigger>(verbose: false); GenerateLevelState generateLevelState = new GenerateLevelState(blackBoard); ReadGameFlowState readGameFlowState = new ReadGameFlowState(blackBoard); InstructionState instructionState = new InstructionState(blackBoard); LevelBeatenState levelBeatenState = new LevelBeatenState(blackBoard); CountDownState countDownState = new CountDownState(blackBoard); GameOverState gameOverState = new GameOverState(blackBoard); EndGameState endGameState = new EndGameState(blackBoard); LoadingState loadingState = new LoadingState(blackBoard); ConfigState configState = new ConfigState(blackBoard); DeathState deathState = new DeathState(blackBoard); MenuState menuState = new MenuState(blackBoard); PlayState playState = new PlayState(blackBoard); EmptyState emptyState = new EmptyState(); sm.AddEntryState(emptyState); sm.AddState(generateLevelState); sm.AddState(readGameFlowState); sm.AddState(instructionState); sm.AddState(levelBeatenState); sm.AddState(countDownState); sm.AddState(gameOverState); sm.AddState(endGameState); sm.AddState(loadingState); sm.AddState(configState); sm.AddState(deathState); sm.AddState(menuState); sm.AddState(playState); // start by going to the loading sm.AddTransition( emptyState, loadingState, sm.CreateTriggerCondition(GameTrigger.NextState)); // loading state always goes to the menu state sm.AddTransition( loadingState, menuState, sm.CreateTriggerCondition(GameTrigger.NextState)); // menu to config sm.AddTransition( menuState, configState, sm.CreateTriggerCondition(GameTrigger.GotoConfig)); // config back to menu sm.AddTransition( configState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // menu straight to game if the player has already seen the instructions sm.AddTransition( menuState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.GotoGame), sm.CreateBoolCondition(GameBool.HasSeenInstructions, true)); // menu to instructions sm.AddTransition( menuState, instructionState, sm.CreateTriggerCondition(GameTrigger.GotoGame), sm.CreateBoolCondition(GameBool.HasSeenInstructions, false)); // instruction to start game state sm.AddTransition( instructionState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.NextState)); // reading game to config to set up variables sm.AddTransition( readGameFlowState, configState, sm.CreateTriggerCondition(GameTrigger.SetUpConfig)); // config back to read game flow sm.AddTransition( configState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.NextState)); // reading game to generating a level sm.AddTransition( readGameFlowState, generateLevelState, sm.CreateTriggerCondition(GameTrigger.GotoGame)); // on generation fail, go back to main menu sm.AddTransition( generateLevelState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // generating game to countdown sm.AddTransition( generateLevelState, countDownState, sm.CreateTriggerCondition(GameTrigger.NextState)); // countdown to play state sm.AddTransition( countDownState, playState, sm.CreateTriggerCondition(GameTrigger.NextState)); // play state to death sm.AddTransition( playState, deathState, sm.CreateTriggerCondition(GameTrigger.PlayerDied)); // death back to generating level sm.AddTransition( deathState, generateLevelState, sm.CreateTriggerCondition(GameTrigger.NextState)); // death state back to main menu sm.AddTransition( deathState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // play to level beaten sm.AddTransition( playState, levelBeatenState, sm.CreateTriggerCondition(GameTrigger.PlayerWon)); // level beating to replay sm.AddTransition( levelBeatenState, generateLevelState, sm.CreateTriggerCondition(GameTrigger.ReplayLevel)); // level beaten back to read game flow to figure out what is next sm.AddTransition( levelBeatenState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.NextState)); // level beaten back to the main menu sm.AddTransition( levelBeatenState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // game is over since read game flow state can't find anything else sm.AddTransition( readGameFlowState, gameOverState, sm.CreateTriggerCondition(GameTrigger.GotoGameOver)); // in the game over state, the only option is to go back to the main menu sm.AddTransition( gameOverState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); }