Ejemplo n.º 1
0
        static public OldCatanGame Deserialize(string savedGame)
        {
            OldCatanGame game = new OldCatanGame();

            game.Serializing = true;
            Dictionary <string, string> sections = null;

            try
            {
                sections = StaticHelpers.GetSections(savedGame);
                if (sections == null)
                {
                    game.Error = String.Format($"Error parsing the file into sections.\nThere are no sections.  Please load a valid .catangame file.");
                    return(game);
                }
            }
            catch (Exception e)
            {
                game.Error = e.Message;
                return(game);
            }

            StaticHelpers.DeserializeObject <OldCatanGame>(game, sections["View"], false);
            for (int groupCount = 0; groupCount < game.GroupCount; groupCount++)
            {
                TileGroup tg         = new TileGroup();
                string    tgAsString = sections[$"TileGroup {groupCount}"];
                tg.Deserialize(tgAsString, sections, groupCount);
                game.TileGroups.Add(tg);
            }
            game.Serializing = false;
            return(game);
        }
Ejemplo n.º 2
0
        //
        //  opens and parses the file into a Game object
        public async Task <OldCatanGame> LoadGame(StorageFile file)
        {
            string       error = "";
            OldCatanGame game  = null;

            try
            {
                using (var stream = await file.OpenStreamForReadAsync())
                {
                    using (var streamReader = new StreamReader(stream))
                    {
                        string savedGame = streamReader.ReadToEnd();
                        game = new OldCatanGame();

                        game.FastDeserialize(savedGame);

                        if (game.Error != null)
                        {
                            await DeleteCurrentGame(file, error);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                CurrentGameName = "";
                if (await StaticHelpers.AskUserYesNoQuestion($"Error Loading file {file.DisplayName}.\n\nDelete it?\nException: {e.Message}\n\n{e.InnerException}\n\n{e.StackTrace}", "Yes", "No") == true)
                {
                    await file.DeleteAsync();
                }
            }

            return(game);
        }
Ejemplo n.º 3
0
        public async Task LoadAllGames()
        {
            await SaveDefaultGamesLocally();

            IReadOnlyList <StorageFile> files = await GetSavedFilesInternal();

            foreach (StorageFile file in files)
            {
                OldCatanGame game = await LoadGame(file);

                if (game.Error == null)
                {
                    _games.Add(game);
                }
            }

            CurrentGameName = "Regular";
        }
Ejemplo n.º 4
0
        public void SetCurrentGame(OldCatanGame game)
        {
            //_hexPanel.Children.Clear();
            //_hexPanel.Rows = game.Rows;
            //_hexPanel.Columns = game.Columns;
            //_hexPanel.NormalHeight = 96;
            //_hexPanel.NormalWidth = 110;

            //if (game.TilesByHexOrder.Count == 0)
            //{
            //    game.LoadRestOfGame();
            //}

            //foreach (TileCtrl tile in game.TilesByHexOrder)
            //{
            //    _hexPanel.Children.Add(tile);
            //    if (_designModeSet)
            //        tile.SetTileOrientationAsync(TileOrientation.FaceUp, true);
            //}
            ////
            ////  TODO: set the harbors

            //_currentGame = game;
            //this.Rows = game.Rows;
            //this.Columns = game.Columns;
            //this.GameName = game.GameName;
            //this.NumberOfPlayers = game.NumberOfPlayers;
            //this.UseClassic = game.UsesClassicTiles;
            //this.Randomize = game.Randomize;
            //this.GameType = game.GameType;
            //this.TileGroupAsString = game.TileGroupsAsString;
            //this.CurrentGameName = game.GameName;



            //SetDesignModeAsync(_designModeSet);
            //_hexPanel.UpdateLayout();

            //BuildRoadDictionary();
        }
Ejemplo n.º 5
0
        private bool IsValidNumberLayout(OldCatanGame game)
        {
            List <List <TileCtrl> > visualTiles = game.VisualLayout();

            //
            //  Need to check the last column to see if one red tile is below another
            for (int col = 0; col < Columns; col++)
            {
                for (int row = 0; row < visualTiles.ElementAt(col).Count; row++)
                {
                    int number = visualTiles.ElementAt(col).ElementAt(row).Number;
                    if (IsRed(number))
                    {
                        if (NextLowerRightIsRed(row, col, visualTiles))
                        {
                            return(false);
                        }
                        if (NextUpperRightIsRed(row, col, visualTiles))
                        {
                            return(false);
                        }
                        if (BelowTileIsRed(row, col, visualTiles))
                        {
                            return(false);
                        }

                        // shouldn't need the below, as they are next to a tile that is above
                        //if (AboveTileIsRed(row, col, visualTiles))
                        //    return false;
                        //if (PreviousLowerLeftIsRed(row, col, visualTiles))
                        //    return false;
                        //if (PreviousUpperLeftIsRed(row, col, visualTiles))
                        //    return false;
                    }
                }
            }

            return(true);
        }