public void ChangeStateCommandObjectCreatedIsSameAsAConstructedObject(CommandType commandType, int magnitude) { IChangeStateCommand commandFromFactory = (ChangeStateCommand) commandFactory.NewChangeStateCommand(commandType, magnitude); IChangeStateCommand commandConstructedDirectly = new ChangeStateCommand(commandType, magnitude); Assert.IsNotNull(commandFromFactory); Assert.AreEqual(typeof(ChangeStateCommand), commandFromFactory.GetType()); Assert.AreEqual(commandConstructedDirectly.CommandType, commandFromFactory.CommandType); Assert.AreEqual(commandConstructedDirectly.Magnitude, commandFromFactory.Magnitude); }
private void CycleAction(object state) { CommandInvoker invoker = new CommandInvoker(); ICommand command = new ChangeStateCommand(RandomAnimal()); invoker.SetCommand(command); invoker.Run(); if (_animals.GetAll().Where(a => !a.IsAlive).Count() == _animals.GetAll().Count() && _animals.GetAll().Count() > 0) { AllAnimalsDead(this, new AllAnimalsDeadEventArgs()); } }
/// <summary> /// 备忘录模式 + 命令模式 /// </summary> static void MementoWithCommand() { Console.WriteLine($"备忘录模式 + 命令模式{Environment.NewLine}-------------------------------------------"); Originator originator = new Originator(); ChangeStateCommand command = new ChangeStateCommand(originator); command.Execute("v1"); command.Execute("v2"); Console.WriteLine($"[Originator.State]:{originator.State}"); command.Undo(); Console.WriteLine($"[Originator.State]:{originator.State}"); Console.ReadKey(); }
public async Task <ActionResult> ChangeState(ChangeStateCommand command) { await Mediator.Send(command); return(NoContent()); }
public void CurrentTrackOrdinalCanBeRead() { IChangeStateCommand nextCommand = new ChangeStateCommand(CommandType.SkipTrack, 1); IFileCommand playlistCommand = SetupPlaylistPlay(); Expect.Call(fileFinder.FindFiles(playlistCommand.Search, new FileTypes[] { FileTypes.M3U, FileTypes.PLS }, FileListSort.SmallestFirst)).Return( new List<string>(new string[] { "a playlist.list" })); Expect.Call(playlistReader.GetTracklist("a playlist.list")).Return( new List<string>(new string[] { "track 1.mp3", "track 2.mp3", "track 3.mp3" })); IAudioStream audioStream = SetupAudioStream(); SetupBackgroundWorker(); audioStream.Stop(); LastCall.On(audioStream).Repeat.Any(); SetupAudioStream(); SetupBackgroundWorker(); ReplayAll(); player.ProcessCommand(playlistCommand); player.ProcessCommand(nextCommand); Assert.AreEqual(2, player.CurrentTrackOrdinal); VerifyAll(); }
//float _timeInStage = 0; void Update() { // If we're not currently playing out a command.. if (!Command.playingQueue) { // If there's no commands in the queue, figure out what to do next?? if (Command.CommandQueue.Count == 0) { if (CurrentState == GameState.GameBeginPhase) { var gameBeginMsgCmd = new ShowMessageCommand("Game Begin", GlobalSettings.MessageStartTime); gameBeginMsgCmd.AddToQueue(); var changeStateCmd = new ChangeStateCommand(GameState.DrawPhase); changeStateCmd.AddToQueue(); } else if (CurrentState == GameState.DrawPhase) { TimeInStage += Time.deltaTime; if (TimeInStage > 5) { // Show a Tip to tap the deck } } else if (CurrentState == GameState.DrawTransitionPhase) { //(new MoveGameObjectCommand(drawnCard, player.inPlay.transform.position, 0.5f)).AddToQueue(); //(new MoveGameObjectCommand(oppDrawnCard, opponent.inPlay.transform.position, 0.5f)).AddToQueue(); (new MoveGameObjectCommand(new GameObject[] { player.CardOnTable, opponent.CardOnTable }, new Vector3[] { player.inPlay.transform.position, opponent.inPlay.transform.position }, GlobalSettings.CardMoveTime)).AddToQueue(); (new ChangeStateCommand(GameState.PlayPhase)).AddToQueue(); } else if (CurrentState == GameState.PlayPhase) { (new RevealCardsCommand(new GameObject[] { player.CardOnTable, opponent.CardOnTable })).AddToQueue(); (new DelayCommand(GlobalSettings.RevealDelayTime)).AddToQueue(); (new ChangeStateCommand(GameState.ResolvePhase)).AddToQueue(); (new ResolvePlayCommand(ref player, ref opponent)).AddToQueue(); } else if (CurrentState == GameState.WarPhase) { } else if (CurrentState == GameState.ResolvePhase) { } else if (CurrentState == GameState.EndPhase) { if (player.deck.cards.Count == 0) { if (player.discard.cards.Count == 0) { player.HasLost = true; } else { (new MoveDiscardToDeckCommand(ref player)).AddToQueue(); } } if (opponent.deck.cards.Count == 0) { if (opponent.discard.cards.Count == 0) { opponent.HasLost = true; } else { (new MoveDiscardToDeckCommand(ref opponent)).AddToQueue(); } } if (player.HasLost || opponent.HasLost) { (new ChangeStateCommand(GameState.GameOverPhase)).AddToQueue(); } else { (new ChangeStateCommand(GameState.DrawPhase)).AddToQueue(); } } else if (CurrentState == GameState.GameOverPhase) { Command.CommandQueue.Clear(); if (player.HasLost) { (new ShowMessageCommand("You Lose!", GlobalSettings.MessageGameEndTime)).AddToQueue(); } else { (new ShowMessageCommand("You Win!", GlobalSettings.MessageGameEndTime)).AddToQueue(); } (new ChangeStateCommand(GameState.NotPlaying)).AddToQueue(); } else if (CurrentState == GameState.NotPlaying) { if (!GameMenu.activeSelf) { GameMenu.SetActive(true); } } } //if (Command.CommandQueue.Count > 0 && !Command.playingQueue) if (Command.CommandQueue.Count > 0) { Command cmd = Command.CommandQueue.Dequeue(); cmd.StartCommandExecution(); } } }