Example #1
0
        private static void ReadData(StreamReader saveFileReader)
        {
            saveGame = new SaveGame(Convert.ToInt32(saveFileReader.ReadLine()));

            int actualCurrentFloor = Convert.ToInt32(saveFileReader.ReadLine());
            turnCounter = Convert.ToInt32(saveFileReader.ReadLine());

            saveFileReader.ReadLine();

            for (currentFloor = 0; currentFloor < saveGame.maxFloors; currentFloor++)
            {

                int tempMapX = Convert.ToInt32(saveFileReader.ReadLine());
                int tempMapY = Convert.ToInt32(saveFileReader.ReadLine());

                saveFileReader.ReadLine();

                string saveString = saveFileReader.ReadLine();
                while ((saveString[0].ToString() + saveString[1].ToString()) != "//") //read tiles
                {
                    Queue<string> saveStrings = new Queue<string>(saveString.Split(new string[] { separator }, StringSplitOptions.None));
                    Type type = Type.GetType("ProjectRogue." + saveStrings.Dequeue());
                    var instance = Activator.CreateInstance(type);
                    GameObject go = (GameObject)instance;
                    go.Load(saveStrings);
                    saveString = saveFileReader.ReadLine();
                }

                saveGame.map[currentFloor] = new TileMap(tempMapX, tempMapY, saveGame.gameObjectDatabase[currentFloor].Select(x => (Tile)x.Value).ToList());

                if (saveFileReader.EndOfStream)
                {
                    currentFloor = actualCurrentFloor;
                    return;
                }

                saveString = saveFileReader.ReadLine();
                while ((saveString[0].ToString() + saveString[1].ToString()) != "//") //read creatures
                {
                    Queue<string> saveStrings = new Queue<string>(saveString.Split(new string[] { separator }, StringSplitOptions.None));
                    Type type = Type.GetType("ProjectRogue." + saveStrings.Dequeue());
                    var instance = Activator.CreateInstance(type);
                    GameObject go = (GameObject)instance;
                    go.Load(saveStrings);

                    if (saveFileReader.EndOfStream)
                    {
                        currentFloor = actualCurrentFloor;
                        return;
                    }

                    saveString = saveFileReader.ReadLine();
                }

                if(saveString == comment + "misc")
                {
                    saveString = saveFileReader.ReadLine();
                    while ((saveString[0].ToString() + saveString[1].ToString()) != "//") //read misc
                    {
                        Queue<string> saveStrings = new Queue<string>(saveString.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries));
                        Type type = Type.GetType("ProjectRogue." + saveStrings.Dequeue());
                        var instance = Activator.CreateInstance(type);
                        GameObject go = (GameObject)instance;
                        go.Load(saveStrings);

                        if (saveFileReader.EndOfStream)
                        {
                            currentFloor = actualCurrentFloor;
                            return;
                        }

                        saveString = saveFileReader.ReadLine();
                    }
                }
            }

            currentFloor = actualCurrentFloor;
        }
Example #2
0
        public static void NewGame()
        {
            save = true; //for now, we want to save

            saveGame = new SaveGame(3);
            r = new Random();

            //create the map
            for (currentFloor = 0; currentFloor < saveGame.map.Length; currentFloor++)
            {
                saveGame.map[currentFloor] = new TileMap(new Map(100, 100, r, currentFloor));
            }
            currentFloor = 0;

            //spawn the player
            List<Tile> dummy = new List<Tile>();
            dummy.AddRange(map.emptyTiles);

            Tile t = dummy[r.Next(dummy.Count)];
            dummy.Remove(t);

            player = new Player(t.x, t.y, 9, playerName);

            //start message
            GameLog.newMessage("Welcome, " + player.name + "!");
            GameLog.newMessage("Trog says: KILL THEM ALL!!", Color.Red);

            // spawn the monsters
            for (int i = 0; i < 50; i++)
            {
                t = dummy[r.Next(dummy.Count)];
                new Rat(t.x, t.y);
                dummy.Remove(t);
            }
            GraphX.UpdateVisibleArea();
        }