Exemple #1
0
        private int Run()
        {
            if (StateCount <= 0)
            {
                Window win = new Window(new WindowTemplate());
                Push(win);
            }

            while (!TCODConsole.isWindowClosed() && !IsQuitting)
            {
                var newUpdateMilli    = TCODSystem.getElapsedMilli();
                var elapsedUpdateTime = newUpdateMilli - _lastUpdateMilli;
//				if (elapsedUpdateTime > upsFrameLength) {
                _lastUpdateMilli = newUpdateMilli;
                Update(elapsedUpdateTime);
//				}

                var newDrawMilli    = TCODSystem.getElapsedMilli();
                var elapsedDrawTime = newDrawMilli - _lastDrawMilli;
//				if (elapsedDrawTime > fpsFrameLength) {
                _lastDrawMilli = newDrawMilli;
                Draw(elapsedDrawTime);
//				}
            }

            return(0);
        }
Exemple #2
0
        public void Start()
        {
            isRunning = true;
            while (isRunning)
            {
                // Check for scene change
                if (sceneChanged)
                {
                    CurrentScene = newScene;
                    newScene     = null;
                    sceneChanged = false;
                }

                // Check if the game is still running.
                if (TCODConsole.isWindowClosed() || CurrentScene == null)
                {
                    Stop();
                    break;
                }

                // Update
                CurrentScene.Update(TCODSystem.getLastFrameLength());

                // Render
                TCODConsole.root.clear();
                CurrentScene.Render(TCODSystem.getLastFrameLength());
                TCODConsole.flush();

                // Handle user input
                CheckForKeyboardEvents();
                CheckForMouseEvents();
            }
            CleanUp();
        }
Exemple #3
0
 public void Play()
 {
     Console.WriteLine("Welcome to Z-Day!");
     while (!Over && !TCODConsole.isWindowClosed())
     {
         Draw();
         Update();
     }
 }
 public void RunGame()
 {
     _model.CommitChanges();
     do
     {
         TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
         _logic.RunCurrentState();
     } while (!_exitGame && !TCODConsole.isWindowClosed());
 }
Exemple #5
0
 public void run()
 {
     while (!TCODConsole.isWindowClosed() && !gameEnd)
     {
         draw();
         input();
         process();
     }
     end();
 }
Exemple #6
0
        // Handle the main menu keypresses
        public char HandleMainMenu()
        {
            // Wait for a keypress
            TCODKey key = new TCODKey();

            do
            {
                // Get the keypress
                TCODConsole.flush();
                key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (key.Character == 'S' || key.Character == 's' ||
                    key.Character == 'C' || key.Character == 'c' ||
                    key.Character == 'Q' || key.Character == 'q')
                {
                    string characterPressed = key.Character.ToString().ToUpper();
                    return(characterPressed[0]);
                }
                else if (key.KeyCode == TCODKeyCode.Up || key.KeyCode == TCODKeyCode.KeypadEight)
                {
                    if (currentMenuOption != MenuOption.Start)
                    {
                        currentMenuOption--;
                        return(' ');
                    }
                    else
                    {
                        currentMenuOption = MenuOption.Quit;
                        return(' ');
                    }
                }
                else if (key.KeyCode == TCODKeyCode.Down || key.KeyCode == TCODKeyCode.KeypadTwo)
                {
                    if (currentMenuOption != MenuOption.Quit)
                    {
                        currentMenuOption++;
                        return(' ');
                    }
                    else
                    {
                        currentMenuOption = MenuOption.Start;
                        return(' ');
                    }
                }
                else if (key.KeyCode == TCODKeyCode.KeypadEnter || key.KeyCode == TCODKeyCode.Enter)
                {
                    string KeyCodes = "SCQ";
                    return(KeyCodes[(int)currentMenuOption]);
                }

                PrintMainMenu();
            }while (!TCODConsole.isWindowClosed());
            return(' ');
        }
Exemple #7
0
        private string getInput(string initial)
        {
            string s = initial;

            Message.Write(s);
            while (true && !TCODConsole.isWindowClosed())
            {
                engine.key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
                engine.render();
                TCODConsole.flush();

                if (engine.key.KeyCode == TCODKeyCode.Enter)
                {
                    break;
                }
                if (engine.key.KeyCode == TCODKeyCode.Backspace)
                {
                    if (s.Length > 0)
                    {
                        s = s.Remove(s.Length - 1);
                        Message.unwriteLastChar();
                    }
                }
                if (engine.key.KeyCode == TCODKeyCode.Up)
                {
                    if (s != "")
                    {
                        record[index] = s;
                    }
                    s = "up";
                    break;
                }
                if (engine.key.KeyCode == TCODKeyCode.Down)
                {
                    if (s != "")
                    {
                        record[index] = s;
                    }
                    s = "down";
                    break;
                }
                if (!char.IsControl(engine.key.Character))
                {
                    Message.Write(engine.key.Character.ToString());
                    s += engine.key.Character;
                    if (engine.key.Character == '|')
                    {
                        break;
                    }
                }
            }
            return(s);
        }
Exemple #8
0
 public void Update()
 {
     do
     {
         TCODConsole.flush();
         _currentInput = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
         if (TCODConsole.isWindowClosed())
         {
             Environment.Exit(0);
         }
     } while (_currentInput.KeyCode == TCODKeyCode.NoKey);
 }
Exemple #9
0
        static void Main(string[] args)
        {
            const int ScreenHeight = 35;
            const int ScreenWidth  = 80;

            // Set up the main window
            //Window rootWindow = new Window("Md_curses_16x16.png", ScreenWidth, ScreenHeight, "Stygia: The Hidden Depths");
            Window rootWindow = new Window("font_16x16.png", ScreenWidth, ScreenHeight, "Stygia: The Hidden Depths");

            // Display the title screen and wait for a keypress
            rootWindow.ClearScreen();
            rootWindow.DisplayTitleScreen();
            rootWindow.WaitForAnyKeyPress();

            // Then display the main menu
            rootWindow.ClearScreen();
            rootWindow.DisplayMainMenu();

            // Handle main menu keypresses
            bool canQuit = false;

            do
            {
                TCODConsole.flush();
                char keypress = rootWindow.HandleMainMenu();

                switch (keypress)
                {
                case 'S':
                    rootWindow.ClearScreen();
                    rootWindow.DisplayIntro();
                    rootWindow.WaitForAnyKeyPress();
                    rootWindow.ClearScreen();
                    Game newgame = new Game(rootWindow, true);
                    newgame.Start(rootWindow);
                    rootWindow.DisplayMainMenu();
                    break;

                case 'C':
                    rootWindow.ClearScreen();
                    Game oldgame = new Game(rootWindow, false);
                    oldgame.Start(rootWindow);
                    rootWindow.DisplayMainMenu();
                    break;

                case 'Q':
                    rootWindow.ClearScreen();
                    canQuit = true;
                    break;
                }
            }while (!TCODConsole.isWindowClosed() && !canQuit);
        }
