game

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package game defines the plugin interface for puzzle games.

Index

Constants

This section is empty.

Variables

View Source
var (
	CursorFG     = compat.AdaptiveColor{Light: lipgloss.Color("255"), Dark: lipgloss.Color("235")}
	CursorBG     = compat.AdaptiveColor{Light: lipgloss.Color("130"), Dark: lipgloss.Color("173")}
	CursorWarmBG = compat.AdaptiveColor{Light: lipgloss.Color("130"), Dark: lipgloss.Color("214")}
	ConflictFG   = compat.AdaptiveColor{Light: lipgloss.Color("160"), Dark: lipgloss.Color("167")}
	ConflictBG   = compat.AdaptiveColor{Light: lipgloss.Color("224"), Dark: lipgloss.Color("52")}
)

Shared cursor color tokens, used both in style construction and for composite styling where a cursor color is applied on top of another style.

View Source
var (

	// CursorStyle highlights the cursor position with an accent background.
	// Used by lightsout, sudoku, wordsearch.
	CursorStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(CursorFG).
				Background(CursorBG)

	// CursorWarmStyle highlights the cursor with a warmer background.
	// Used by hitori, takuzu, nonogram.
	CursorWarmStyle = lipgloss.NewStyle().
					Bold(true).
					Foreground(CursorFG).
					Background(CursorWarmBG)

	// CursorSolvedStyle highlights the cursor position on a solved grid.
	// Shared across all puzzle types.
	CursorSolvedStyle = lipgloss.NewStyle().
						Bold(true).
						Foreground(CursorFG).
						Background(compat.AdaptiveColor{Light: lipgloss.Color("28"), Dark: lipgloss.Color("28")})

	// StatusBarStyle is the shared style for the status/help bar below each puzzle grid.
	StatusBarStyle = lipgloss.NewStyle().
					Foreground(compat.AdaptiveColor{Light: lipgloss.Color("244"), Dark: lipgloss.Color("244")}).
					MarginTop(1)
)
View Source
var DefaultCursorKeyMap = CursorKeyMap{
	Up: key.NewBinding(
		key.WithKeys("k", "up", "w"),
		key.WithHelp("↑/w/k", "Up"),
	),
	Down: key.NewBinding(
		key.WithKeys("j", "down", "s"),
		key.WithHelp("↓/s/j", "Down"),
	),
	Left: key.NewBinding(
		key.WithKeys("h", "left", "a"),
		key.WithHelp("←/a/h", "Left"),
	),
	Right: key.NewBinding(
		key.WithKeys("l", "right", "d"),
		key.WithHelp("→/d/l", "Right"),
	),
}

DefaultCursorKeyMap provides the standard cursor movement bindings.

View Source
var Registry = map[string]func([]byte) (Gamer, error){}

Registry maps game type names to their import functions.

Functions

func BorderChar added in v1.4.0

func BorderChar(ch string, colors GridBorderColors, solved, highlight bool) string

BorderChar renders a single border character with optional crosshair highlighting.

func DebugHeader

func DebugHeader(title string, rows [][2]string) string

DebugHeader returns the markdown heading and property table header for debug info. rows is a list of [key, value] pairs for the "Game State" table.

func DebugTable

func DebugTable(heading string, headers []string, rows [][]string) string

DebugTable returns a markdown table section with a heading and arbitrary columns. headers is the column names, rows is a list of row values.

func HBorderRow added in v1.4.0

func HBorderRow(w, cursorX, cellWidth int, left, right string, colors GridBorderColors, solved bool) string

HBorderRow builds a horizontal border row (top or bottom) with per-column crosshair highlighting. cellWidth is the visual width of each cell.

func Register

func Register(name string, fn func([]byte) (Gamer, error))

Register adds an import function for a game type to the registry.

func TitleBarView

func TitleBarView(gameName, modeName string, solved bool) string

TitleBarView renders a title bar with the game name, mode name, and optional solved badge.

Types

type BaseMode

type BaseMode struct {
	// contains filtered or unexported fields
}

BaseMode provides the common title/description fields and the three Mode-interface methods so that concrete mode structs can embed it instead of duplicating boilerplate.

func NewBaseMode

func NewBaseMode(title, description string) BaseMode

NewBaseMode creates a BaseMode with the given title and description.

func (BaseMode) Description

func (b BaseMode) Description() string

func (BaseMode) FilterValue

func (b BaseMode) FilterValue() string

func (BaseMode) Title

func (b BaseMode) Title() string

type Category

type Category struct {
	Name  string
	Desc  string
	Modes []list.Item
	Help  string // embedded help.md content rendered in "How to Play"
}

Category groups related game modes under a heading in the menu.

func (Category) Description

func (c Category) Description() string

func (Category) FilterValue

func (c Category) FilterValue() string

func (Category) Title

func (c Category) Title() string

type Cursor

type Cursor struct {
	X, Y int
}

Cursor represents a 2D grid cursor position.

func (*Cursor) Move

func (c *Cursor) Move(keys CursorKeyMap, msg tea.KeyPressMsg, maxX, maxY int) bool

Move updates the cursor position based on the key message and bounds. Returns true if the cursor moved.

type CursorKeyMap

type CursorKeyMap struct {
	Up    key.Binding
	Down  key.Binding
	Left  key.Binding
	Right key.Binding
}

CursorKeyMap defines the shared cursor movement key bindings.

type Gamer

type Gamer interface {
	GetDebugInfo() string
	GetFullHelp() [][]key.Binding

	GetSave() ([]byte, error)
	IsSolved() bool
	Reset() Gamer
	SetTitle(string) Gamer

	Init() tea.Cmd
	View() string
	Update(msg tea.Msg) (Gamer, tea.Cmd)
}

Gamer is the interface that an active game instance must implement.

type GridBorderColors added in v1.4.0

type GridBorderColors struct {
	BorderFG       compat.AdaptiveColor
	BackgroundBG   compat.AdaptiveColor
	CrosshairBG    compat.AdaptiveColor
	SolvedBorderFG compat.AdaptiveColor
	SolvedBG       compat.AdaptiveColor
}

GridBorderColors holds the color configuration for a grid border with crosshair and solved-state highlighting.

type HelpToggleMsg

type HelpToggleMsg struct{ Show bool }

HelpToggleMsg is sent from the root model to games when the user toggles the full help display with Ctrl+H.

type Mode

type Mode interface {
	Title() string
	Description() string
	FilterValue() string
}

Mode describes a game mode for menu display.

type SeededSpawner added in v1.3.0

type SeededSpawner interface {
	Spawner
	SpawnSeeded(rng *rand.Rand) (Gamer, error)
}

SeededSpawner creates a new game instance using a deterministic RNG. This enables reproducible puzzle generation for daily puzzles.

type SpawnCompleteMsg added in v1.3.0

type SpawnCompleteMsg struct {
	Game Gamer
	Err  error
}

SpawnCompleteMsg is sent when an async Spawn() call finishes.

type Spawner

type Spawner interface {
	Spawn() (Gamer, error)
}

Spawner creates a new game instance. Implemented by concrete mode types but kept separate from Mode so that Category (which also satisfies Mode) does not need a Spawn method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL