private void Update() { NCurses.GetChar(); UpdateSnakeDirection(NCurses.GetChar()); CheckEatApple(); CheckSnakeOutOfBounds(); }
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; } } }
/// <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); }
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(); } }
private static void InterpretKeyPress() { Direction moveViewportDir = Direction.None; int key = NCurses.GetChar(); switch (key) { case CursesKey.ESC: _exit = true; break; case ' ': _routine.NextTimeUnit(); _dirty = true; break; // Backspace can be 3 different key-codes, depending on platform case CursesKey.BACKSPACE: case '\b': case 127: _routine.LastTimeUnit(); _dirty = true; break; case CursesKey.LEFT: moveViewportDir = Direction.Left; break; case CursesKey.RIGHT: moveViewportDir = Direction.Right; break; case CursesKey.UP: moveViewportDir = Direction.Up; break; case CursesKey.DOWN: moveViewportDir = Direction.Down; break; case '+': _mapView.NextView(); _dirty = true; break; case '-': _mapView.PreviousView(); _dirty = true; break; default: _routine.InterpretKeyPress(key); break; } if (moveViewportDir != Direction.None) { _dirty = _mapView.CenterViewOn(_mapView.CurrentViewport.ViewArea.Center + moveViewportDir); } }