예제 #1
0
        public bool Deserialize(string s, Deck deck)
        {
            Dictionary <string, string> dict = StaticHelpers.DeserializeDictionary(s);

            if (dict == null)
            {
                return(false);
            }
            string sHand = dict["Hand"];

            _type = (PlayerType)Enum.Parse(typeof(PlayerType), dict["Type"], true);

            List <CardView> cards = StaticHelpers.DeserializeToList(sHand, deck);;

            _hand    = new Hand(cards);
            _hasCrib = Convert.ToBoolean(dict["HasCrib"]);
            if (_hasCrib)
            {
                _crib       = new Crib();
                _crib.Cards = StaticHelpers.DeserializeToList(dict["Crib"], deck);
            }



            _score = Convert.ToInt32(dict["Score"]);

            return(true);
        }
예제 #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);
        }
예제 #3
0
        public bool Deserialize(string s)
        {
            Dictionary <string, string> dict = StaticHelpers.DeserializeDictionary(s);

            if (dict == null)
            {
                return(false);
            }
            _nCardsCounted = Convert.ToInt32(dict["CardsCounted"]);
            _startOver     = Convert.ToBoolean(dict["StartOver"]);
            Count          = Convert.ToInt32(dict["Count"]);
            bool playerTurn = Convert.ToBoolean(dict["PlayerTurn"]);

            if (playerTurn)
            {
                _turnPlayer = _player;
            }
            else
            {
                _turnPlayer = _computer;
            }
            return(true);
        }
예제 #4
0
        public bool Deserialize(string s, Deck deck)
        {
            Dictionary <string, string> dict = StaticHelpers.DeserializeDictionary(s);

            if (dict == null)
            {
                return(false);
            }

            _runCards     = StaticHelpers.DeserializeToList(dict["RunCards"], deck);
            _countedCards = StaticHelpers.DeserializeToList(dict["CountedCards"], deck);

            foreach (CardView card in _countedCards)
            {
                if (StaticHelpers.RemoveCardByValueFromList(_playerHand, card) == false)
                {
                    StaticHelpers.RemoveCardByValueFromList(_computerHand, card);
                }
            }


            return(true);
        }