コード例 #1
0
        /// <summary>
        /// Modified singleton pattern. Creates the root console based on
        /// the behavior values in RootConsole.Width, RootConsole.Height,
        /// RootConsole.WindowTitle, RootConsole.Fullscreen, and
        /// RootConsole.Font, or gets the already-created console if one
        /// exists.
        /// </summary>
        /// <returns>
        ///    The root console object.
        /// </returns>
        public static RootConsole GetInstance()
        {
            if (singletonInstance == null)
            {
                if (width == null)
                {
                    throw new TCODException("RootConsole.Width is not set.");
                }
                if (height == null)
                {
                    throw new TCODException("RootConsole.Height is not set.");
                }
                if (windowTitle == null)
                {
                    throw new TCODException("RootConsole.WindowTitle is not set.");
                }
                if (isFullscreen == null)
                {
                    throw new TCODException("RootConsole.Fullscreen is not set.");
                }

                if (font == null)
                {
                    singletonInstance = new RootConsole((Int32)width, (Int32)height,
                                                        windowTitle, (Boolean)isFullscreen);
                }
                else
                {
                    singletonInstance = new RootConsole((Int32)width, (Int32)height,
                                                        windowTitle, (Boolean)isFullscreen, font);
                }
            }

            return(singletonInstance);
        }
コード例 #2
0
        private static void TurnBasedLoopTest(RootConsole console, ref KeyPress key)
        {
            console.Clear();
            console.PrintLine("Keyboard Test Suite", 40, 5, LineAlignment.Center);
            console.PrintLine("Press 'F10' to enter Real Time Test.", 40, 6, LineAlignment.Center);
            console.PrintLine("Press 'q' to quit.", 40, 7, LineAlignment.Center);

            if (key.KeyCode == KeyCode.TCODK_CHAR)
                console.PrintLine("Key Hit = \"" + (char)key.Character + "\"", 10, 10, LineAlignment.Left);
            else
                console.PrintLine("Special Key Hit = " + key.KeyCode.ToString(), 10, 10, LineAlignment.Left);

            PrintStatus(console, "Status", key.Pressed, 10, 12);
            PrintStatus(console, "lalt", key.LeftAlt, 10, 13);
            PrintStatus(console, "lctrl", key.LeftControl, 10, 14);
            PrintStatus(console, "ralt", key.RightAlt, 10, 15);
            PrintStatus(console, "rctrl", key.RightControl, 10, 16);
            PrintStatus(console, "shift", key.Shift, 10, 17);

            console.PrintLine("F1 Key Pressed = " + (Keyboard.IsKeyPressed(KeyCode.TCODK_F1) ? "Yes" : "No"), 10, 20, LineAlignment.Left);

            console.Flush();

            key = Keyboard.WaitForKeyPress(false);

            if (key.KeyCode == KeyCode.TCODK_F10)
                inRealTimeTest = true;
        }
コード例 #3
0
        private static void RealTimeLoopTest(RootConsole console)
        {
            TCODSystem.FPS = 25;

            console.Clear();

            console.PrintLine("Keyboard Test Suite", 40, 5, LineAlignment.Center);
            console.PrintLine("Press 'F10' to enter Turn Based Test.", 40, 6, LineAlignment.Center);

            KeyPress pressedKey = Keyboard.CheckForKeypress(KeyPressType.Pressed);

            console.PrintLine("F2 Key Pressed = " + ((pressedKey.KeyCode == KeyCode.TCODK_F2 && pressedKey.Pressed) ? "Yes" : "No"), 10, 10, LineAlignment.Left);
            console.PrintLine("'d' to disable repeat keys", 10, 11, LineAlignment.Left);
            console.PrintLine("'e' to enable repeat keys", 10, 12, LineAlignment.Left);
            console.PrintLine(string.Format("Ctrl: {0}", pressedKey.LeftControl), 10, 13, LineAlignment.Left);
            console.PrintLine(string.Format("Ctrl Up: {0}", ctrlUpHit), 10, 14, LineAlignment.Left);
            if(pressedKey.KeyCode == KeyCode.TCODK_UP && pressedKey.Control)
            {
                ctrlUpHit = true;
            }

            console.Flush();

            if (pressedKey.Character == 'd')
                Keyboard.DisableRepeat();
            if (pressedKey.Character == 'e')
                Keyboard.SetRepeat(0, 10);

            if (pressedKey.KeyCode == KeyCode.TCODK_F10 && pressedKey.Pressed)
                inRealTimeTest = false;
        }