Exemple #10
0
        static void Main()
        {
            TCODConsole.initRoot(80, 61, "Lights Out");
            TCODSystem.setFps(100);
            TCODConsole.setKeyboardRepeat(250, 100);
            Game game = new Game();

            game.Draw();
            while (!TCODConsole.isWindowClosed() && !game.Exit)
            {
                game.Update();
            }
        }
Exemple #11
0
        /// <summary>
        /// Starts the game simulation and set off the normal update life cycle
        /// </summary>
        /// <returns> A code corresponding to how the game exited: 0 = normal quit </returns>
        public int Run()
        {
            if (mainConsole == null || isRunning)
            {
                return(APPLICATION_EXIT_ERROR);
            }

            isRunning = true;
            internalTimer.Start();

            // Main update loop
            while (!TCODConsole.isWindowClosed() && isRunning)
            {
                long current   = internalTimer.ElapsedMilliseconds;
                long frameTime = current - previousUpdateTime;
                previousUpdateTime = current;

                frameLag += frameTime;

                // Actual update / console drawing runs on an inner catchup loop that is also interuptable
                // will run catchup frames or delay so that it closely matches desired FRAME_RATE, that
                // is also synced with the TCODConsoles own render frame rate
                while (frameLag >= MS_PER_UPDATE &&
                       !TCODConsole.isWindowClosed() && isRunning)
                {
                    // TCOD must be flushed immedietly before polling the input channels
                    TCODConsole.flush();
                    lastKey   = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
                    mouseData = TCODMouse.getStatus();

                    // Handle transitions between states
                    if (gotoNewState)
                    {
                        EnteredNewState(nextState);
                        gotoNewState = false;
                    }

                    Update();
                    Render();

                    // always allow for core update interrupt
                    if (lastKey.KeyCode == TCODKeyCode.F4)
                    {
                        isRunning = false;
                    }
                }
            }

            internalTimer.Stop();
            return(APPLICATION_EXIT_NORMAL);
        }
Exemple #12
0
        public static int Main()
        {
            Console.WriteLine("Started Game");
            TCODSystem.setFps(30);
            engine.initialize(false);
            while (!TCODConsole.isWindowClosed() && !exit)
            {
                engine.update();
                engine.render();
            }



            Console.WriteLine("Game exited with code " + exitCode.ToString());
            return(exitCode);
        }
Exemple #13
0
        // /////////////////////////////////////////////////////////////////////////////////
        #endregion
        #region Private
        // /////////////////////////////////////////////////////////////////////////////////
        private int Run()
        {
            if (CurrentWindow == null)
            {
                Window win = new Window(new WindowTemplate());
                SetWindow(win);
            }

            while (!TCODConsole.isWindowClosed() && !IsQuitting)
            {
                Update();
                Draw();
            }

            return(0);
        }
Exemple #14
0
        static void Main()
        {
            TCODConsole.initRoot(80, 50, "my game", false);
            TCODSystem.setFps(25);
            bool endGame = false;

            while (!endGame && !TCODConsole.isWindowClosed())
            {
                TCODConsole.root.print(0, 0, "Hello, world");
                TCODConsole.flush();
                var key = TCODConsole.checkForKeypress();

                if (key.KeyCode == TCODKeyCode.Escape)
                {
                    endGame = true;
                }
            }
        }
Exemple #15
0
        public void run(Screen tempscreen)
        {
            screen    = tempscreen;
            kbHistory = new List <KeyHistory>();

            TimeSpan startTime = DateTime.Now.TimeOfDay;
            double   timectrl  = startTime.TotalMilliseconds;
            double   timespent = 0;

            while (running && !TCODConsole.isWindowClosed())
            {
                screen.update();
                screen.printDebug();
                terminalManager.drawTerminals(debug);

                TCODConsole.flush();

                KeyHistory temp = new KeyHistory(DateTime.Now.TimeOfDay - startTime);

                TCODKey key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                temp.RegisterKeyStatus(key, TCODKeyStatus.KeyPressed);

                kbHistory.Add(temp);
                screen = screen.respondToUserInput(kbHistory);

                timespent = DateTime.Now.TimeOfDay.TotalMilliseconds - timectrl;


                if (timespent > 250)
                {
                    adjustFPS();
                    timectrl = DateTime.Now.TimeOfDay.TotalMilliseconds;
                }
            }
        }
Exemple #16
0
        private bool getInputPos(out Point p)
        {
            string ps = "";

            p = new Point();
            int       oldX = 0, oldY = 0;
            TCODColor oldC = TCODConsole.root.getCharBackground(0, 0);

            while (true && !TCODConsole.isWindowClosed())
            {
                engine.mousedata = TCODMouse.getStatus();
                engine.key       = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
                engine.render(false);

                TCODConsole.root.setCharBackground(engine.mousedata.CellX, engine.mousedata.CellY, TCODColor.white);
                if (engine.mousedata.CellX != oldX || engine.mousedata.CellY != oldY)
                {
                    TCODConsole.root.setCharBackground(oldX, oldY, oldC);
                    oldC = TCODConsole.root.getCharBackground(engine.mousedata.CellX, engine.mousedata.CellY);

                    oldX = engine.mousedata.CellX;
                    oldY = engine.mousedata.CellY;
                }
                TCODConsole.flush();
                if (Engine.Engine.useMouse)
                {
                    p.X = engine.mousedata.CellX;
                    p.Y = engine.mousedata.CellY;
                    if (engine.mousedata.LeftButtonPressed)
                    {
                        p.X = engine.mousedata.CellX + engine.map.offsetX;
                        p.Y = engine.mousedata.CellY + engine.map.offsetY;
                        return(true);
                    }
                }

                if (engine.key.KeyCode == TCODKeyCode.Enter)
                {
                    break;
                }
                if (char.IsLetterOrDigit(engine.key.Character) || engine.key.Character == ',')
                {
                    Message.Write(engine.key.Character.ToString());
                    ps += engine.key.Character;
                }
                if (engine.key.KeyCode == TCODKeyCode.Backspace)
                {
                    if (ps.Length > 0)
                    {
                        ps.Remove(ps.Length - 1);
                        Message.unwriteLastChar();
                    }
                }
            }


            if (ps == "here")
            {
                p.X = engine.player.x;
                p.Y = engine.player.y;
                return(true);
            }

            try
            {
                string[] coords = ps.Split(',');
                p = new Point(int.Parse(coords[0]), int.Parse(coords[1]));
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Message.WriteLine("Incorrect position");
                return(false);
            }
        }
