lightsout

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package lightsout implements the lights out toggle puzzle game.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,

	Toggle: key.NewBinding(
		key.WithKeys("enter", " "),
		key.WithHelp("space/enter", "Toggle"),
	),
}
View Source
var Modes = []list.Item{
	NewMode("Easy", "3x3 grid", 3, 3),
	NewMode("Medium", "5x5 grid", 5, 5),
	NewMode("Hard", "7x7 grid", 7, 7),
	NewMode("Extreme", "9x9 grid", 9, 9),
}

Modes defines the available difficulty levels.

Functions

func Generate

func Generate(w, h int) [][]bool

Generate creates a new w x h grid with a solvable puzzle. It starts with all lights off and applies random toggles.

func IsSolved

func IsSolved(grid [][]bool) bool

func Toggle

func Toggle(grid [][]bool, x, y int)

Toggle switches the state of the cell at (x,y) and its immediate neighbors. It assumes grid is rectangular.

Types

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	Toggle key.Binding
}

type Mode

type Mode struct {
	game.BaseMode
	Width, Height int
}

Mode represents a specific difficulty configuration for Lights Out.

func NewMode

func NewMode(title, desc string, w, h int) Mode

NewMode creates a new game mode.

func (Mode) Spawn

func (m Mode) Spawn() (game.Gamer, error)

Spawn creates a new game instance for this mode.

type Model

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

func ImportModel

func ImportModel(data []byte) (*Model, error)

func New

func New(w, h int) (Model, error)

func (Model) GetDebugInfo

func (m Model) GetDebugInfo() string

func (Model) GetFullHelp

func (m Model) GetFullHelp() [][]key.Binding

func (Model) GetSave

func (m Model) GetSave() ([]byte, error)

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) IsSolved

func (m Model) IsSolved() bool

func (Model) SetTitle

func (m Model) SetTitle(t string) game.Gamer

func (Model) Update

func (m Model) Update(msg tea.Msg) (game.Gamer, tea.Cmd)

func (Model) View

func (m Model) View() string

type Save

type Save struct {
	Grid      [][]bool `json:"grid"`
	CursorX   int      `json:"cx"`
	CursorY   int      `json:"cy"`
	ModeTitle string   `json:"mode_title"`
	Solved    bool     `json:"solved"`
}

Jump to

Keyboard shortcuts

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