Inheritance: Microsoft.Xna.Framework.DrawableGameComponent
Exemple #1
0
        public static void InitializeConsole(Game game, Dungeon dungeon, IEnumerable<ICommandFactory<ConsoleContext<Dungeon>>> thirdPartyFactories)
        {
            if (Instance != null)
                throw new InvalidOperationException($"Cannont create multiple instances of {Instance.GetType()}. Instead access instance through {nameof(Instance)}");

            Instance = new GameConsole(game, dungeon, thirdPartyFactories);
        }
Exemple #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            ResourceProvider.Instance.Initialize(GraphicsDevice, Content);
            dungeon = new Dungeon(this, new LegacyMapBuilder()) { DrawOrder = 0 };
            GameConsole.InitializeConsole(this, dungeon);
            GameConsole.Instance.DrawOrder = 1;
        }
Exemple #3
0
        public DungeonLevel(Dungeon d, IEnumerable<Tile> t, IEnumerable<Creature> creatures, int levelIndex, IReadOnlyDictionary<Point,Tile> positions, Tile startTile, Texture2D minimap)
        {
            TilesPositions = positions;

            dungeon = d;
            Tiles = t;
            StartTile = startTile;
            LevelIndex = levelIndex;
            MiniMap = minimap;
            Creatures = creatures;
        }
Exemple #4
0
        private GameConsole(Game game, Dungeon dungeon, IEnumerable<ICommandFactory<ConsoleContext<Dungeon>>> thirdPartyFactories) : base(game)
        {
            In = new StreamReader(input = new KeyboardStream());
            var s = new StreamWriter(ouput = new ScreenStream())
            { AutoFlush = true };
            Out = s;
            interpreter = new BaseInterpreter(defaultFactories.Concat(thirdPartyFactories), In, Out, input)
            { ConsoleContext = new ConsoleContext<Dungeon>(defaultFactories.Concat(thirdPartyFactories), dungeon) };
            new Action(async () =>
            {
                await interpreter.Run();
                return;
            })();

            LoadResources();
            game.Components.Add(this);
        }
        public override DungeonLevel GetLevel(int level, Dungeon dungeon, Point? startTile)
        {
            DungeonLevel dungeonLevel = null;
            if (Data.Maps.Count <= level)
                throw new ArgumentException("Level does not exist.");
            if (loadedLevels.TryGetValue(level, out dungeonLevel))
                return dungeonLevel;

            Initialize(level, startTile);
            stack.Push(new TileInfo<TileData>
            {
                Position = start,
                Tile = CurrentMap[start.X, start.Y]
            });
            bitMap[start.X, start.Y] = true;

            while (stack.Count > 0)
            {
                currentTile = stack.Pop();
                var nextTiles = CreateTile(currentTile).Where(t => t.Tile != null && t.Tile.GetType() != typeof(WallTileData) && !bitMap[t.Position.X, t.Position.Y]);

                foreach (var t in nextTiles) //recursion
                {
                    stack.Push(t);
                    bitMap[t.Position.X, t.Position.Y] = true;
                }
            }

            SetupNeighbours(TilesPositions, outputTiles);
            SetupItems();

            dungeonLevel = new DungeonLevel(dungeon, outputTiles, creatures, level, TilesPositions, TilesPositions[start], legacyTileCreator.MiniMap);
            loadedLevels.Add(level, dungeonLevel);
            return dungeonLevel;
        }
Exemple #6
0
 public abstract DungeonLevel GetLevel(int i, Dungeon dungeon, Point? startTile);