Exemple #17
0
        public void growMaze(int x, int y)
        {
            TCODRandom   rng     = TCODRandom.getInstance();
            List <Point> cells   = new List <Point>();
            Direction    lastDir = Direction.NULL;

            map.dig(x, y, x, y);

            cells.Add(new Point(x, y));

            while (cells.Count > 0 && !TCODConsole.isWindowClosed())
            // for(int j = 0; j < 10; j ++)
            {
                if (cells.Count > 0)
                {
                    if (cells.Count > 1000)
                    {
                    }
                    Point            cell        = cells.Last();
                    List <Direction> unmadeCells = new List <Direction>();
                    foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                    {
                        if (dir != Direction.NULL)
                        {
                            if (canDig(cell.X, cell.Y, dir))
                            {
                                unmadeCells.Add(dir);
                            }
                            else
                            {
                                Point p = dirToPoint(dir);
                            }
                        }
                    }
                    if (unmadeCells.Count > 0)
                    {
                        if (unmadeCells.Count > 10000)
                        {
                        }
                        Direction dir = Direction.NULL;

                        if (unmadeCells.Contains(lastDir) && rng.getInt(0, 100) > windingPercent)
                        {
                            dir = lastDir;
                        }
                        else
                        {
                            dir = unmadeCells[rng.getInt(0, unmadeCells.Count - 1)];
                        }
                        Point p = dirToPoint(dir);
                        //map.dig(cell.X + p.X, cell.Y + p.Y, cell.X + p.X * 2, cell.Y + p.Y * 2);
                        carve(cell.X + p.X, cell.Y + p.Y);
                        carve(cell.X + p.X * 2, cell.Y + p.Y * 2);
                        // cells.Add(new Point(cell.X + p.X, cell.Y + p.Y));
                        cells.Add(new Point(cell.X + p.X * 2, cell.Y + p.Y * 2));
                        lastDir = dir;
                    }
                    else
                    {
                        cells.Remove(cells.Last());
                        lastDir = Direction.NULL;
                    }
                }
            }
        }
Exemple #18
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (CurrentDomain_UnhandledException);
            TCODColor fogOfWarColour = new TCODColor(80, 80, 80);

            int horizontalPixels, verticalPixels;

            TCODSystem.getCurrentResolution(out horizontalPixels, out verticalPixels);

            //string font = "celtic_garamond_10x10_gs_tc.png";
            string font = "arial12x12.png";

            TCODConsole.setCustomFont(
                font,
                (int)(TCODFontFlags.Grayscale | TCODFontFlags.LayoutTCOD),
                32,
                8);

            int fontWidth, fontHeight;

            TCODSystem.getCharSize(out fontWidth, out fontHeight);

            int screenWidth  = horizontalPixels / fontWidth;
            int screenHeight = verticalPixels / fontHeight;



            var screenBounds = new Rectangle(0, 0, screenWidth,
                                             screenHeight);

            int infoPanelWidth = 42;
            var playBounds     = new Rectangle(0, 0, screenBounds.Width - infoPanelWidth, screenBounds.Height);
            var playerBounds   = new Rectangle(playBounds.Right, 0, infoPanelWidth, 6);
            //var threatBounds = new Rectangle(playBounds.Right, playerBounds.Bottom, infoPanelWidth, 10);
            var competitorBounds = new Rectangle(playBounds.Right, playerBounds.Bottom, infoPanelWidth, 27);
            var eventBounds      = new Rectangle(playBounds.Right, competitorBounds.Bottom, infoPanelWidth,
                                                 screenBounds.Height -
                                                 (playerBounds.Height + competitorBounds.Height));

            Game game = CreateGame();

            Logger.Info("Initializing RootConsole...");

            TCODConsole.initRoot(screenBounds.Width, screenBounds.Height, "Last Man Standing v1.0", true, TCODRendererType.SDL);

            TCODSystem.setFps(30);
            var rootConsole = TCODConsole.root;

            rootConsole.setForegroundColor(ColorPresets.White);
            rootConsole.setAlignment(TCODAlignment.LeftAlignment);
            rootConsole.setBackgroundFlag(TCODBackgroundFlag.Set);

            Logger.Info("Initializing playConsole...");
            TCODConsole playConsole = new TCODConsole(playBounds.Width, playBounds.Height);

            //Logger.Info("Initializing threatConsole...");
            //Console threatConsole = RootConsole.GetNewConsole(threatBounds.Width, threatBounds.Height);
            Logger.Info("Initializing playerConsole...");
            TCODConsole playerConsole = new TCODConsole(playerBounds.Width, playerBounds.Height);

            Logger.Info("Initializing competitorConsole...");
            TCODConsole competitorConsole = new TCODConsole(competitorBounds.Width, competitorBounds.Height);

            Logger.Info("Initializing eventsConsole...");
            TCODConsole eventsConsole = new TCODConsole(eventBounds.Width, eventBounds.Height);

            Logger.Info("Starting Game Loop...");
            do
            {
                TCODKey keyStroke = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (game.IsActive)
                {
                    game.ProcessTurn();

                    if (keyStroke.KeyCode != TCODKeyCode.NoKey)
                    {
                        ((PlayerAI)game.Player.Intellect).EvaluateKeyPress(keyStroke);
                    }
                }

                RenderAllConsoles(game, rootConsole, playConsole, fogOfWarColour, playerConsole,
                                  competitorConsole, eventsConsole, playBounds, playerBounds,
                                  competitorBounds, eventBounds);

                if (!game.IsActive)
                {
                    rootConsole.printEx((screenBounds.Width - 30) / 2, (screenBounds.Height - 10) / 2, TCODBackgroundFlag.Set,
                                        TCODAlignment.LeftAlignment, "Press SPACE to start a new game. Press ESC to quit.");
                    if (keyStroke.KeyCode == TCODKeyCode.Space)
                    {
                        rootConsole.print(1, 1, "Creating new game...");
                        TCODConsole.flush();
                        game = CreateGame();
                    }
                }

                TCODConsole.flush();

                if (keyStroke.KeyCode == TCODKeyCode.Escape)
                {
                    return;
                }
            } while (!TCODConsole.isWindowClosed());
        }
