Beispiel #1
0
        private void LoadTiles(int x, int y)
        {
            ObstacleFactory destroyableFactory   = FactoryPicker.GetFactory("Destroyable");
            ObstacleFactory undestroyableFactory = FactoryPicker.GetFactory("Undestroyable");
            var             index = 0;

            for (int i = y; i < height; i++)
            {
                for (int j = x; j < width; j++)
                {
                    int texture = 2; // Default ground tile
                    // If we launch the game and map is not big enough it will throw an npe XD
                    switch (map[i, j])
                    {
                    // Destructible Obstacles
                    case "B":
                        obstacles.Add(destroyableFactory.GetDestroyable("BrickWall"));
                        break;

                    case "C":
                        obstacles.Add(destroyableFactory.GetDestroyable("Crate"));
                        break;

                    // Undestructible Obstacles
                    case "O":
                        obstacles.Add(undestroyableFactory.GetUndestroyable("Obsidian"));
                        break;

                    case "S":
                        obstacles.Add(undestroyableFactory.GetUndestroyable("Stone"));
                        break;

                    default:
                        if (int.TryParse(map[i, j], out texture))
                        {
                            obstacles.Add(null);
                        }
                        else
                        {
                            throw new ArgumentException($"Map tile {map[i, j]} does not map to any object.");
                        }
                        break;
                    }
                    // We add a ground tile every time

                    tiles.Add(new Ground(texture));

                    //_compoundTile.Add(obstacles[index] == null ? tiles[index] : obstacles[index]);
                }
            }
        }