Exemple #1
0
    public void LoadLevel(DataReader.LevelInfo loadLevel)
    {
        if (loadLevel != null)
        {
            startingMoney = loadLevel.money;
            width         = loadLevel.grid.rowsCount;
            length        = loadLevel.grid.columnsCount;

            int counter      = 0;
            int innerCounter = 0;
            // Load grid
            for (counter = 0; counter < loadLevel.grid.rows.Count; counter++)
            {
                int[] row = Array.ConvertAll <string, int>(loadLevel.grid.rows[counter].Split(','), int.Parse);
                grid.Add(row);
            }

            // Load waypoints
            waypointsNo = 0;
            for (counter = 0; counter < loadLevel.waypoints.Count; counter++)
            {
                int[] row = Array.ConvertAll <string, int>(loadLevel.waypoints[counter].Split(','), int.Parse);
                for (innerCounter = 0; innerCounter < row.Length; innerCounter++)
                {
                    if (row[innerCounter] > 0)
                    {
                        waypointsNo++;
                    }
                }
                waypoints.Add(row);
            }

            // Load towers
            for (counter = 0; counter < loadLevel.towers.Count; counter++)
            {
                towers.Add(GameData.instance.GetTower(loadLevel.towers[counter], 0));
            }

            // Load monster waves
            Wave wave;
            List <DataReader.Monster> waveMonsters;

            for (counter = 0; counter < loadLevel.waves.Count; counter++)
            {
                wave         = new Wave();
                waveMonsters = loadLevel.waves[counter].monsters;
                for (innerCounter = 0; innerCounter < waveMonsters.Count; innerCounter++)
                {
                    wave.AddMonster(waveMonsters[innerCounter].Amount, waveMonsters[innerCounter].Seconds,
                                    GameData.instance.GetMonster(waveMonsters[innerCounter].ID));
                }
                waves.Add(wave);
            }
        }
        loaded = true;
    }