async Task <bool> IShowInstructionsAndHistoryController.Load(string s) { Dictionary <string, string> history = StaticHelpers.DeserializeDictionary(s); if (history == null) { return(false); } string value = ""; Deck deck = MainPage.Current.Deck; for (int i = 0; i < history.Count; i++) { string key = String.Format("Score {0}", i); if (history.TryGetValue(key, out value)) { var tokens = value.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); if (tokens[0] == "ScoreInstance") { ScoreHistoryView shv = new ScoreHistoryView(); await shv.PopulateGrid(tokens[1]); ShowInstructionsUi.HistoryList.Add(shv); } } } return(true); }
public static Dictionary <string, string> GetSection(string file, string section) { Dictionary <string, string> sections = StaticHelpers.GetSections(file); if (sections == null) { return(null); } return(StaticHelpers.DeserializeDictionary(sections[section])); }
public async Task <Dictionary <string, string> > Load(string s) { if (s == "") { return(null); } Dictionary <string, string> sections = StaticHelpers.GetSections(s); if (_game.Deserialize(sections, _view.Deck) == false) { return(null); } Dictionary <string, string> game = StaticHelpers.DeserializeDictionary(sections["State"]); if (sections == null) { return(null); } if (game["Version"] != SERIALIZATION_VERSION) { return(null); } _gameState = (GameState)Enum.Parse(typeof(GameState), game["GameState"]); _dealer = (PlayerType)Enum.Parse(typeof(PlayerType), game["Dealer"]); _totalCardsDropped = Convert.ToInt32(game["TotalCardsDropped"]); _nPlayerCountingPoint = Convert.ToInt32(game["PlayerCountingPoints"]); _nPlayerPointsThisTurn = Convert.ToInt32(game["PlayerPointsThisTurn"]); _nComputerCountingPoint = Convert.ToInt32(game["ComputerCountingPoints"]); _nComputerPointsThisTurn = Convert.ToInt32(game["ComputerPointsThisTurn"]); _nCribPointsThisTurn = Convert.ToInt32(game["CribPointsThisTurn"]); int playerScore = Convert.ToInt32(game["PlayerScore"]); int computerScore = Convert.ToInt32(game["ComputerScore"]); _hfs = _game.GetHfs(); _view.Hfs = _hfs; Dictionary <string, string> grids = StaticHelpers.DeserializeDictionary(sections["Grids"]); List <CardView> PlayerCards = StaticHelpers.DeserializeToList(grids["Player"], _view.Deck); List <CardView> ComputerCards = StaticHelpers.DeserializeToList(grids["Computer"], _view.Deck); List <CardView> cribCards = StaticHelpers.DeserializeToList(grids["Crib"], _view.Deck); CardView SharedCard = StaticHelpers.CardFromString(grids["SharedCard"], _view.Deck); List <CardView> playedCards = StaticHelpers.DeserializeToList(grids["Played"], _view.Deck); List <Task <object> > taskList = new List <Task <object> >(); _view.MoveCards(taskList, playedCards, _view.GridPlayedCards); _view.MoveCards(taskList, cribCards, _view.GridCrib); _view.MoveCards(taskList, PlayerCards, _view.GridPlayer); _view.MoveCards(taskList, ComputerCards, _view.GridComputer); if (_gameState == GameState.PlayerGiveToCrib) { _crib.AddRange(playedCards); } await Task.WhenAll(taskList); SharedCard.BoostZindex(ZIndexBoost.SmallBoost); _game.UpdateScoreDirect(PlayerType.Player, ScoreType.Saved, playerScore); // give the points to the player _game.UpdateScoreDirect(PlayerType.Computer, ScoreType.Saved, computerScore); // give the points to the player await UiState.AddScore(PlayerType.Player, playerScore); await UiState.AddScore(PlayerType.Computer, computerScore); _view.CountControl.Count = _game.CurrentCount; await FixUpUiState(); string scoreHistory = ""; if (sections.TryGetValue("Score History", out scoreHistory)) { await _view.Load(scoreHistory); } if (_gameState == GameState.PlayerScoreHand) { // // if we saved in the state where the player is supposed to score the hard, we need to drive the state machine // through the completion of the GameState.ScoreHand states if (_dealer == PlayerType.Player) { await SetState(GameState.PlayerScoreHand); await SetState(GameState.ShowCrib); await SetState(GameState.PlayerScoreCrib); _gameState = GameState.EndOfHand; } else { _gameState = GameState.ScoreHands; } } else if (_gameState == GameState.PlayerScoreCrib) { await SetState(GameState.PlayerScoreCrib); _gameState = GameState.EndOfHand; } SetStateAsync(_gameState); return(sections); }