lettersnake

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package lettersnake contains game logic.

Index

Constants

View Source
const (
	// NotStarted indicates that the game has not started yet.
	NotStarted = iota

	// GameOn indicates that the game is currently in progress.
	GameOn

	// GameOver indicates that the game has ended.
	GameOver
)

Game state.

View Source
const (
	// MovingDown indicates that the snake is moving downward.
	MovingDown = iota

	// MovingUp indicates that the snake is moving upward.
	MovingUp

	// MovingLeft indicates that the snake is moving to the left.
	MovingLeft

	// MovingRight indicates that the snake is moving to the right.
	MovingRight
)

Direction represents the direction in which the snake is moving.

View Source
const (

	// EdgeHit indicates that the snake has hit the edge of the screen.
	EdgeHit

	// AteItself indicates that the snake has collided with its own body.
	AteItself

	// AllWordsUsed means all words in the list have already been used.
	AllWordsUsed

	// ContinueGame indicates that the game should continue running.
	ContinueGame
)

Game iteration result.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

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

Game holds the state and data of the game.

func NewGame

func NewGame() *Game

NewGame returns new Game instance.

func (*Game) ConsumedLetters

func (g *Game) ConsumedLetters() string

ConsumedLetters returns letters that have been consumed by the snake so far.

func (*Game) CurrentTranslation

func (g *Game) CurrentTranslation() string

CurrentTranslation returns the translation of the current word.

func (*Game) CurrentWord

func (g *Game) CurrentWord() string

CurrentWord returns the current word that is being guessed by the player.

func (*Game) Direction

func (g *Game) Direction() int

Direction returns direction snake is moving.

func (*Game) IsPlayAreaSizeSet added in v0.5.0

func (g *Game) IsPlayAreaSizeSet() bool

IsPlayAreaSizeSet determines whether the play area size was set.

func (*Game) Iterate

func (g *Game) Iterate() int

Iterate runs one iteration of the game.

func (*Game) Letters

func (g *Game) Letters() *map[int]map[int]rune

Letters returns two-dimensional map of letter positions on the play area.

func (*Game) NumCorrectGuesses added in v0.5.0

func (g *Game) NumCorrectGuesses() int

NumCorrectGuesses returns the number of correctly guessed words.

func (*Game) NumUsedWords

func (g *Game) NumUsedWords() int

NumUsedWords returns the number of words used so far in the game.

func (*Game) NumWordList added in v0.5.0

func (g *Game) NumWordList() int

NumWordList returns the total number of words in the input list.

func (*Game) RandomizeWords

func (g *Game) RandomizeWords()

RandomizeWords reorders the word list in a random order.

func (*Game) ReadWords

func (g *Game) ReadWords(f io.Reader)

ReadWords reads list of words from a text file.

func (*Game) SetDirection

func (g *Game) SetDirection(direction int)

SetDirection changes direction snake is moving.

func (*Game) SetPlayAreaSize added in v0.5.0

func (g *Game) SetPlayAreaSize(width int, height int)

SetPlayAreaSize sets size of the play area on which the snake can move.

func (*Game) Snake

func (g *Game) Snake() []Segment

Snake returns snake's Segments.

func (*Game) StartGame

func (g *Game) StartGame()

StartGame resets all game variables and starts a new game.

func (*Game) State

func (g *Game) State() int

State returns current state of the game.

func (*Game) StopGame

func (g *Game) StopGame()

StopGame sets the game state to GameOver.

func (*Game) Tail added in v0.5.0

func (g *Game) Tail() *Segment

Tail returns last Segment of the snake.

func (*Game) WordListTitle added in v0.5.0

func (g *Game) WordListTitle() string

WordListTitle returns title of the word list.

type Letter

type Letter struct {
	PositionX int
	PositionY int
	Letter    string
}

Letter represents a single character displayed at a specific position on the screen.

type Segment

type Segment struct {
	PositionX int
	PositionY int
}

Segment represents a segment of the snake with its position on the screen.

Jump to

Keyboard shortcuts

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