Exemple #19
0
        // Handle standard keypresses
        public char WaitForKeyPress(KeyMode keymode)
        {
            // Wait for a keypress
            TCODKey key = new TCODKey();

            // This needs to be rewritten!
            if (keymode == KeyMode.Exploration)
            {
                do
                {
                    // Get the keypress
                    TCODConsole.flush();
                    key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                    if (key.Character == 'H' || key.Character == 'h' ||
                        key.Character == 'J' || key.Character == 'j' ||
                        key.Character == 'K' || key.Character == 'k' ||
                        key.Character == 'L' || key.Character == 'l' ||
                        key.Character == 'Y' || key.Character == 'y' ||
                        key.Character == 'U' || key.Character == 'u' ||
                        key.Character == 'B' || key.Character == 'b' ||
                        key.Character == 'N' || key.Character == 'n' ||
                        key.Character == 'S' || key.Character == 's' ||
                        key.Character == 'G' || key.Character == 'g' ||
                        key.Character == 'I' || key.Character == 'i' ||
                        key.Character == 'D' || key.Character == 'd' ||
                        key.Character == 'W' || key.Character == 'w' ||
                        key.Character == 'T' || key.Character == 't' ||
                        key.Character == 'X' || key.Character == 'x' ||
                        key.Character == 'V' || key.Character == 'v' ||
                        key.Character == 'Q' || key.Character == 'q' ||
                        key.Character == '>' ||
                        key.Character == '?' ||
                        key.Character == '.' ||
                        key.KeyCode == TCODKeyCode.Up ||
                        key.KeyCode == TCODKeyCode.Down ||
                        key.KeyCode == TCODKeyCode.Left ||
                        key.KeyCode == TCODKeyCode.Right ||
                        key.KeyCode == TCODKeyCode.Escape ||
                        key.KeyCode == TCODKeyCode.KeypadOne ||
                        key.KeyCode == TCODKeyCode.KeypadTwo ||
                        key.KeyCode == TCODKeyCode.KeypadThree ||
                        key.KeyCode == TCODKeyCode.KeypadFour ||
                        key.KeyCode == TCODKeyCode.KeypadSix ||
                        key.KeyCode == TCODKeyCode.KeypadSeven ||
                        key.KeyCode == TCODKeyCode.KeypadEight ||
                        key.KeyCode == TCODKeyCode.KeypadNine
                        )
                    {
                        if (key.KeyCode == TCODKeyCode.Up || key.KeyCode == TCODKeyCode.KeypadEight)
                        {
                            key.Character = 'K';
                        }
                        else if (key.KeyCode == TCODKeyCode.Down || key.KeyCode == TCODKeyCode.KeypadTwo)
                        {
                            key.Character = 'J';
                        }
                        else if (key.KeyCode == TCODKeyCode.Left || key.KeyCode == TCODKeyCode.KeypadFour)
                        {
                            key.Character = 'H';
                        }
                        else if (key.KeyCode == TCODKeyCode.Right || key.KeyCode == TCODKeyCode.KeypadSix)
                        {
                            key.Character = 'L';
                        }
                        else if (key.KeyCode == TCODKeyCode.KeypadSeven)
                        {
                            key.Character = 'Y';
                        }
                        else if (key.KeyCode == TCODKeyCode.KeypadNine)
                        {
                            key.Character = 'U';
                        }
                        else if (key.KeyCode == TCODKeyCode.KeypadOne)
                        {
                            key.Character = 'B';
                        }
                        else if (key.KeyCode == TCODKeyCode.KeypadThree)
                        {
                            key.Character = 'N';
                        }

                        string characterPressed = key.Character.ToString().ToUpper();
                        return(characterPressed[0]);
                    }
                }while (!TCODConsole.isWindowClosed());
                return(' ');
            }
            else if (keymode == KeyMode.Inventory)
            {
                do
                {
                    // Get the keypress
                    TCODConsole.flush();
                    key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                    if (key.KeyCode == TCODKeyCode.Escape)
                    {
                        string characterPressed = key.Character.ToString().ToUpper();
                        return('#');
                    }
                    else
                    {
                        char keyPressed = Convert.ToChar(key.Character.ToString());
                        if (char.IsLetter(keyPressed))
                        {
                            string characterPressed = key.Character.ToString().ToUpper();
                            return(characterPressed[0]);
                        }
                    }
                }while (!TCODConsole.isWindowClosed());
                return(' ');
            }
            else if (keymode == KeyMode.Drop || keymode == KeyMode.Wear || keymode == KeyMode.Takeoff || keymode == KeyMode.Activate)
            {
                do
                {
                    // Get the keypress
                    TCODConsole.flush();
                    key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                    if (key.KeyCode == TCODKeyCode.Escape)
                    {
                        string characterPressed = key.Character.ToString().ToUpper();
                        return('#');
                    }
                    else
                    {
                        char keyPressed = Convert.ToChar(key.Character.ToString());
                        if (char.IsLetter(keyPressed))
                        {
                            string characterPressed = key.Character.ToString().ToUpper();
                            return(characterPressed[0]);
                        }
                    }
                }while (!TCODConsole.isWindowClosed());
                return(' ');
            }
            else if (keymode == KeyMode.ItemDetails)
            {
                do
                {
                    // Get the keypress
                    TCODConsole.flush();
                    key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                    if (key.KeyCode == TCODKeyCode.Escape)
                    {
                        return(' ');
                    }
                }while (!TCODConsole.isWindowClosed());
                return(' ');
            }
            else
            {
                return(' ');
            }
        }
