예제 #1
0
 private static void AddStr(int y, int x, string str)
 {
     if (x >= 0 && x < NCurses.Columns && y >= 0 && y < NCurses.Lines)
     {
         NCurses.MoveAddString(y, x, str);
     }
 }
예제 #2
0
        static void Mouse()
        {
            NCurses.NoDelay(Screen, true);
            NCurses.NoEcho();

            NCurses.MoveAddString(0, 0, "Click a button or press any key to exit.");
            NCurses.MoveAddString(2, 0, "[X]  [Y]");

            // some terminals require this to differentiate mouse "keys" from random keyboard input
            NCurses.Keypad(Screen, true);

            // not reporting mouse movement?
            // https://stackoverflow.com/questions/52047158/report-mouse-position-for-ncurses-on-windows/52053196
            // https://stackoverflow.com/questions/7462850/mouse-movement-events-in-ncurses

            var eventsToReport =
                CursesMouseEvent.BUTTON1_CLICKED |
                CursesMouseEvent.BUTTON2_CLICKED |
                CursesMouseEvent.REPORT_MOUSE_POSITION;

            var availableMouseEvents = NCurses.MouseMask(eventsToReport, out uint oldMask);

            bool exit   = false;
            bool update = true;

            while (!exit)
            {
                switch (NCurses.GetChar())
                {
                case CursesKey.MOUSE:
                    try
                    {
                        NCurses.GetMouse(out MouseEvent mouse);
                        NCurses.MoveAddString(3, 0, $"{mouse.x.ToString("000")}  {mouse.y.ToString("000")}");
                        update = true;
                    }
                    catch (DotnetCursesException)
                    {
                        // no events in the queue
                    }
                    break;

                case -1:
                    // no input received
                    break;

                default:
                    exit = true;
                    break;
                }

                if (update)
                {
                    NCurses.Move(NCurses.Lines - 1, NCurses.Columns - 1);
                    NCurses.Refresh();
                    update = false;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Picks a routine out of the possible candidates
        /// </summary>
        /// <returns>The Routine we're running in this test</returns>
        private static IRoutine PickRoutine()
        {
            IRoutine?chosenRoutine = null;

            do
            {
                int y = 0;

                // Clear current data from console
                NCurses.Erase();

                // Display selection menu for routines
                NCurses.MoveAddString(y, 0, "Pick your routine by using its corresponding number:");
                y += 1;

                List <IRoutine> routines = GetRoutines();
                foreach (var(routine, index) in routines.Select((routine, index) => (routine, index)))
                {
                    NCurses.MoveAddString(y, 0, index + ") " + routine.Name);
                    y += 1;
                }

                // Move cursor to new line
                NCurses.Move(y, 0);

                // Render menu to screen
                NCurses.Refresh();

                // Read user input and parse into index
                int key = NCurses.GetChar();
                try
                {
                    // Convert the character code we get to string, then from that to the integer that was typed.
                    string number = ((char)key).ToString();
                    int    index  = int.Parse(number);
                    chosenRoutine = routines[index];
                }
                catch // Invalid selection: Display retry message to user.
                {
                    // Clear old menu
                    NCurses.Erase();

                    // Print retry message
                    NCurses.MoveAddString(0, 0,
                                          "Invalid selection.  Please select from the available options.  Press [Enter] to continue.");

                    // Display to screen and wait for user to acknowledge
                    NCurses.Refresh();
                    NCurses.GetChar();
                }
            } while (chosenRoutine == null);

            return(chosenRoutine);
        }
예제 #4
0
        private static void Fireworks()
        {
            NCurses.NoDelay(Screen, true);
            NCurses.NoEcho();

            if (NCurses.HasColors())
            {
                NCurses.StartColor();
                for (short i = 1; i < 8; i++)
                {
                    NCurses.InitPair(i, color_table[i], CursesColor.BLACK);
                }
            }

            int flag = 0;

            while (NCurses.GetChar() == -1)
            {
                int start, end, row, diff, direction;
                do
                {
                    start     = rng.Next(NCurses.Columns - 3);
                    end       = rng.Next(NCurses.Columns - 3);
                    start     = (start < 2) ? 2 : start;
                    end       = (end < 2) ? 2 : end;
                    direction = (start > end) ? -1 : 1;
                    diff      = Math.Abs(start - end);
                } while (diff < 2 || diff >= NCurses.Lines - 2);

                NCurses.AttributeSet(CursesAttribute.NORMAL);
                for (row = 1; row < diff; ++row)
                {
                    NCurses.MoveAddString(NCurses.Lines - row, row * direction + start, (direction < 0) ? "\\" : "/");
                    if (flag++ > 0)
                    {
                        MyRefresh();
                        NCurses.Erase();
                        flag = 0;
                    }
                }

                if (flag++ > 0)
                {
                    MyRefresh();
                    flag = 0;
                }

                Explode(NCurses.Lines - row, diff * direction + start);
                NCurses.Erase();
                MyRefresh();
            }
        }
예제 #5
0
        public void Print(Board board)
        {
            NCurses.NoDelay(Screen, true);
            NCurses.NoEcho();

            for (int i = 0; i < board.height; i++)
            {
                StringBuilder buffer = new StringBuilder();
                for (int j = 0; j < board.width; j++)
                {
                    buffer.Append(board.board[i, j] ? '■' : ' ');
                }
                NCurses.MoveAddString(i, 0, buffer.ToString());
            }
            NCurses.Refresh();
        }
예제 #6
0
 private void RenderScore()
 {
     NCurses.MoveAddString(size.Height + 2, 0, "Score : " + PlayerScore.ToString());
 }