Ejemplo n.º 1
0
        internal static Puzzle BuildTutorialLevel(string solvedString, string initialString, int numMoves)
        {
            var   solved  = PuzzleState.FromString(solvedString);
            var   initial = PuzzleState.FromString(initialString);
            Level level   = Level.TutorialLevel(solved, new int[] { 1 }, numMoves);

            return(new Puzzle(level, initial));
        }
Ejemplo n.º 2
0
        public static GameState FromString(string str)
        {
            var       parts = str.Split(SEPARATOR);
            GameState gs    = new GameState(
                PuzzleState.FromString(parts[0]),
                Move.ListFromString(parts[1])
                );

            return(gs);
        }
Ejemplo n.º 3
0
            public static LevelRef FromString(string str)
            {
                LevelRef lr = new LevelRef();
                var      ss = str.Trim();

                if (ss.Length > 0)
                {
                    var parts = str.Split('/');
                    var type  = (Level.LevelType)Enum.Parse(typeof(Level.LevelType), parts[0]);
                    var cc    = PuzzleState.FromString(parts[1]);
                    lr = new LevelRef(type, cc);
                }
                return(lr);
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads all level classes from metadata file
        /// format
        /// type, image file, solved config, configs move level 1, configs move level 2, ... configs move level N
        /// </summary>
        /// <param name="metaText"></param>
        private void LoadLevelDefs(string metaText)
        {
            levels.Clear();

            var json = JSON.Parse(metaText);

            foreach (JSONClass typeData in json["types"].AsArray)
            {
                var type        = (Level.LevelType)Enum.Parse(typeof(Level.LevelType), typeData["type"]);
                var typeTexture = typeData["texture"];

                foreach (JSONClass levelData in typeData["levels"].AsArray)
                {
                    var textureFile = levelData["texture"] ?? typeTexture;
                    var pieces      = levelData["pieces"];
                    var indexesStr  = levelData["indexes"].AsArray;
                    var indexes     = new int[indexesStr.Count];
                    for (int cs = 0; cs < indexesStr.Count; cs++)
                    {
                        indexes[cs] = int.Parse(indexesStr[cs]);
                    }
                    var playIndex     = levelData["moves"].AsInt;
                    var starsRequired = levelData["starsRequired"].AsInt;

                    bool  forceLoadTree = levelData["forceLoadTree"] != null;
                    bool  tutorial      = levelData["tutorial"] != null;
                    Level level         = new Level(type, PuzzleState.FromString(pieces), textureFile, LEVELS_BASE_DIR + pieces, indexes, playIndex, starsRequired, tutorial, forceLoadTree);
                    if (tutorial)
                    {
                        tutorialLevelRef = level.Ref;
                    }
                    AddLevel(level);
                }
            }

            availableLevels = new List <Level>();
            foreach (var ll in levels.Values)
            {
                availableLevels.AddRange(ll);
            }
            availableLevels.Sort();
        }
Ejemplo n.º 5
0
        public static Level TutorialLevel()
        {
            var initial = PuzzleState.FromString("0");

            return(new Level(LevelType.simple, initial, null, null, new int[] { 1 }, 1, 0, true, false));
        }
Ejemplo n.º 6
0
 public GameState()
     : this(PuzzleState.FromString("0"))
 {
 }