Exemple #7
0
        public override DungeonLevel GetLevel(int i, Dungeon dungeon, Point? startTile)
        {
            var tiles = new List<Tile>();

            if (i == 0)
            {
                tiles.Add(new Floor(new Vector3(0, 0, 2)));

                tiles.Add(new Stairs(new Vector3(2, 0, -3), false, true));
                tiles.Add(new Floor(new Vector3(2, 0, -2)));
                tiles.Add(new Floor(new Vector3(3, 0, -2)));
                tiles.Add(new Floor(new Vector3(3, 0, -1)));
                tiles.Add(new Floor(new Vector3(3, 0, 0)));
                tiles.Add(new Floor(new Vector3(4, 0, 0)));
                tiles.Add(new Floor(new Vector3(5, 0, 0)));
                tiles.Add(new Floor(new Vector3(6, 0, 0)));
                tiles.Add(new Floor(new Vector3(7, 0, 0)));
                tiles.Add(new Floor(new Vector3(8, 0, 0)));
                tiles.Add(new Floor(new Vector3(6, 0, -1)));
                tiles.Add(new Floor(new Vector3(6, 0, -2)));
                //Tiles.Add(new Floor(new Vector3(0, 0, 0), CubeFaces.Sides ^ CubeFaces.Back ^ CubeFaces.Left));
                tiles.Add(new Stairs(new Vector3(0, 0, 1), false, false));
                tiles.Add(new Floor(new Vector3(-1, 0, 2) ));
                tiles.Add(new Stairs(new Vector3(-2, 0, 2), true, true));
                tiles.Add(new Stairs(new Vector3(5, 0, -2), true, false));
            }
            else
            {
                tiles.Add(new Stairs(new Vector3(2, -1, -3)));
                tiles.Add(new Floor(new Vector3(1, -1, -3)));
                tiles.Add(new Floor(new Vector3(1, -1, -2)));
                tiles.Add(new Floor(new Vector3(1, -1, -1)));
                tiles.Add(new Floor(new Vector3(1, -1, 0)));
                tiles.Add(new Floor(new Vector3(0, -1, -1)));
                tiles.Add(new Floor(new Vector3(-1, -1, -1)));
                tiles.Add(new Floor(new Vector3(0, -1, 0)));

                tiles.Add(new Stairs(new Vector3(0, -1, 1)));
                tiles.Add(new Floor(new Vector3(-2, -1, -1)));

                tiles.Add(new Floor(new Vector3(-2, -1, 0)));
                tiles.Add(new Floor(new Vector3(-2, -1, 1)));
                tiles.Add(new Stairs(new Vector3(-2, -1, 2)));
                tiles.Add(new Floor(new Vector3(2, -1, 0)));
                tiles.Add(new Floor(new Vector3(3, -1, 0)));
                tiles.Add(new Floor(new Vector3(4, -1, 0)));
                tiles.Add(new Floor(new Vector3(4, -1, -1)));
                tiles.Add(new Floor(new Vector3(4, -1, -2)));
                tiles.Add(new Stairs(new Vector3(5, -1, -2)));
            }

            //if (i == 0)
            //{
            //    Tiles.Add(new Floor(new Vector3(0, 0, 2), CubeFaces.Sides ^ CubeFaces.Back ^ CubeFaces.Left));

            //    Tiles.Add(new Stairs(new Vector3(0, 0, -3), false, true));
            //    Tiles.Add(new Floor(new Vector3(0, 0, -2), CubeFaces.Sides ^ CubeFaces.Back  ^ CubeFaces.Right));
            //    Tiles.Add(new Floor(new Vector3(1, 0, -2), CubeFaces.Sides ^ CubeFaces.Left ^ CubeFaces.Right));
            //    //Tiles.Add(new Floor(new Vector3(0, 0, 0), CubeFaces.Sides ^ CubeFaces.Back ^ CubeFaces.Left));
            //    Tiles.Add(new Stairs(new Vector3(0, 0, 1), false, false));
            //    Tiles.Add(new Floor(new Vector3(-1, 0, 2), CubeFaces.Sides ^ CubeFaces.Right ^ CubeFaces.Left));
            //    Tiles.Add(new Stairs(new Vector3(-2, 0, 2), true, true));
            //}
            //else
            //{
            //    Tiles.Add(new Stairs(new Vector3(0, -1, -3)));
            //    Tiles.Add(new Floor(new Vector3(1, -1, -3), CubeFaces.Sides ^ CubeFaces.Left ^ CubeFaces.Front));
            //    Tiles.Add(new Floor(new Vector3(1, -1, -2), CubeFaces.Sides ^ CubeFaces.Front ^ CubeFaces.Back));
            //    Tiles.Add(new Floor(new Vector3(1, -1, -1), CubeFaces.Sides ^ CubeFaces.Left ^ CubeFaces.Front ^ CubeFaces.Back));
            //    Tiles.Add(new Floor(new Vector3(1, -1, 0), CubeFaces.Sides ^ CubeFaces.Left ^ CubeFaces.Back));
            //    Tiles.Add(new Floor(new Vector3(0, -1, -1), CubeFaces.Sides ^ CubeFaces.Left ^ CubeFaces.Right ^ CubeFaces.Front));
            //    Tiles.Add(new Floor(new Vector3(-1, -1, -1), CubeFaces.Sides ^ CubeFaces.Left ^ CubeFaces.Right ));
            //    Tiles.Add(new Floor(new Vector3(0, -1, 0), CubeFaces.Sides ^ CubeFaces.Front ^ CubeFaces.Back ^ CubeFaces.Right));

            //    Tiles.Add(new Stairs(new Vector3(0, -1, 1)));
            //    Tiles.Add(new Floor(new Vector3(-2, -1, -1), CubeFaces.Sides ^ CubeFaces.Right ^ CubeFaces.Front));

            //    Tiles.Add(new Floor(new Vector3(-2, -1, 0), CubeFaces.Sides ^ CubeFaces.Back ^ CubeFaces.Front));
            //    Tiles.Add(new Floor(new Vector3(-2, -1, 1), CubeFaces.Sides ^ CubeFaces.Back ^ CubeFaces.Front));
            //    Tiles.Add(new Stairs(new Vector3(-2, -1, 2)));
            //}

            var tilePositions = new Dictionary<Point, Tile>();

            foreach (var t in tiles)            
                tilePositions.Add(t.GridPosition, t);

            SetupNeighbours(tilePositions, tiles);

            return new DungeonLevel(dungeon, tiles, new Creature[0], i, tilePositions, tiles.FirstOrDefault(), null);

        }
Exemple #8
0
 public static void InitializeConsole(Game game, Dungeon dungeon) => InitializeConsole(game, dungeon, new ICommandFactory<ConsoleContext<Dungeon>>[0]);