public LockingGameHost(Game game) { _game = game; _players = new Dictionary<IGameClient, Player>(); _lock = new ReaderWriterLockSlim(); _chatSubject = new Subject<string>(); }
public void GivenANewGameWithPlayersAndBank(int playerCount, string bankCardNames) { var cardNameList = bankCardNames.Split(new char[]{',', ' '}, StringSplitOptions.RemoveEmptyEntries); var startingConfig = new ChosenStartingConfiguration(playerCount, cardNameList, false); var names = playerCount.Items(i => "Player" + i); _game = startingConfig.CreateGame(names); }
public GameViewModel(Game game, Player player) { Log = game.Log.Contents; Version = game.Version; PopulateActivityRelated(game, player); Bank = game.Bank.Piles .Select(p => new CardPileViewModel(p, game.CurrentTurn, player)).ToArray(); Hand = player.Hand .Select(c => new CardViewModel(c, game.CurrentTurn, player)).ToArray(); if (game.IsComplete) { InPlay = player.PlayArea .Select(c => new CardViewModel(c)).ToArray(); } else { InPlay = game.ActivePlayer.PlayArea .Select(c => new CardViewModel(c)).ToArray(); } Status = new TurnContextViewModel(game.CurrentTurn, player); Deck = new DeckViewModel(player.Deck); Discards = new DiscardPileViewModel(player.Discards); }
public void WhenTheGameIsScored() { var gameBinding = Binding<GameStateBindings>(); _game = gameBinding.Game; _game.Score(); _scores = _game.Scores; }
public void UpdateGameState(Game game) { var player = game.Players.Single(p => p.Id == PlayerId); var activity = game.GetPendingActivity(player) as ChoiceActivity; if (activity == null) throw new InvalidOperationException("There must be a corresponding activity"); activity.MakeChoice(Choice); }
public void UpdateGameState(Game game) { var player = game.Players.Single(p => p.Id == PlayerId); var pile = game.Bank.Piles.SingleOrDefault(p => p.Id == PileId); var activity = game.GetPendingActivity(player) as ISelectPileActivity; if (activity == null) throw new InvalidOperationException("There must be a corresponding activity"); activity.SelectPile(pile); }
public TurnContext(Player player, Game game) { ActivePlayer = player; Game = game; AvailableSpend = 0; RemainingActions = 1; Buys = 1; foreach (var longLivedEffect in player.LongLivedEffects) longLivedEffect.OnTurnStarting(this); }
private void PopulateActivityRelated(Game game, Player player) { var activity = game.GetPendingActivity(player); if(activity != null) PendingActivity = new ActivityModel(activity); if (activity is IRevealedCardsActivity) { this.Revealed = ((IRevealedCardsActivity)activity).RevealedCards .Select(c => new CardViewModel(c)).ToArray(); } }
public void UpdateGameState(Game game) { var player = game.Players.Single(p => p.Id == PlayerId); var activity = game.GetPendingActivity(player) as ISelectCardsActivity; if (activity == null) throw new InvalidOperationException("There must be a corresponding activity"); IEnumerable<ICard> cardSource; if(activity is ISelectFromRevealedCardsActivity) { cardSource = ((ISelectFromRevealedCardsActivity) activity).RevealedCards; } else { cardSource = player.Hand; } var cards = cardSource.Where(c => CardIds.Contains(c.Id)).ToList(); activity.SelectCards(cards); }
public void LogGameEnd(Game game) { GameScores scores = game.Score(); _builder .AppendLine("The game has ended!") .AppendLine() .AppendLine("----- SCORES -----"); foreach (var item in scores) _builder .AppendFormat("{0}: {1}", item.Key.Name, item.Value) .AppendLine(); _builder.AppendLine(); var winner = scores.Winner; _builder.AppendLine(); _builder.AppendLine(winner.Name + " is the winner!"); }
public void UpdateGameState(Game game) { game.CurrentTurn.MoveToBuyStep(); }
public void GivenANewGameWithPlayers(int playerCount) { var startingConfig = new SimpleStartingConfiguration(playerCount); var names = playerCount.Items(i => "Player" + i); _game = startingConfig.CreateGame(names); }
public void Validate(Game game) { }
public TurnContext BeginTurn(Game game) { var context = new TurnContext(this, game); return context; }
public void UpdateGameState(Game game) { game.EndTurn(); }
public void UpdateGameState(Game game) { CardPile pile = game.Bank.Piles.Single(p => p.Id == PileId); game.CurrentTurn.Buy(pile); }
public void UpdateGameState(Game game) { TurnContext tempQualifier = game.CurrentTurn; if (tempQualifier.ActivePlayer.Hand.OfType<IActionCard>().Any() == false || tempQualifier.RemainingActions == 0) tempQualifier.MoveToBuyStep(); }
public void Validate(Game game) { if (game.ActivePlayer.Id != PlayerId) throw new InvalidOperationException(string.Format("Player '{0}' is not active.", PlayerId)); }
public void UpdateGameState(Game game) { ICard card = game.CurrentTurn.ActivePlayer.Hand.Single(c => c.Id == CardId); game.CurrentTurn.Play((IActionCard) card); }