コード例 #4
0
        private static void PaintFOVTest(RootConsole console, int x, int y, TCODFov fov)
        {
            fov.CalculateFOV(x, y, 3, false, FovAlgorithm.Basic);

            for (int i = 0; i < 5; ++i)    //width
            {
                for (int j = 0; j < 5; ++j) //height
                {
                    if (room[j, i] == '.')
                    {
                        if (fov.CheckTileFOV(i, j))
                            console.PutChar(i, j, '.');
                        else
                            console.PutChar(i, j, '~');
                    }
                    else
                    {
                        console.PutChar(i, j, '#');
                    }
                }
            }
            console.PutChar(x, y, '@');
            console.Flush();
        }
コード例 #5
0
ファイル: TCODConsole.cs プロジェクト: Sinellil/roguelike-cs
        /// <summary>
        /// Modified singleton pattern. Creates the root console based on
        /// the behavior values in RootConsole.Width, RootConsole.Height,
        /// RootConsole.WindowTitle, RootConsole.Fullscreen, and
        /// RootConsole.Font, or gets the already-created console if one
        /// exists.
        /// </summary>
        /// <returns>
        ///    The root console object.
        /// </returns>
        public static RootConsole GetInstance()
        {
            if (singletonInstance == null)
            {
                if (width == null)
                    throw new TCODException("RootConsole.Width is not set.");
                if (height == null)
                    throw new TCODException("RootConsole.Height is not set.");
                if (windowTitle == null)
                    throw new TCODException("RootConsole.WindowTitle is not set.");
                if (isFullscreen == null)
                    throw new TCODException("RootConsole.Fullscreen is not set.");

                if (font == null)
                    singletonInstance = new RootConsole((Int32)width, (Int32)height,
                        windowTitle, (Boolean)isFullscreen);
                else
                    singletonInstance = new RootConsole((Int32)width, (Int32)height,
                        windowTitle, (Boolean)isFullscreen, font);
            }

            return singletonInstance;
        }
コード例 #6
0
        public void Init()
        {
            RootConsole.Width = 80;
            RootConsole.Height = 50;
            RootConsole.WindowTitle = "Image Testing";
            RootConsole.Fullscreen = false;

            console = RootConsole.GetInstance();
            console.Clear();
        }
