コード例 #1
0
ファイル: FogOfWar.cs プロジェクト: exallium/DotNetHack
        /// <summary>
        /// FogOfWar
        /// </summary>
        /// <param name="aDungeon"></param>
        public FogOfWar(Dungeon3 aDungeon)
        {
            // Set the linked dungeon.
            FogOfWarDungeon = aDungeon;

            // Mimc the size and shape of the dungeon.
            SeenData = new bool[aDungeon.DungeonWidth, aDungeon.DungeonHeight,
                aDungeon.DungeonDepth];
        }
コード例 #2
0
ファイル: GameEngine.cs プロジェクト: exallium/DotNetHack
        /// <summary>
        /// GameEngine
        /// </summary>
        /// <param name="aPlayer"></param>
        public GameEngine(Player aPlayer, Dungeon3 aStartDungeon)
        {
            Time = new DateTime(1688, 11, 16);
            Player = aPlayer;
            CurrentMap = aStartDungeon;

            // TODO: more junk
            foreach (var m in aStartDungeon.NonPlayerControlled)
                m.WieldedWeapons.CurrentWeapon = new ShortswordOfRending(null);
        }
コード例 #3
0
ファイル: EntryPoint.cs プロジェクト: exallium/DotNetHack
        /// <summary>
        /// Main
        /// </summary>
        /// <param name="args">
        /// A <see cref="System.String[]"/>
        /// </param>
        public static void Main(string[] args)
        {
            // Parse runtime arguments
            R.ParseArgs(args);

            // Initialize graphics
            UI.Graphics.Initialize();

            Dungeon3 d = new Dungeon3(UI.Graphics.ScreenWidth,
                UI.Graphics.ScreenHeight, 10);

            // Create a new game engine
            GameEngine g = new GameEngine(new Player("pete"), d);

            // Run
            GameEngine.EngineRunFlags runFlags =
                GameEngine.EngineRunFlags.Normal;

            // If runtime is setup for debug, set the run flags
            if (R.IsDebug)
                runFlags |= GameEngine.EngineRunFlags.Debug;

            g.Run(runFlags);
        }
コード例 #4
0
 /// <summary>
 /// DungeonRenderer
 /// </summary>
 /// <param name="aDungeon"></param>
 public DungeonRenderer(Dungeon3 aDungeon)
 {
     RenderDungeon = aDungeon;               // must be set first
     RenderBuffer = new Tile[Width, Height];
     ClearBuffer();
 }
