Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 3
0
        private static void Explode(int row, int col)
        {
            NCurses.Erase();
            AddStr(row, col, "-");
            MyRefresh();

            col--;

            GetColor();
            AddStr(row - 1, col, " - ");
            AddStr(row, col, "-+-");
            AddStr(row + 1, col, " - ");
            MyRefresh();

            col--;

            GetColor();
            AddStr(row - 2, col, " --- ");
            AddStr(row - 1, col, "-+++-");
            AddStr(row, col, "-+#+-");
            AddStr(row + 1, col, "-+++-");
            AddStr(row + 2, col, " --- ");
            MyRefresh();

            GetColor();
            AddStr(row - 2, col, " +++ ");
            AddStr(row - 1, col, "++#++");
            AddStr(row, col, "+# #+");
            AddStr(row + 1, col, "++#++");
            AddStr(row + 2, col, " +++ ");
            MyRefresh();

            GetColor();
            AddStr(row - 2, col, "  #  ");
            AddStr(row - 1, col, "## ##");
            AddStr(row, col, "#   #");
            AddStr(row + 1, col, "## ##");
            AddStr(row + 2, col, "  #  ");
            MyRefresh();

            GetColor();
            AddStr(row - 2, col, " # # ");
            AddStr(row - 1, col, "#   #");
            AddStr(row, col, "     ");
            AddStr(row + 1, col, "#   #");
            AddStr(row + 2, col, " # # ");
            MyRefresh();
        }
Ejemplo n.º 4
0
        private void UpdateScreenData()
        {
            int offset = 0;

            NCurses.AttributeSet(CursesAttribute.NORMAL);
            NCurses.Nap(DefaultFramerate);
            NCurses.Erase();
            for (int i = 0; i < Buffer.Height; i++)
            {
                for (int j = 0; j < Buffer.Width; j++)
                {
                    NCurses.AttributeSet(NCurses.ColorPair(_colorMap[Buffer[offset++]]));
                    NCurses.MoveAddChar(i, j, ' ');
                }
            }
            NCurses.Refresh();
        }
Ejemplo n.º 5
0
        private static void DrawMap()
        {
            // Clear current data from console
            NCurses.Erase();

            // Calculate available console space.
            NCurses.GetMaxYX(_window, out int height, out int width);

            // Resize viewport as needed to match console size
            _mapView.ResizeViewport(width, height);

            // Change each character of the console as appropriate
            foreach (var pos in _mapView.CurrentViewport.Positions())
            {
                NCurses.Move(pos.Y, pos.X);
                NCurses.InsertChar(_mapView.CurrentViewport[pos]);
            }

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

            // Reset dirty flag because we just drew
            _dirty = false;
        }