Exemple #1
0
        /// <summary>
        /// Load the game properties
        /// </summary>
        public void Load()
        {
            Logger.I("Loading savedgame...");

            try {
                XmlSerializer xs = new XmlSerializer(typeof(Savedgame));
                using (StreamReader rd = new StreamReader(mSavedgamePath)) {
                    Savedgame = xs.Deserialize(rd) as Savedgame;
                }

                Logger.I("Loading OK. " + Savedgame.Puzzles.Count + " known puzzles.");
            } catch (Exception e) {
                Logger.E("Loading KO", e);
                Savedgame = new Savedgame();
            }
        }
Exemple #2
0
        /// <summary>
        /// Tell the service where to look for puzzles and where is the save game
        /// </summary>
        /// <param name="puzzlePath">Puzzle path.</param>
        /// <param name="savedgamePath">Savedgame path.</param>
        public void Initialize(string puzzlePath, string saveFilename)
        {
            var path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);

            mCustomPuzzlePath = System.IO.Path.Combine(path, "custom");
            if (Directory.Exists (mCustomPuzzlePath) == false) {
                Directory.CreateDirectory (mCustomPuzzlePath);
            }

            // Load the saved infos
            //----------------------------------------------------------------
            this.mSavedgamePath = System.IO.Path.Combine (path, saveFilename);

            if (File.Exists (mSavedgamePath) == false) {

                Logger.I ("No savedgame found: creating a new one");

                // Create a new save game
                Savedgame = new Savedgame ();
                Save ();

            } else {

                // Load the existing one
                Load ();
            }

            // Find puzzles
            //----------------------------------------------------------------
            Logger.I ("Initializing puzzles...");

            this.mPuzzlePath = puzzlePath;

            if (Directory.Exists (puzzlePath) == false) {
                throw new ArgumentException ("Invalid puzzle path location: " + puzzlePath + " is not a valid directory!");
            }

            // Look for puzzles!
            var knowPuzzles = Savedgame.Puzzles.Where(p => p.IsCustom == false).Select (p => p.Filename);
            bool shouldSave = false;

            foreach (string file in Directory.GetFiles(this.mPuzzlePath)) {
                if (knowPuzzles.Contains (file) == false) {
                    Savedgame.Puzzles.Add (new PuzzleData () {
                        Filename = file,
                        IsNew = true,
                        IsCustom = false,
                        OwnerId = "Pixelnest Studio"
                    });

                    shouldSave = true;
                }
            }

            if (shouldSave) {
                Save ();
            }
        }
Exemple #3
0
        /// <summary>
        /// Load the game properties
        /// </summary>
        public void Load()
        {
            Logger.I ("Loading savedgame...");

            try {
                XmlSerializer xs = new XmlSerializer (typeof(Savedgame));
                using (StreamReader rd = new StreamReader(mSavedgamePath)) {
                    Savedgame = xs.Deserialize (rd) as Savedgame;
                }

                Logger.I ("Loading OK. " + Savedgame.Puzzles.Count + " known puzzles.");
            } catch (Exception e) {
                Logger.E ("Loading KO", e);
                Savedgame = new Savedgame ();
            }
        }
Exemple #4
0
        /// <summary>
        /// Tell the service where to look for puzzles and where is the save game
        /// </summary>
        /// <param name="puzzlePath">Puzzle path.</param>
        /// <param name="savedgamePath">Savedgame path.</param>
        public void Initialize(string puzzlePath, string saveFilename)
        {
            var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            mCustomPuzzlePath = System.IO.Path.Combine(path, "custom");
            if (Directory.Exists(mCustomPuzzlePath) == false)
            {
                Directory.CreateDirectory(mCustomPuzzlePath);
            }

            // Load the saved infos
            //----------------------------------------------------------------
            this.mSavedgamePath = System.IO.Path.Combine(path, saveFilename);

            if (File.Exists(mSavedgamePath) == false)
            {
                Logger.I("No savedgame found: creating a new one");

                // Create a new save game
                Savedgame = new Savedgame();
                Save();
            }
            else
            {
                // Load the existing one
                Load();
            }

            // Find puzzles
            //----------------------------------------------------------------
            Logger.I("Initializing puzzles...");

            this.mPuzzlePath = puzzlePath;

            if (Directory.Exists(puzzlePath) == false)
            {
                throw new ArgumentException("Invalid puzzle path location: " + puzzlePath + " is not a valid directory!");
            }

            // Look for puzzles!
            var  knowPuzzles = Savedgame.Puzzles.Where(p => p.IsCustom == false).Select(p => p.Filename);
            bool shouldSave  = false;

            foreach (string file in Directory.GetFiles(this.mPuzzlePath))
            {
                if (knowPuzzles.Contains(file) == false)
                {
                    Savedgame.Puzzles.Add(new PuzzleData()
                    {
                        Filename = file,
                        IsNew    = true,
                        IsCustom = false,
                        OwnerId  = "Pixelnest Studio"
                    });

                    shouldSave = true;
                }
            }

            if (shouldSave)
            {
                Save();
            }
        }