Пример #1
0
        public Program()
        {
            Console.Title = "Ascii Demon Attack";
              inputBuffer = JConsole.GetInputBuffer();
              screenBuffer = JConsole.GetActiveScreenBuffer();
              screenBuffer.SetWindowSize(80, 50);
              screenBuffer.SetBufferSize(80, 50);
              screenBuffer.CursorVisible = false;
              screenBuffer.Clear();
              hiddenBuffer = new ConsoleCharInfo[50, 80];

              GameEngine gameEngine = new GameEngine(hiddenBuffer, inputBuffer);
              updateModelDelegate = gameEngine.UpdateModel;
              renderFrameDelegate = gameEngine.RenderFrame;

              for (int y = 0; y < 50; y++) {
            for (int x = 0; x < 80; x++) {
              hiddenBuffer[y, x].AsciiChar = (byte)0xdd;
            }
              }

              stopwatch.Start();
              nextFrameStart = stopwatch.ElapsedTicks;
              while (true) {
            do {
              UpdateModel();
              nextFrameStart += TICKS_PER_FRAME;
            } while (nextFrameStart < stopwatch.ElapsedTicks);
            RenderFrame();
            long remainingTicks = nextFrameStart - stopwatch.ElapsedTicks;
            if (remainingTicks > 0) {
              Thread.Sleep((int)(1000 * remainingTicks / FREQUENCY));
            }
              }
        }
Пример #2
0
        /// <summary>
        /// Opens the screen buffer.
        /// </summary>
        /// <returns>Returns a new <see cref="ConsoleInputBuffer"/> instance that references the
        /// console's input buffer.</returns>
        /// <remarks>This method allocates a new ConsoleInputBuffer instance.  Callers should
        /// call Dispose on the returned instance when they're done with it.</remarks>
        static public ConsoleInputBuffer GetInputBuffer()
        {
            IntPtr inHandle = WinApi.CreateFile("CONIN$",
                                                WinApi.GENERIC_READ | WinApi.GENERIC_WRITE,
                                                WinApi.FILE_SHARE_READ | WinApi.FILE_SHARE_WRITE,
                                                null,
                                                WinApi.OPEN_EXISTING,
                                                0,
                                                IntPtr.Zero);

            if (inHandle.ToInt32() == WinApi.INVALID_HANDLE_VALUE)
            {
                throw new IOException("Unable to open CONIN$", Marshal.GetLastWin32Error());
            }
            ConsoleInputBuffer inputBuffer = new ConsoleInputBuffer(inHandle);

            inputBuffer.ownsHandle = true;

            return(inputBuffer);
        }
Пример #3
0
        public GameEngine(ConsoleCharInfo[,] hiddenBuffer, ConsoleInputBuffer inputBuffer)
        {
            this.hiddenBuffer = hiddenBuffer;
              this.inputBuffer = inputBuffer;

              playerX = (80 - shipSprite.Width) / 2;
              missileY = 49 - shipSprite.Height;
              for (int i = 0; i < 3; i++) {
            demons[i] = new Demon();
              }
        }
Пример #4
0
        /// <summary>
        /// Opens the screen buffer.
        /// </summary>
        /// <returns>Returns a new <see cref="ConsoleInputBuffer"/> instance that references the
        /// console's input buffer.</returns>
        /// <remarks>This method allocates a new ConsoleInputBuffer instance.  Callers should
        /// call Dispose on the returned instance when they're done with it.</remarks>
        public static ConsoleInputBuffer GetInputBuffer()
        {
            IntPtr inHandle = WinApi.CreateFile("CONIN$",
                WinApi.GENERIC_READ | WinApi.GENERIC_WRITE,
                WinApi.FILE_SHARE_READ | WinApi.FILE_SHARE_WRITE,
                null,
                WinApi.OPEN_EXISTING,
                0,
                IntPtr.Zero);
            if (inHandle.ToInt32() == WinApi.INVALID_HANDLE_VALUE)
            {
                throw new IOException("Unable to open CONIN$", Marshal.GetLastWin32Error());
            }
            ConsoleInputBuffer inputBuffer = new ConsoleInputBuffer(inHandle);
            inputBuffer.ownsHandle = true;

            return inputBuffer;
        }