Example #1
0
        public static bool LoadGame(GameState state)
        {
            if (!File.Exists(FILENAME)) return false;
            bool sucessfulLoad = false;

            using (StreamReader reader = new StreamReader(FILENAME))
            {
                String st;

                while ((st = reader.ReadLine()) != null)
                {
                    if (st.StartsWith("[GameState]"))
                    {
                        state.ParseSaveString(st);
                    }
                    else if (st.StartsWith("[Accordian]"))
                    {
                        state.SetPlayer(Accordian.ParseSaveString(st));
                        sucessfulLoad = true;
                    }
                    else if (st.StartsWith("[Note]"))
                    {
                        state.AddNote(Note.ParseSaveString(st));
                    }
                    else if (st.StartsWith("[Banjo]"))
                    {
                        state.AddBanjo(Banjo.ParseSaveString(st, state.GetPlayer()));
                    }
                }
                reader.Close();
            }
            File.Delete(FILENAME);
            return sucessfulLoad;
        }
Example #2
0
        public static bool SaveGame(GameState state)
        {
            if (!Directory.Exists(PATH)) Directory.CreateDirectory(PATH);

            using (StreamWriter writer = new StreamWriter(FILENAME))
            {

                writer.WriteLine(state.ToSaveString());
                writer.WriteLine(state.GetPlayer().ToSaveString());

                foreach (Note n in state.GetNotes())
                {
                    writer.WriteLine(n.ToSaveString());
                }

                foreach (Banjo b in state.GetBanjos())
                {
                    writer.WriteLine(b.ToSaveString());
                }

                writer.Close();
            }
            return true;
        }