コード例 #5
0
ファイル: Editor.cs プロジェクト: exallium/DotNetHack
        /// <summary>
        /// Main
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Parse incoming args for the runtime env.
            R.ParseArgs(args);

            // Load all monsters
            try { Monsters = Persisted.Read<List<Monster>>(R.MonsterFile); }
            catch { UI.Graphics.MessageBox.Show("DNH-Edit", "Monster file not found!"); }

            // Show welcome message.
            UI.Graphics.MessageBox.Show("DNH-Edit", "Welcome to DotNetHack-Editor!");

            // Create a new map with a couple of floors
            CurrentMap = new Dungeon3(UI.Graphics.ScreenWidth, UI.Graphics.ScreenHeight, 3);

            Console.SetWindowSize(UI.Graphics.ScreenWidth, UI.Graphics.ScreenHeight);

            CurrentLocation = new Location3i(UI.Graphics.ScreenCenter);

            // The last unit movement is recorded.
            Location3i LastUnitMovement = Location3i.Origin3i;

            // The default is the "Layout" mode.
            CommandProcessor = ProcessLayoutModeCommands;

            // Set the game engine run flags
            GameEngine.RunFlags = GameEngine.EngineRunFlags.Debug | GameEngine.EngineRunFlags.Editor;

            #region Main Loop
            redo__main_input:
            try
            {
                var inkey = Console.ReadKey();
                Location3i UnitMovement = new Location3i(0, 0, 0);

                switch (inkey.Key)
                {
                    #region Directional Keys
                    case ConsoleKey.LeftArrow:
                        UnitMovement.X--;
                        break;
                    case ConsoleKey.RightArrow:
                        UnitMovement.X++;
                        break;
                    case ConsoleKey.UpArrow:
                        UnitMovement.Y--;
                        break;
                    case ConsoleKey.DownArrow:
                        UnitMovement.Y++;
                        break;
                    case ConsoleKey.PageUp:
                        UnitMovement.D--;
                        break;
                    case ConsoleKey.PageDown:
                        UnitMovement.D++;
                        break;
                    #endregion

                    #region Editor Control Commands
                    case ConsoleKey.Escape:
                        return;
                    case ConsoleKey.F1:
                        {
                            // Show File Menu
                            // (1) Save
                            // (2) Load
                            // (3) Exit

                            break;
                        }
                    case ConsoleKey.F5:

                        // Create a new instance of the game engine with the current location and map.
                        GameEngine g = new GameEngine(new Player("Editor", CurrentLocation),
                            Util.DeepCopy<Dungeon3>(CurrentMap));

                        // Run the full out game engine except with editor and debug run flags.
                        g.Run(GameEngine.EngineRunFlags.Debug | GameEngine.EngineRunFlags.Editor);
                        CurrentMap.DungeonRenderer.HardRefresh(CurrentLocation);
                        break;

                    // generate a new guid.
                    case ConsoleKey.F4:
                        UI.Graphics.CursorToLocation(1, 1);
                        CurrentGuid = Guid.NewGuid();
                        UI.Graphics.MessageBox.Show("Generated New Guid",
                            CurrentGuid.ToString());
                        UI.Graphics.Display.Refresh(CurrentMap, CurrentLocation);
                        break;
                    // Change editor mode to "Layout"
                    case ConsoleKey.F9:
                        EditorMode = DotNetHack.Editor.EditorMode.Layout;
                        UI.Graphics.Display.ShowMessage("Changed to \"{0}\" mode.", EditorMode);
                        break;
                    // Change editor mode to "Items"
                    case ConsoleKey.F10:
                        EditorMode = DotNetHack.Editor.EditorMode.Items;
                        UI.Graphics.CursorToLocation(1, 1);
                        UI.Graphics.Display.ShowMessage("Changed to \"{0}\" mode.", EditorMode);
                        break;
                    case ConsoleKey.F11:
                        EditorMode = DotNetHack.Editor.EditorMode.Monsters;
                        UI.Graphics.Display.ShowMessage("Changed to \"{0}\" mode.", EditorMode);
                        break;
                    #endregion

                    #region Map Load/Save Commands
                    /**
                     * Save
                     */
                    case ConsoleKey.F2:
                        if (ConsoleModifiers.Control == inkey.Modifiers)
                        {
                            if (CurrentMapFileName == null)
                            {
                                UI.Graphics.CursorToLocation(1, 1);
                                Console.Write("Save As: ");
                                CurrentMapFileName = Console.ReadLine();
                            }

                            // save the map, but if this fails say so.
                            CurrentMap.SaveAs(CurrentMapFileName);
                            CurrentMap.DungeonRenderer.HardRefresh(CurrentLocation);
                        }
                        break;
                    /**
                     * Load
                     */
                    case ConsoleKey.F3:
                        if (ConsoleModifiers.Control == inkey.Modifiers)
                        {
                            UI.Graphics.CursorToLocation(1, 1);
                            Console.Write("Load Dungeon: ");
                            string strLoadFile = Console.ReadLine();
                            CurrentMap = Dungeon3.Load(strLoadFile);
                            CurrentMapFileName = strLoadFile;
                            CurrentMap.DungeonRenderer.HardRefresh(CurrentLocation);
                        }
                        break;

                    #endregion
                }

                // Depending on the editor "mode" re-wire the command procesor
                // (kind of like a func pointer)
                switch (EditorMode)
                {
                    case DotNetHack.Editor.EditorMode.Layout:
                        CommandProcessor = ProcessLayoutModeCommands;
                        break;
                    case DotNetHack.Editor.EditorMode.Items:
                        CommandProcessor = ProcessItemModeCommands;
                        break;
                    case DotNetHack.Editor.EditorMode.Monsters:
                        CommandProcessor = ProcessMonsterModeCommands;
                        break;
                }

                // Fire off command processor, be sure to see the switch above
                CommandProcessor(inkey);

                // Record what the last UnitMovement was.
                LastUnitMovement = UnitMovement;

                // Check the boundaries of the dungeon.
                if (!CurrentMap.CheckBounds(CurrentLocation + UnitMovement))
                    goto redo__main_input;

                // Add UnitMovement to the CurrentLocation.
                CurrentLocation += UnitMovement;

                // Render
                CurrentMap.Render(CurrentLocation);

                // Move cursor to current location
                UI.Graphics.CursorToLocation(CurrentLocation);

                // Show the editor "hand"
                Console.Write(EDITOR_GLYPH);

                // CursorToLocation
                UI.Graphics.CursorToLocation(0, UI.Graphics.ScreenHeight - 1);

                Console.Write(CurrentLocation);
            }
            catch (Exception ex)
            {
                UI.Graphics.MessageBox.Show("DNH-Edit Exception", ex);
                UI.Graphics.Display.Refresh(CurrentMap, CurrentLocation);
            }

            // jump back to main input
            goto redo__main_input;

            #endregion
        }