Exemple #20
0
        private void input()
        {
            bool moveon = false;

            while (!moveon && !TCODConsole.isWindowClosed())
            {
                TCODKey key = TCODConsole.waitForKeypress(true);

                switch (key.KeyCode)
                {
                case TCODKeyCode.Up:
                case TCODKeyCode.KeypadEight:
                    if (player.getPlayerY() > 0 && currentMap.getPassable(player.getPlayerX(), player.getPlayerY() - 1))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX(), player.getPlayerY() - 1))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() && tempMon.getY() == player.getPlayerY() - 1)
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerY(player.getPlayerY() - 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.Down:
                case TCODKeyCode.KeypadTwo:
                    if (player.getPlayerY() < 39 && currentMap.getPassable(player.getPlayerX(), player.getPlayerY() + 1))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX(), player.getPlayerY() + 1))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() && tempMon.getY() == player.getPlayerY() + 1)
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerY(player.getPlayerY() + 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.Left:
                case TCODKeyCode.KeypadFour:
                    if (player.getPlayerX() > 0 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY()))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY()))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY())
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerX(player.getPlayerX() - 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.Right:
                case TCODKeyCode.KeypadSix:
                    if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY()))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY()))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY())
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerX(player.getPlayerX() + 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.KeypadSeven:
                    if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY() - 1))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY() - 1))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY() - 1)
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerX(player.getPlayerX() - 1);
                        player.setPlayerY(player.getPlayerY() - 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.KeypadNine:
                    if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY() - 1))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY() - 1))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY() - 1)
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerX(player.getPlayerX() + 1);
                        player.setPlayerY(player.getPlayerY() - 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.KeypadOne:
                    if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY() + 1))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY() + 1))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY() + 1)
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerX(player.getPlayerX() - 1);
                        player.setPlayerY(player.getPlayerY() + 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.KeypadThree:
                    if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY() + 1))
                    {
                        if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY() + 1))
                        {
                            Object[] temp = currentMap.getMonsters();
                            for (int i = 0; i < temp.Length; i++)
                            {
                                Monster tempMon = (Monster)temp[i];
                                if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY() + 1)
                                {
                                    tempMon.reduceHealth(executePlayerAttack(tempMon));
                                }
                            }
                            moveon = true;
                            break;
                        }
                        player.setPlayerX(player.getPlayerX() + 1);
                        player.setPlayerY(player.getPlayerY() + 1);
                        moveon = true;
                    }
                    break;

                case TCODKeyCode.Char:
                    switch (key.Character)
                    {
                    case 'q':
                        if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null)
                        {
                            if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsWeapon())
                            {
                                textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold");
                                player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality());
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                            else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsArmor())
                            {
                                textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold");
                                player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality());
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                            else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsGold())
                            {
                                textBox.Add("You picked up " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold");
                                player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality());
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                            else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsPotion())
                            {
                                textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for 10 gold");
                                player.addGold(10);
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                        }
                        break;

                    case 'w':
                        if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null)
                        {
                            if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsWeapon())
                            {
                                textBox.Add("You looted " + player.getWeapon().getName() + " for " + player.getWeapon().getQuality() + " gold");
                                player.addGold(player.getWeapon().getQuality());
                                player.setWeapon(currentMap.getItem(player.getPlayerX(), player.getPlayerY()));
                                textBox.Add("You equip " + player.getWeapon().getName());
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                            else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsArmor())
                            {
                                textBox.Add("You looted " + player.getArmor().getName() + " for " + player.getArmor().getQuality() + " gold");
                                player.addGold(player.getArmor().getQuality());
                                player.setArmor(currentMap.getItem(player.getPlayerX(), player.getPlayerY()));
                                textBox.Add("You equip " + player.getArmor().getName());
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                        }
                        break;

                    case 'e':
                        if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null)
                        {
                            if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsPotion())
                            {
                                player.setNowHP(player.getNowHP() + (player.getMaxHP() / 2));
                                textBox.Add("You drink the healing potion, and recover some lost health.");
                                currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null);
                                moveon = true;
                            }
                        }
                        else if (currentMap.getTransision().getX() == player.getPlayerX() && currentMap.getTransision().getY() == player.getPlayerY())
                        {
                            textBox.Add("You transport yourself into another realm");

                            Map tmp = new Map(realmStarts[rand.Next(0, realmStarts.Length)] + realmNames[rand.Next(0, realmNames.Length)] + realmNames[rand.Next(0, realmNames.Length)] + ", The " + realmTypes[rand.Next(0, realmTypes.Length)] + " of " + realmTitles[currentMap.getLevel()], currentMap.getLevel() + 1);

                            currentMap = tmp;
                            player.setPlayerX(rand.Next(1, 44));
                            player.setPlayerY(rand.Next(1, 39));
                            moveon = true;
                        }
                        break;
                    }
                    break;
                }
            }
        }
