Class TicTacToeScreen
A game of tic-tac-toe played inside the debug console, as a worked example of a full screen taking over the console grid.
Implements
Inherited Members
Namespace: Scylla.Console.TextMode
Assembly: ScyllaTextMode.ConsoleDisplay.dll
Syntax
public sealed class TicTacToeScreen : IConsoleScreen
Remarks
The player is X and moves first, the computer is O. Empty squares show the digit that claims them, laid out like a numeric keypad, so 7 is the top left and 3 the bottom right. Q leaves the game and gives the console back, and R starts a new game.
Everything is drawn in the console's own text color. A screen cannot know whether the console is themed light or dark, so a fixed palette risks marks that disappear into the background; monochrome follows whatever theme is loaded.
What this demonstrates, beyond the game: a screen owns every cell and draws straight into the grid it is handed, reads the keyboard itself because the console suspends its command line, redraws only when something changes rather than every frame, and hands the console back with its log and scroll position intact.
Properties
IsFinished
Gets whether the screen has finished and wants the console back.
Declaration
public bool IsFinished { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
OnClose()
Called once as the screen closes, whether it finished on its own or the console took it down.
Declaration
public void OnClose()
Remarks
The console closes an open screen when it is hidden or destroyed, so this is the place to release anything the screen holds. The grid handed to OnOpen(UITextModeView, DebugConsoleColorScheme) must not be touched after this returns.
OnOpen(UITextModeView, DebugConsoleColorScheme)
Called once as the screen opens, handing it the grid it draws into.
Declaration
public void OnOpen(UITextModeView view, DebugConsoleColorScheme colors)
Parameters
| Type | Name | Description |
|---|---|---|
| UITextModeView | view | The view the console has switched onto its alternate grid. Its Rows and Columns are whatever the console is currently sized to, so a screen should lay itself out from those rather than assume a size. The grid arrives holding whatever a previous screen left in it; clear it through Grid if a blank start matters. |
| DebugConsoleColorScheme | colors | The console's current theme. Draw from these rather than from fixed colors: the console is themed by palette and a project may well be running a light one, where hard-coded white text would be invisible. |
Remarks
Draw through SetCell(int, int, uint, Color32, Color32, CellAttributes) rather than writing to the grid directly. The view looks the glyph up in the font atlas and stamps its texture coordinates into the cell; a cell written straight to the grid carries a codepoint with no atlas data behind it, and renders as a blank block of background.
Pass DefaultBackground as the cell background unless a block of color is actually wanted. The console sets that fully transparent so its gradient shows through the text, and an opaque background stamps a flat rectangle over the gradient behind every character drawn.
The theme is handed over once, as the screen opens. A screen that outlives a live theme change keeps the colors it was given until it is reopened.
OnUpdate(float)
Called once per frame while the screen is open, to read input and redraw.
Declaration
public void OnUpdate(float deltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | deltaTime | Seconds since the previous frame, scaled by the framework's time. |
Remarks
The console does not redraw anything on a screen's behalf, so a screen that draws nothing shows the frame it last drew. That is a reasonable way to run: draw on change rather than every frame, since the grid keeps its contents.