Ejemplo n.º 1
0
        public static Models.GameProgress Deserialize(string serializedGameProgress)
        {
            Csv csv = new Csv (serializedGameProgress);
            int[] savedGameData = csv.ToIntArray ();
            int dataIndex = 0;

            Models.GameProgress gameProgress = new Models.GameProgress (savedGameData [dataIndex++]);

            while (dataIndex < savedGameData.Length) {
                int worldNumber = savedGameData [dataIndex++];
                int levelNumber = savedGameData [dataIndex++];
                int moves = savedGameData [dataIndex++];
                int stars = savedGameData [dataIndex++];
                Models.SolvedLevel solvedLevel = new Models.SolvedLevel (worldNumber, levelNumber, moves, stars);
                gameProgress.AddSolvedLevel (solvedLevel);
            }

            return gameProgress;
        }
Ejemplo n.º 2
0
        public static string Serialize(Models.GameProgress gameProgress)
        {
            Csv csv = new Csv ();

            csv.Append (gameProgress.Slot);
            for (int world=0; world < Constants.WorldCount; world++) {
                for (int level=0; level < Constants.WorldLevelCount; level++) {
                    Models.SolvedLevel solvedLevel = gameProgress.GetSolvedLevel (world, level);
                    if (solvedLevel == null) {
                        break; // Levels must be solved in order
                    } else {
                        csv.Append (solvedLevel.WorldNumber);
                        csv.Append (solvedLevel.LevelNumber);
                        csv.Append (solvedLevel.Moves);
                        csv.Append (solvedLevel.Stars);
                    }
                }
            }

            return csv.ToString ();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deserialize the specified serializedLockGrid: see Serialize.
        /// </summary>
        /// <param name="serializedLockGrid">Serialized lock grid.</param>
        public static Models.LockGrid Deserialize(string serializedLockGrid)
        {
            Csv csv = new Csv (serializedLockGrid);
            int[] values = csv.ToIntArray ();
            int valueIndex = 0;

            // Deserialize the lock grid properties
            int rowCount = values [valueIndex++];
            int colCount = values [valueIndex++];
            int buttonCount = values [valueIndex++];
            int maxMovesFor2Stars = values [valueIndex++];
            int maxMovesFor3Stars = values [valueIndex++];
            Models.LockGrid lockGrid = new Models.LockGrid (rowCount, colCount, buttonCount, maxMovesFor2Stars, maxMovesFor3Stars);

            // Deserialize the locks and buttons
            for (int row=0; row<rowCount; row++) {
                for (int col=0; col<colCount; col++) {
                    Models.Lock currentLock = lockGrid.Locks [row, col];
                    // Deserialize the lock properties
                    //currentLock.UnlockedPosition = values [valueIndex++];
                    currentLock.CurrentPosition = values [valueIndex++];
                    // Deserialize the buttons
                    for (int buttonIndex=0; buttonIndex<buttonCount; buttonIndex++) {
                        Models.LockButton button = currentLock.Buttons [buttonIndex];
                        button.IsOn = (values [valueIndex++] == 1);
                        int linkedButtonRow = values[valueIndex++];
                        int linkedButtonCol = values [valueIndex++];
                        int linkedButtonIndex = values [valueIndex++];
                        if (button.IsUnlinked ()) {
                            button.LinkWithButton (lockGrid.GetButtonAt (linkedButtonRow, linkedButtonCol, linkedButtonIndex));
                        }
                    }
                }
            }

            return lockGrid;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates a string representation of the specified LockGrid: see Deserialize.
        /// </summary>
        /// <param name="lockGrid">Lock grid.</param>
        public static string Serialize(Models.LockGrid lockGrid)
        {
            Csv csv = new Csv ();

            // Serialize the lock grid properties
            csv.Append (lockGrid.RowCount);
            csv.Append (lockGrid.ColCount);
            csv.Append (lockGrid.ButtonCount);
            csv.Append (lockGrid.MaxMovesFor2Stars);
            csv.Append (lockGrid.MaxMovesFor3Stars);

            // Serialize the locks and their buttons
            for (int row=0; row<lockGrid.RowCount; row++) {
                for (int col=0; col<lockGrid.ColCount; col++) {
                    Models.Lock currentLock = lockGrid.Locks [row, col];
                    // Serialize the lock properties
                    //csv.Append (currentLock.UnlockedPosition);
                    csv.Append (currentLock.CurrentPosition);
                    // Serialize the buttons
                    for (int buttonIndex=0; buttonIndex<currentLock.ButtonCount; buttonIndex++) {
                        Models.LockButton button = currentLock.Buttons [buttonIndex];
                        csv.Append (button.IsOn);
                        csv.Append (button.LinkedButton.ContainingLockGridRow);
                        csv.Append (button.LinkedButton.ContaingLockGridCol);
                        csv.Append (button.LinkedButton.ContainingLockIndex);
                    }
                }
            }

            return csv.ToString ();
        }