コード例 #7
0
ファイル: sample.cs プロジェクト: AndrewBaker/libtcod-net
        public int Run(string[] args)
        {
            fillSampleList();

            int curSample = 0; // index of the current sample
            bool first = true; // first time we render a sample
            KeyPress key = new KeyPress();
            string font = "celtic_garamond_10x10_gs_tc.png";
            int numberCharsHorz = 32;
            int numberCharsVert = 8;
            int fullscreenWidth = 0;
            int fullscreenHeight = 0;
            bool fullscreen = false;
            bool credits = false;
            CustomFontRequestFontTypes flags = CustomFontRequestFontTypes.Grayscale | CustomFontRequestFontTypes.LayoutTCOD;
            CustomFontRequestFontTypes newFlags = 0;

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i] == "-font" && ArgsRemaining(args, i, 1))
                {
                    i++;
                    font = args[i];
                }
                else if (args[i] == "-font-char-numberRows" && ArgsRemaining(args, i, 2))
                {
                    i++;
                    numberCharsHorz = System.Convert.ToInt32(args[i]);
                    i++;
                    numberCharsVert = System.Convert.ToInt32(args[i]);
                }
                else if (args[i] == "-fullscreen-resolution" && ArgsRemaining(args, i, 2))
                {
                    i++;
                    fullscreenWidth = System.Convert.ToInt32(args[i]);
                    i++;
                    fullscreenHeight = System.Convert.ToInt32(args[i]);
                }
                else if (args[i] == "-fullscreen")
                {
                    fullscreen = true;
                }
                else if (args[i] == "-font-in-row")
                {
                    flags = 0;
                    newFlags |= CustomFontRequestFontTypes.LayoutAsciiInRow;
                }
                else if (args[i] == "-font-greyscale")
                {
                    flags = 0;
                    newFlags |= CustomFontRequestFontTypes.Grayscale;
                }
                else if (args[i] == "-font-tcod")
                {
                    flags = 0;
                    newFlags |= CustomFontRequestFontTypes.LayoutTCOD;
                }
                else if (args[i] == "-help")
                {
                    System.Console.Out.WriteLine("options : \n");
                    System.Console.Out.WriteLine("-font <filename> : use a custom font\n");
                    System.Console.Out.WriteLine("-font-char-size <char_width> <char_height> : size of the custom font's characters\n");
                    System.Console.Out.WriteLine("-font-in-row : the font layout is in row instead of columns\n");
                    System.Console.Out.WriteLine("-font-tcod : the font uses TCOD layout instead of ASCII\n");
                    System.Console.Out.WriteLine("-font-greyscale : antialiased font using greyscale bitmap\n");
                    System.Console.Out.WriteLine("-fullscreen : start in fullscreen\n");
                    System.Console.Out.WriteLine("-fullscreen-resolution <screen_width> <screen_height> : force fullscreen resolution\n");

                }
            }
            if (flags == 0)
                flags = newFlags;
            CustomFontRequest fontReq = new CustomFontRequest(font, flags, numberCharsHorz, numberCharsVert);
            if (fullscreenWidth > 0)
                TCODSystem.ForceFullscrenResolution(fullscreenWidth, fullscreenHeight);

            RootConsole.Width = 80;
            RootConsole.Height = 50;
            RootConsole.WindowTitle = "tcodlib C# sample";
            RootConsole.Fullscreen = fullscreen;
            RootConsole.Font = fontReq;
            rootConsole = RootConsole.GetInstance();
            sampleConsole = RootConsole.GetNewConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);

            setupStaticData();
            do
            {
                rootConsole.Clear();
                if (!credits)
                    credits = rootConsole.ConsoleCreditsRender(60, 42, false);
                for (int i = 0; i < sampleList.Length; i++)
                {
                    if (i == curSample)
                    {
                        // set colors for currently selected sample
                        rootConsole.ForegroundColor = (ColorPresets.White);
                        rootConsole.BackgroundColor = (ColorPresets.Blue);
                    }
                    else
                    {
                        // set colors for other samples
                        rootConsole.ForegroundColor = (ColorPresets.Gray);
                        rootConsole.BackgroundColor = ColorPresets.Black;
                    }
                    rootConsole.PrintLine(sampleList[i].name, 2, 45 - sampleList.Length + i, Background.Set, LineAlignment.Left);
                }
                rootConsole.ForegroundColor = (ColorPresets.Gray);
                rootConsole.BackgroundColor = ColorPresets.Black;
                rootConsole.PrintLine("last frame : " + ((int)(TCODSystem.LastFrameLength * 1000)).ToString() + " ms ( " + TCODSystem.FPS + "fps)", 79, 46, LineAlignment.Right);
                rootConsole.PrintLine("elapsed : " + TCODSystem.ElapsedMilliseconds + "ms " + (TCODSystem.ElapsedSeconds.ToString("0.00")) + "s", 79, 47, LineAlignment.Right);
                rootConsole.PutChar(2, 47, SpecialCharacter.ARROW_N);
                rootConsole.PutChar(3, 47, SpecialCharacter.ARROW_S);
                rootConsole.PrintLine(" : select a sample", 4, 47, LineAlignment.Left);
                rootConsole.PrintLine("ALT-ENTER : switch to " + (RootConsole.Fullscreen ? "windowed mode  " : "fullscreen mode"), 2, 48, LineAlignment.Left);

                sampleList[curSample].render(first, key);
                first = false;

                sampleConsole.Blit(0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, rootConsole, SAMPLE_SCREEN_X, SAMPLE_SCREEN_Y);

                rootConsole.Flush();
                key = Keyboard.CheckForKeypress(KeyPressType.Pressed);

                if (key.KeyCode == KeyCode.TCODK_DOWN)
                {
                    // down arrow : next sample
                    curSample = (curSample + 1) % sampleList.Length;
                    first = true;
                }
                else if (key.KeyCode == KeyCode.TCODK_UP)
                {
                    // up arrow : previous sample
                    curSample--;
                    if (curSample < 0)
                        curSample = sampleList.Length - 1;
                    first = true;
                }
                else if (key.KeyCode == KeyCode.TCODK_ENTER && key.Alt)
                {
                    // ALT-ENTER : switch fullscreen
                    RootConsole.Fullscreen = !RootConsole.Fullscreen;
                }
                else if (key.KeyCode == KeyCode.TCODK_F1)
                {
                    System.Console.Out.WriteLine("key.pressed" + " " +
                        key.LeftAlt + " " + key.LeftControl + " " + key.RightAlt +
                        " " + key.RightControl + " " + key.Shift);
                }

            }
            while (!rootConsole.IsWindowClosed());
            return 0;
        }