wordsearch

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 wordsearch implements the word-finding grid puzzle.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,
	Select: key.NewBinding(
		key.WithKeys("enter", " "),
		key.WithHelp("enter/space", "select start/end"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "cancel selection"),
	),
}
View Source
var Modes = []list.Item{
	NewMode("Easy - 10x10", "Find 6 words in a 10x10 grid.", 10, 10, 6, 3, 5, []Direction{Right, Down, DownRight}),
	NewMode("Medium - 15x15", "Find 10 words in a 15x15 grid.", 15, 15, 10, 4, 7, []Direction{Right, Down, DownRight, DownLeft, Left, Up}),
	NewMode("Hard - 20x20", "Find 15 words in a 20x20 grid.", 20, 20, 15, 5, 10, []Direction{Right, Down, DownRight, DownLeft, Left, Up, UpRight, UpLeft}),
}

Functions

func New

func New(mode WordSearchMode, g grid, words []Word) (game.Gamer, error)

New creates a new word search game

Types

type Direction

type Direction int

Direction represents one of 8 possible directions a word can be placed

const (
	Right Direction = iota
	Down
	DownRight
	DownLeft
	Left
	Up
	UpRight
	UpLeft
)

func (Direction) Vector

func (d Direction) Vector() (int, int)

Vector returns the dx, dy unit vector for a direction

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	Select key.Binding
	Cancel key.Binding
}

type Model

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

func ImportModel

func ImportModel(data []byte) (*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 Position

type Position struct {
	X, Y int
}

Position represents a coordinate in the grid

type Save

type Save struct {
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	Grid       string `json:"grid"`
	Words      []Word `json:"words"`
	CursorX    int    `json:"cursor_x"`
	CursorY    int    `json:"cursor_y"`
	Selection  int    `json:"selection"`
	SelectionX int    `json:"selection_x"`
	SelectionY int    `json:"selection_y"`
	Solved     bool   `json:"solved"`
}

type Word

type Word struct {
	Text      string
	Start     Position
	End       Position
	Direction Direction
	Found     bool
}

Word represents a hidden word in the puzzle

func GenerateWordSearch

func GenerateWordSearch(width, height, wordCount, minLen, maxLen int, allowedDirs []Direction) (grid, []Word)

GenerateWordSearch creates a new word search grid with the specified parameters

func (*Word) Contains

func (w *Word) Contains(pos Position) bool

Contains checks if the given position is part of this word

func (*Word) Positions

func (w *Word) Positions() []Position

Positions returns all positions occupied by this word

type WordSearchMode

type WordSearchMode struct {
	game.BaseMode
	Width       int
	Height      int
	WordCount   int
	MinWordLen  int
	MaxWordLen  int
	AllowedDirs []Direction
}

WordSearchMode implements game.Mode for word search puzzles

func NewMode

func NewMode(title, description string, width, height, wordCount, minLen, maxLen int, allowedDirs []Direction) WordSearchMode

NewMode creates a new WordSearchMode with the given parameters

func (WordSearchMode) Spawn

func (w WordSearchMode) Spawn() (game.Gamer, error)

Jump to

Keyboard shortcuts

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