Exemple #21
0
        public void smooth()
        {
            bool done  = false;
            int  tries = 0;
            int  l     = 0;

            int percent = windingPercent ^ 2;

            while (!done && !TCODConsole.isWindowClosed() && tries < percent)
            {
                // Program.engine.update();
                if (debugDraw)
                {
                    Program.engine.render();
                    TCODConsole.flush();
                }
                done = true;

                percent = (windingPercent ^ 2) + TCODRandom.getInstance().getInt(-50, 50);

                for (var y = 1; y < map.height; y += 1)
                {
                    for (var x = 1; x < map.width; x += 1)
                    {
                        if (!map.isWall(x, y))
                        {
                            List <Point> exits = new List <Point>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (!map.isWall(x + p.X, y + p.Y))
                                    {
                                        exits.Add(p);
                                    }
                                }
                            }
                            if (exits.Count == 2)
                            {
                                Point a = exits[0];
                                Point b = exits[1];
                                if (a.X != 0) //checks if pathway is horisontal or vertical
                                {
                                    if (map.isWall(x + (a.X * 2), y) && map.isWall(x + (b.X * 2), y))
                                    {
                                        if (!map.isWall(x + a.X, y + 1) && !map.isWall(x + b.X, y + 1))
                                        {
                                            if (map.isWall(x + a.X, y - 1) && map.isWall(x + b.X, y - 1))
                                            {
                                                map.setWall(x + a.X, y);
                                                map.setWall(x + b.X, y);
                                                map.setWall(x, y);
                                                map.dig(x, y + 1, x, y + 1);


                                                done = false;
                                            }
                                        }
                                        else
                                        if (!map.isWall(x + a.X, y - 1) && !map.isWall(x + b.X, y - 1))
                                        {
                                            if (map.isWall(x + a.X, y + 1) && map.isWall(x + b.X, y + 1))
                                            {
                                                map.setWall(x + a.X, y);
                                                map.setWall(x + b.X, y);
                                                map.setWall(x, y);
                                                map.dig(x, y - 1, x, y - 1);

                                                done = false;
                                            }
                                        }
                                    }
                                }
                                else if (a.Y != 0)
                                {
                                    if (map.isWall(x, y + (a.Y * 2)) && map.isWall(x, y + (b.Y * 2)))
                                    {
                                        if (!map.isWall(x + 1, y + a.Y) && !map.isWall(x + 1, y + b.Y))
                                        {
                                            if (map.isWall(x - 1, y + a.Y) && map.isWall(x - 1, y + b.Y))
                                            {
                                                map.setWall(x, y + a.Y);
                                                map.setWall(x, y + b.Y);
                                                map.setWall(x, y);
                                                map.dig(x + 1, y, x + 1, y);

                                                done = false;
                                            }
                                        }
                                        else

                                        if (!map.isWall(x - 1, y + a.Y) && !map.isWall(x - 1, y + b.Y))
                                        {
                                            if (map.isWall(x + 1, y + a.Y) && map.isWall(x + 1, y + b.Y))
                                            {
                                                map.setWall(x, y + a.Y);
                                                map.setWall(x, y + b.Y);
                                                map.setWall(x, y);
                                                map.dig(x - 1, y, x - 1, y);

                                                done = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }


                tries++;
                l++;
                if (l < (windingPercent * windingPercent) / 4)
                {
                    Program.engine.loadingGui.loading++;
                    Program.engine.render();
                    l = 0;
                }
            }
            done  = false;
            tries = 0;
            while (!done && !TCODConsole.isWindowClosed() && tries < percent)
            {
                // Program.engine.update();
                //Program.engine.render();

                //TCODConsole.flush();
                if (debugDraw)
                {
                    Program.engine.render();
                    TCODConsole.flush();
                }
                done = true;

                percent = (windingPercent ^ 2) + TCODRandom.getInstance().getInt(-50, 50);

                for (var y = 1; y < map.height; y += 1)
                {
                    for (var x = 1; x < map.width; x += 1)
                    {
                        if (!map.isWall(x, y))
                        {
                            List <Point> exits = new List <Point>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (!map.isWall(x + p.X, y + p.Y))
                                    {
                                        exits.Add(p);
                                    }
                                }
                            }
                            if (exits.Count == 2)
                            {
                                Point a = exits[0];
                                Point b = exits[1];
                                if (a.X != 0) //checks if pathway is horisontal or vertical
                                {
                                    if (map.isWall(x + (a.X * 3), y) && map.isWall(x + (b.X * 3), y))
                                    {
                                        if (!map.isWall(x + (a.X * 2), y) && !map.isWall(x + (b.X * 2), y))
                                        {
                                            if (!map.isWall(x + (a.X * 2), y + 1) && !map.isWall(x + (b.X * 2), y + 1))
                                            {
                                                if (map.isWall(x + (a.X * 2), y - 1) && map.isWall(x + (b.X * 2), y - 1))
                                                {
                                                    map.setWall(x + a.X, y);
                                                    map.setWall(x + b.X, y);
                                                    map.setWall(x + (a.X * 2), y);
                                                    map.setWall(x + (b.X * 2), y);
                                                    map.setWall(x, y);
                                                    map.dig(x, y + 1, x, y + 1);
                                                    map.dig(x + a.X, y + 1, x + a.X, y + 1);
                                                    map.dig(x + b.X, y + 1, x + b.X, y + 1);

                                                    done = false;
                                                }
                                            }
                                            else

                                            if (!map.isWall(x + (a.X * 2), y - 1) && !map.isWall(x + (b.X * 2), y - 1))
                                            {
                                                if (map.isWall(x + (a.X * 2), y + 1) && map.isWall(x + (b.X * 2), y + 1))
                                                {
                                                    map.setWall(x + a.X, y);
                                                    map.setWall(x + b.X, y);
                                                    map.setWall(x + (a.X * 2), y);
                                                    map.setWall(x + (b.X * 2), y);
                                                    map.setWall(x, y);
                                                    map.dig(x, y - 1, x, y - 1);
                                                    map.dig(x + a.X, y - 1, x + a.X, y - 1);
                                                    map.dig(x + b.X, y - 1, x + b.X, y - 1);

                                                    done = false;
                                                }
                                            }
                                        }
                                    }
                                    else if (a.Y != 0)
                                    {
                                        if (map.isWall(x, y + (a.Y * 3)) && map.isWall(x, y + (b.Y * 3)))
                                        {
                                            if (!map.isWall(x, y + (a.Y * 2)) && !map.isWall(x, y + (b.Y * 2)))
                                            {
                                                if (!map.isWall(x + 1, y + (a.Y * 2)) && !map.isWall(x + 1, y + (b.Y * 2)))
                                                {
                                                    if (map.isWall(x - 1, y + (a.Y * 2)) && map.isWall(x - 1, y + (b.Y * 2)))
                                                    {
                                                        map.setWall(x, y + a.Y);
                                                        map.setWall(x, y + b.Y);
                                                        map.setWall(x, y + (a.Y * 2));
                                                        map.setWall(x, y + (b.Y * 2));
                                                        map.setWall(x, y);
                                                        map.dig(x + 1, y + 1, x, y);
                                                        map.dig(x + 1, y + a.Y, x + 1, y + a.Y);
                                                        map.dig(x + 1, y + b.Y, x + 1, y + b.Y);

                                                        done = false;
                                                    }
                                                }
                                                else

                                                if (!map.isWall(x + (a.X * 2), y + 1) && !map.isWall(x + (b.X * 2), y + 1))
                                                {
                                                    if (map.isWall(x + (a.X * 2), y - 1) && map.isWall(x + (b.X * 2), y - 1))

                                                    {
                                                        map.setWall(x, y + a.Y);
                                                        map.setWall(x, y + b.Y);
                                                        map.setWall(x, y + (a.Y * 2));
                                                        map.setWall(x, y + (b.Y * 2));
                                                        map.setWall(x, y);
                                                        map.dig(x - 1, y - 1, x, y);
                                                        map.dig(x - 1, y + a.Y, x - 1, y + a.Y);
                                                        map.dig(x - 1, y + b.Y, x - 1, y + b.Y);

                                                        done = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                tries++;
            }
        }
Exemple #22
0
        public void removeDeadEnds()
        {
            bool         done    = false;
            int          tries   = 0;
            int          l       = 0;
            List <Point> ignores = new List <Point>();

            while (!done && !TCODConsole.isWindowClosed() && tries < 100)
            {
                // Program.engine.update();
                //Program.engine.render();
                //TCODConsole.flush();
                if (debugDraw)
                {
                    Program.engine.render();
                    TCODConsole.flush();
                }
                done = true;


                for (var y = 1; y < map.height; y += 1)
                {
                    for (var x = 1; x < map.width; x += 1)
                    {
                        if (!map.isWall(x, y))
                        {
                            List <Point> exits = new List <Point>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (!map.isWall(x + p.X, y + p.Y) || ignores.Contains(new Point(x + p.X, y + p.Y)))
                                    {
                                        exits.Add(p);
                                    }
                                }
                            }
                            if (exits.Count == 1)
                            {
                                if (TCODRandom.getInstance().getInt(0, 100) < 100 - deadEndLength)
                                {
                                    done = false;
                                    map.setWall(x, y);
                                }
                                else
                                {
                                    ignores.Add(new Point(x, y));
                                }
                            }
                        }
                    }
                }
                tries++;
                l++;
                if (l > (100 - deadEndLength) / 5)
                {
                    Program.engine.loadingGui.loading++;
                    Program.engine.render();
                    l = 0;
                }
            }
        }
Exemple #23
0
        public bool pickATile(out int x, out int y, float maxRange)
        {
            int pickX = Program.engine.player.x - map.offsetX, pickY = Program.engine.player.y - map.offsetY;

            for (int cx = map.renderX; cx < map.renderWidth; cx++)
            {
                for (int cy = map.renderY; cy < map.renderHeight; cy++)
                {
                    if (Program.engine.player.fov.isInFov(cx + map.offsetX, cy + map.offsetY) &&
                        (maxRange == 0 || Program.engine.player.getDistance(cx + map.offsetX, cy + map.offsetY) <= maxRange))
                    {
                        TCODColor col = TCODConsole.root.getCharBackground(cx, cy);
                        col = col.Multiply(1.2f);
                        TCODConsole.root.setCharBackground(cx, cy, col);
                    }
                }
            }
            int       oldX = pickX, oldY = pickY;
            TCODColor oldC = TCODConsole.root.getCharBackground(pickX, pickY);

            while (!TCODConsole.isWindowClosed())
            {
                render();


                mousedata          = TCODMouse.getStatus();
                Program.engine.key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
                if (Engine.useMouse)
                {
                    if (Program.engine.player.fov.isInFov(mousedata.CellX + map.offsetX, mousedata.CellY + map.offsetY))
                    {
                        if ((maxRange == 0 || Program.engine.player.getDistance(mousedata.CellX + map.offsetX, mousedata.CellY + map.offsetY) <= maxRange))
                        {
                            pickX = mousedata.CellX;
                            pickY = mousedata.CellY;
                            if (mousedata.LeftButtonPressed)
                            {
                                x = mousedata.CellX + map.offsetX;
                                y = mousedata.CellY + map.offsetY;
                                return(true);
                            }
                        }
                    }
                    if (mousedata.RightButtonPressed)
                    {
                        x = 0;
                        y = 0;
                        return(false);
                    }
                }
                if (pickX != oldX || pickY != oldY)
                {
                    TCODConsole.root.setCharBackground(oldX, oldY, oldC);
                    oldC = TCODConsole.root.getCharBackground(pickX, pickY);
                    TCODConsole.root.setCharBackground(pickX, pickY, TCODColor.white);
                    oldX = pickX;
                    oldY = pickY;
                }
                if (Program.engine.player.fov.isInFov(pickX + map.offsetX, pickY + map.offsetY))
                {
                    if ((maxRange == 0 || Program.engine.player.getDistance(pickX + map.offsetX, pickY + map.offsetY) <= maxRange))
                    {
                        switch (Program.engine.key.KeyCode)
                        {
                        case TCODKeyCode.Enter:
                        {
                            x = pickX + map.offsetX;
                            y = pickY + map.offsetY;

                            return(true);
                        }

                        case TCODKeyCode.Up:
                        {
                            if (Program.engine.player.fov.isInFov(pickX + map.offsetX, pickY - 1 + map.offsetY))
                            {
                                if (Program.engine.player.getDistance(pickX + map.offsetX, pickY - 1 + map.offsetY) <= maxRange)
                                {
                                    pickY--;
                                }
                            }
                            break;
                        }

                        case TCODKeyCode.Down:
                            if (Program.engine.player.fov.isInFov(pickX + map.offsetX, pickY + 1 + map.offsetY))
                            {
                                if (Program.engine.player.getDistance(pickX + map.offsetX, pickY + 1 + map.offsetY) <= maxRange)
                                {
                                    pickY++;
                                }
                            }
                            break;

                        case TCODKeyCode.Left:
                            if (Program.engine.player.fov.isInFov(pickX - 1 + map.offsetX, pickY + map.offsetY))
                            {
                                if (Program.engine.player.getDistance(pickX - 1 + map.offsetX, pickY + map.offsetY) <= maxRange)
                                {
                                    pickX--;
                                }
                            }
                            break;

                        case TCODKeyCode.Right:
                            if (Program.engine.player.fov.isInFov(pickX + 1 + map.offsetX, pickY + map.offsetY))
                            {
                                if (Program.engine.player.getDistance(pickX + 1 + map.offsetX, pickY + map.offsetY) <= maxRange)
                                {
                                    pickX++;
                                }
                            }
                            break;
                        }
                    }
                }

                TCODConsole.flush();
                Program.engine.lastKey = Program.engine.key;
            }
            x = 0;
            y = 0;
            return(false);
        }
Exemple #24
0
        public void connectRegions()
        {
            List <int[]> _regions       = new List <int[]>();
            List <Point> _points        = new List <Point>();
            TCODRandom   rng            = TCODRandom.getInstance();
            List <Point> extraJunctions = new List <Point>();

            for (var y = 1; y < map.height - 1; y++)
            {
                for (var x = 1; x < map.width - 1; x++)
                {
                    if (map.isWall(x, y))
                    {
                        List <int> regs = new List <int>();

                        foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                        {
                            if (dir != Direction.NULL)
                            {
                                Point p = dirToPoint(dir);
                                if (x + p.X < regions.GetLength(0) - 1 && y + p.Y < regions.GetLength(1) - 1 && x + p.X > 0 && y + p.Y > 0)
                                {
                                    int region = regions[x + p.X, y + p.Y];
                                    if (region != 0 && !regs.Contains(region))
                                    {
                                        regs.Add(region);
                                    }
                                }
                            }
                        }
                        if (regs.Count < 2)
                        {
                            if (rng.getInt(0, extraConnectorChance * extraConnectorChance) == 0)
                            {
                                extraJunctions.Add(new Point(x, y));
                            }
                            continue;
                        }
                        _regions.Add(regs.ToArray());
                        _points.Add(new Point(x, y));
                    }
                    else
                    {
                    }
                }
            }



            int openRegions = currentRegion;
            int tries       = 0;

            while (_regions.Count > 1 && !TCODConsole.isWindowClosed())
            {
                int rnum = TCODRandom.getInstance().getInt(0, _regions.Count - 1);
                if (_regions.Count > 0)
                {
                    int[] connectorReg = _regions[rnum];
                    Point connectorPos = _points[rnum];


                    addJunction(connectorPos.X, connectorPos.Y);

                    List <int> sources = new List <int>();
                    int        dest    = connectorReg[0];
                    bool       foo     = true;

                    for (int y = 1; y < map.height - 1; y++)
                    {
                        for (int x = 1; x < map.width - 1; x++)
                        {
                            for (int j = 0; j < connectorReg.Length; j++)
                            {
                                if (regions[x, y] == connectorReg[j] && regions[x, y] != dest)
                                {
                                    regions[x, y] = dest;
                                    if (foo)
                                    {
                                        foo = false;
                                    }
                                }
                            }
                        }
                    }
                    if (!foo)
                    {
                        openRegions--;
                    }



                    _regions.Remove(connectorReg);
                    _points.Remove(connectorPos);


                    for (int i = 0; i < _regions.Count; i++)
                    {
                        if (i < _regions.Count)
                        {
                            if (Math.Sqrt(Math.Pow(connectorPos.X - _points[i].X, 2) + Math.Pow(connectorPos.Y - _points[i].Y, 2)) < 2)
                            {
                                _points.RemoveAt(i);
                                _regions.RemoveAt(i);
                                continue;
                            }
                            List <int> regs = new List <int>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (_points[i].X + p.X < regions.GetLength(0) - 1 && _points[i].Y + p.Y < regions.GetLength(1) - 1 && _points[i].X + p.X > 0 && _points[i].Y + p.Y > 0)
                                    {
                                        int region = regions[_points[i].X + p.X, _points[i].Y + p.Y];
                                        if (region != 0 && !regs.Contains(region))
                                        {
                                            regs.Add(region);
                                        }
                                    }
                                }
                            }
                            _regions[i] = regs.ToArray();
                            if (_regions[i].Length > 1)
                            {
                                continue;
                            }

                            if (rng.getInt(0, extraConnectorChance) == 0)
                            {
                                if (!extraJunctions.Contains(_points[i]))
                                {
                                    extraJunctions.Add(_points[i]);
                                }
                            }

                            _points.RemoveAt(i);
                            _regions.RemoveAt(i);
                        }
                    }
                }
                else
                {
                    break;
                }
                tries++;
            }


            for (int i = 0; i < maxExtraJunctions; i++)
            {
                if (extraJunctions.Count > 0)
                {
                    Point p = extraJunctions[rng.getInt(0, extraJunctions.Count - 1)];
                    addJunction(p.X, p.Y);
                }
            }

            /*
             * int[] merged = null;
             * if (currentRegion > 0)
             *  merged = new int[currentRegion + 1];
             * List<int> openRegions = new List<int>();
             * for (int i = 0; i <= currentRegion; i++)
             * {
             *  openRegions.Add(i);
             *  if (merged != null)
             *      merged[i] = i;
             * }
             * TCODRandom rng = TCODRandom.getInstance();
             *
             * while (openRegions.Count > 1 && !TCODConsole.isWindowClosed())
             * {
             *
             *  ConnectorCell connector = connectorRegions[rng.getInt(0, connectorRegions.Count - 1)];
             *  addJunction(connector.pos.X, connector.pos.Y);
             *
             *  List<int> regs = new List<int>();
             *
             *
             *  regs = merged.ToList();
             *  int dest = regs[0];
             *  int[] sources = regs.Skip(1).ToArray();
             *  for (int i = 0; i <= currentRegion; i++)
             *  {
             *      if (sources.Contains(merged[i]))
             *      {
             *          merged[i] = dest;
             *      }
             *  }
             *  for (int i = 0; i < sources.Length; i++)
             *  {
             *      openRegions.Remove(sources[i]);
             *  }
             *
             *  for (int i = 0; i < connectorRegions.Count; i++)
             *  {
             *      if (i < connectorRegions.Count)
             *      {
             *          ConnectorCell c = connectorRegions[i];
             *          if (connector.pos.X - c.pos.X < 2 || connector.pos.Y - c.pos.Y < 2)
             *          {
             *              connectorRegions.Remove(c);
             *              continue;
             *          }
             *          if (regions.Length > 1) { continue; }
             *
             *          if (rng.getInt(0, extraConnectorChance) > 0)
             *          {
             *              addJunction(c.pos.X, c.pos.Y);
             *              connectorRegions.Remove(c);
             *              continue;
             *          }
             *      }
             *  }
             *
             * }
             */
        }