internal void SetSavedData(Deck deck, HandsFromServer hfs, List <CardView> cribCards, List <CardView> playedCards, PlayerType dealer, Dictionary <string, string> countingState) { _dealer = dealer; NewGame(_dealer, deck); _deck.SharedCard = hfs.SharedCard; _player.Hand = new Hand(hfs.PlayerCards); _computer.Hand = new Hand(hfs.ComputerCards); if (dealer == PlayerType.Player) { _player.Crib = new Crib(cribCards); _player.HasCrib = true; _computer.HasCrib = false; } else { _computer.Crib = new Crib(cribCards); _player.HasCrib = false; _computer.HasCrib = true; } if (countingState != null && countingState.Count != 0) { _countingPhase = new CountingPhase(_player, _player.Hand.Cards, _computer, _computer.Hand.Cards); _countingPhase.Deserialize(countingState); CountingState state = new CountingState(_player, _computer); _countingPhase.State = state; } }
public CardView PickCard(Player player) { if (_countingPhase == null) { // // get a state machine to for the counting phase _countingPhase = new CountingPhase(_player, _player.Hand.Cards, _computer, _computer.Hand.Cards); } return(_countingPhase.PickCard(player)); }
public CountingData CountCard(PlayerType type, CardView card, GameDifficulty diffuculty) { Player player = GetPlayer(type); if (_countingPhase == null) { // // get a state machine to for the counting phase _countingPhase = new CountingPhase(_player, _player.Hand.Cards, _computer, _computer.Hand.Cards); } // MainPage.LogTrace.WriteLogEntry("in countcard. Turn is: {0}", _countingPhase.State.TurnPlayer.Name); CountingData data = new CountingData(); Player playThisTurn = _countingPhase.State.TurnPlayer; Player playNextTurn = _countingPhase.State.NextTurnPlayer; if (playThisTurn.Type != type) { Debug.Assert(false, "Wrong turn encountered"); //throw new Exception("Not your turn!"); } CountingState state = _countingPhase.PlayCard(playThisTurn, card, diffuculty); data.Score = state.LastScore; data.CurrentCount = state.Count; data.ResetCount = state.ResetCount; data.CardId = card.Index; data.CardName = card.CardName; data.isGo = state.isGo; data.NextPlayer = state.TurnPlayer.Type; data.NextPlayerId = state.TurnPlayer.ID; data.NextPlayerCanGo = state.NextPlayerCanGo; data.ThisPlayerCanGo = state.ThisPlayerCanGo; data.CardsCounted = state.CardsCounted; data.ScoreStory = state.ScoreStory; data.NextPlayerIsComputer = (state.TurnPlayer.Type == PlayerType.Computer); data.CountBeforeReset = state.CountBeforeReset; if (data.CardsCounted == 8) { _countingPhase = null; } else { _countingPhase.State.ResetCount = false; _countingPhase.State.isGo = false; } return(data); }
public bool Deserialize(Dictionary <string, string> sections, Deck deck) { if (sections.Count == 0) { return(false); } Dictionary <string, string> game = StaticHelpers.DeserializeDictionary(sections["Game"]); if (sections == null) { return(false); } if (game["Version"] != SERIALIZATION_VERSION) { return(false); } _dealer = (PlayerType)Enum.Parse(typeof(PlayerType), game["Dealer"]); NewGame(_dealer, deck); CardView shared = StaticHelpers.CardFromString(game["SharedCard"], deck); _deck.SharedCard = shared; _player.Deserialize(sections["Player"], deck); _computer.Deserialize(sections["Computer"], deck); string countingPhase; if (sections.TryGetValue("Counting", out countingPhase)) { _countingPhase = new CountingPhase(_player, _player.Hand.Cards, _computer, _computer.Hand.Cards); _countingPhase.Deserialize(countingPhase, deck); CountingState state = new CountingState(_player, _computer); state.Deserialize(sections["CountingState"]); _countingPhase.State = state; } return(true); }