Beispiel #1
0
        private Block blockElementFactory(ElementType type)
        {
            Block newBlockElement = null;

            switch (type)
            {
            case ElementType.Block:
                newBlockElement = new Block();
                break;

            case ElementType.Steelwall:
                new Steelwall(out newBlockElement);
                break;

            case ElementType.Exit:
                new Exit(out newBlockElement);
                break;

            case ElementType.Wall:
                new Wall(out newBlockElement);
                break;

            case ElementType.Mud:
                new Mud(out newBlockElement);
                break;

            case ElementType.Boulder:
                new Boulder(out newBlockElement);
                break;

            case ElementType.Diamond:
                new Diamond(out newBlockElement);
                break;

            case ElementType.Rockfort:
                Rockford rf = new Rockford(out newBlockElement);
                rockfordPos = rf;
                break;

            case ElementType.Firefly:
                new FireFly(out newBlockElement);
                break;
            }

            if (newBlockElement == null)
            {
                throw new Exception();
            }
            else
            {
                return(newBlockElement);
            }
        }
Beispiel #2
0
        public Level createLevel(string path)
        {
            newLine             = false;
            columnIterator      = 0;
            rowIterator         = 0;
            firstBlock          = null;
            lastCreatedBlock    = null;
            firstOfLastRowBlock = null;
            rockfordPos         = null;

            foreach (var line in System.IO.File.ReadAllLines("Resources\\" + path))
            {
                foreach (char c in line)
                {
                    switch (c)
                    {
                    case 'S':
                        connectBlock(blockElementFactory(ElementType.Steelwall));
                        break;

                    case 'B':
                        connectBlock(blockElementFactory(ElementType.Boulder));
                        break;

                    case 'D':
                        connectBlock(blockElementFactory(ElementType.Diamond));
                        break;

                    case 'F':
                        connectBlock(blockElementFactory(ElementType.Firefly));
                        break;

                    case 'M':
                        connectBlock(blockElementFactory(ElementType.Mud));
                        break;

                    case 'R':
                        connectBlock(blockElementFactory(ElementType.Rockfort));
                        break;

                    case 'W':
                        connectBlock(blockElementFactory(ElementType.Wall));
                        break;

                    case ' ':
                        connectBlock(blockElementFactory(ElementType.Block));
                        break;

                    case 'E':
                        connectBlock(blockElementFactory(ElementType.Exit));
                        break;

                    default:
                        break;
                    }
                }
                newLine = true;
            }
            Level returnLevel = new Level();

            returnLevel.Block     = firstBlock;
            returnLevel.rPosition = rockfordPos;
            return(returnLevel);
        }
Beispiel #3
0
        public Tile[,] ReadLevel(int levelNumber)
        {
            char[,] chars = LevelData.GetLevel(levelNumber);
            tiles         = new Tile[LevelData.Level_height, LevelData.Level_width];

            for (int y = 0; y < tiles.GetLength(0); y++)
            {
                for (int x = 0; x < tiles.GetLength(1); x++)
                {
                    switch (chars[y, x])
                    {
                    case 'R':
                        Rockford r = new Rockford(Game);
                        Game.Rockford = r;
                        tiles[y, x]   = new Tile(new Empty(r));
                        tiles[y, x].StaticObject.moveableObject          = Game.Rockford;
                        tiles[y, x].StaticObject.moveableObject.Location = tiles[y, x];
                        break;

                    case 'M':
                        tiles[y, x] = new Tile(new Mud(null));
                        break;

                    case 'B':
                        Boulder b = new Boulder(Game);
                        tiles[y, x] = new Tile(new Empty(b));
                        tiles[y, x].StaticObject.moveableObject.Location = tiles[y, x];
                        Game.moveableObjects.Add(b);
                        break;

                    case 'D':
                        Diamond d = new Diamond(Game);
                        tiles[y, x] = new Tile(new Empty(d));
                        tiles[y, x].StaticObject.moveableObject.Location = tiles[y, x];
                        Game.moveableObjects.Add(d);
                        break;

                    case 'W':
                        tiles[y, x] = new Tile(new Wall(null));
                        break;

                    case 'S':
                        tiles[y, x] = new Tile(new SteelWall(null));
                        break;

                    case 'F':
                        Firefly f = new Firefly(Game);
                        tiles[y, x] = new Tile(new Empty(f));
                        tiles[y, x].StaticObject.moveableObject.Location = tiles[y, x];
                        Game.moveableObjects.Add(f);
                        break;

                    case 'E':
                        Exit ex = new Exit(null);
                        Game.Exit          = ex;
                        tiles[y, x]        = new Tile(ex);
                        Game.Exit.Location = tiles[y, x];
                        break;

                    case 'H':
                        HardenedMud h = new HardenedMud(Game);
                        tiles[y, x] = new Tile(new Empty(h));
                        tiles[y, x].StaticObject.moveableObject.Location = tiles[y, x];
                        Game.moveableObjects.Add(h);
                        break;

                    case 'T':
                        TNT e = new TNT(Game);
                        tiles[y, x] = new Tile(new Empty(e));
                        tiles[y, x].StaticObject.moveableObject.Location = tiles[y, x];
                        Game.moveableObjects.Add(e);
                        break;

                    case ' ':
                        tiles[y, x] = new Tile(new Empty(null));
                        break;

                    default:
                        Console.WriteLine("Unknown tile at y: " + y + " x: " + x);
                        break;
                    }
                }
            }
            CreateLinks(tiles);
            return(tiles);
        }