public bool IsValidTransition(GameAction action) { if (Game.CurrentTurn.PendingActions.Any(a => a.State == action.State)) { return IsValidGameState(action); } return false; }
public void DoActionSingle(GameAction action) { Game.CurrentTurn.SetCurrentAction(action.State, action.Location); if (!_context.NameToState.ContainsKey(action.State)) { _context = ActionContextFactory.GetContext(action.State, Game); } _context.DoAction(action); Game.CurrentTurn.AddCompletedAction(action); }
public static void AddPendingActions(this GameTurn turn, List<GameActionState> actions, GameAction parent, GameActionPriority priority, bool isExecutable) { var temp = turn.PendingActions; foreach (GameActionState state in actions) { var action = new GameAction { State = state, Parent = parent, Priority = priority, IsExecutable = isExecutable }; temp.Add(action); } turn.PendingActions = temp; }
public static void AddCompletedAction(this GameTurn turn, GameAction action) { if(action.IsComplete == false) { action.IsComplete = true; var temp = turn.CompletedActions; temp.Add(action); turn.CompletedActions = temp; } }
public static void RemoveAllSiblingActions(this GameTurn turn, GameAction action) { var temp = turn.PendingActions; if (action != null) { if (action.Priority == GameActionPriority.OptionalExclusive) { temp.RemoveAll(a => a.Priority == GameActionPriority.OptionalExclusive && a.Parent == action.Parent); } else { temp.Remove(action); } } turn.PendingActions = temp; }
public bool DoAction(GameActionState state, string actionLocation = "") { var newAction = new GameAction { State = state, Location = actionLocation, IsExecutable = true }; if (!IsValidTransition(newAction)) { return false; } //todo remove the pending action that corresponds to the new action request Game.CurrentTurn.RemoveAllSiblingActions(newAction.State); DoActionSingle(newAction); var nextAction = Game.CurrentTurn.PendingActions.FirstOrDefault(a => a.IsExecutable == true); if (nextAction != null) { Game.CurrentTurn.RemoveAllSiblingActions(nextAction); DoActionSingle(nextAction); } return true; }
public static GameAction GetTicketAction(VisitorTicketType type) { GameAction action = new GameAction(); switch (type) { case VisitorTicketType.collector: action.State = GameActionState.GetTicketCollector; break; case VisitorTicketType.vip: action.State = GameActionState.GetTicketVip; break; case VisitorTicketType.investor: action.State = GameActionState.GetTicketInvestor; break; default: action = null; break; } return action; }
private bool ValidateSpace(Game game, PlayerLocation location) { var state = (GameActionState)Enum.Parse(typeof(GameActionState), location.ToString()); var action = new GameAction { State = state, Location = game.CurrentTurn.CurrentAction.Location }; var invoker = new ActionContextInvoker(game); return invoker.IsValidTransition(action); }
public bool IsValidTransition(GameActionState state) { if (Game.CurrentTurn.PendingActions.Any(a => a.State == state)) { var action = new GameAction { State = state }; return IsValidGameState(action); } return false; }
public bool IsValidGameState(GameAction action) { var context = ActionContextFactory.GetContext(action.State, Game); return context.IsValidGameState(action); }
public static void RemovePendingAction(this GameTurn turn, GameAction action) { var temp = turn.PendingActions; temp.Remove(action); turn.PendingActions = temp; }
public static void AddPendingAction(this GameTurn turn, GameAction action) { var temp = turn.PendingActions; temp.Add(action); turn.PendingActions = temp; }
public static void StartTurn(this GameTurn turn) { var startAction = new GameAction { State = GameActionState.ChooseLocation }; turn.CurrentAction = startAction; var invoker = new ActionContextInvoker(turn.Game); invoker.DoActionSingle(startAction); }
public static void SetupFirstTurn(this Game newGame) { var firstTurn = new GameTurn { TurnNumber = 0, Type = GameTurnType.Setup, CurrentAction = new GameAction { State = GameActionState.GameStart } }; newGame.Turns.Add(firstTurn); var next = new GameAction { State = GameActionState.Pass }; (new ActionContextInvoker(newGame)).DoActionSingle(next); }