Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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);
        }