public void OnDrop(PointerEventData pointerEventData) { GameAction action = pointerEventData.pointerDrag.GetComponent <GameAction>(); if (action != null) { Debug.Log(pointerEventData.pointerDrag.name + " OnDrop to " + name); action.Apply(gameObject); } }
private void TryApplyAction(GameAction moveAction, Location location, Location target = Location.Undefined) { _context.LastMessage = moveAction.CheckError(_context.BoardState); if (_context.LastMessage == null) { Console.WriteLine($"Accepted: {moveAction.ToString()}"); _context.BoardState = GameAction.PrepareNextTurn(moveAction.Apply(_context.BoardState)); if (_context.ImageBehavior == BoardImageBehavior.EveryStep) { Console.WriteLine(_context.BoardState.ImageMarkdown(location, target)); } } else { Console.WriteLine($"Rejected: {moveAction.ToString()}: {_context.LastMessage}"); } }
/// <summary> /// Appends a new player move to an existing game state. /// </summary> /// <param name="playerMove">Player move to append</param> /// <returns>Tuple containing an updated game state created by the action (leaving the string null) /// OR a null game state and a populated string message explaining why the move cannot be performed.</returns> public (State, string) CommitPlayerMove(GameAction playerMove) { var lastState = this.Any() ? this[Count - 1].NewState : StateManager.Create(); var moveIdx = (lastState.Flags.IsBlueTurn() ? 2 : 0) + (lastState.Flags.IsSecondTurn() ? 1 : 0); var error = playerMove.CheckError(lastState); if (error != null) { return(new State(), error); } var postActionState = playerMove.Apply(lastState); var newState = GameAction.PrepareNextTurn(postActionState); GameTurn nextTurn; if (Count != 0 && this[Count - 1] is GameTurn lastTurn && lastTurn.Blue2 is NullAction) { nextTurn = lastTurn; }
public override void Reverse(GameState gs) { _ga.Apply(gs); }