hangman

package module
v0.0.0-...-7e4284f Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GameEntry = `entry`
	GameEP    = `ep`
)

Is it an entry round or an EP round?

View Source
const (
	// SpecialChars collects characters that shouldn't be turned into '_'
	SpecialChars string = `"[]-(),.:;?!'& /_\`
)

Variables

This section is empty.

Functions

func CreateBlankName

func CreateBlankName(name string) string

CreateBlankName generates a string in which each character is replaced with a '_', except for the SpecialChars.

func ReplaceLetter

func ReplaceLetter(name, blankName, letter string) string

ReplaceLetter inserts each occurence of the given letter in name on blankName.

func ReplaceWord

func ReplaceWord(name, blankName, word string) string

ReplaceWord inserts the first occurence of the given word in name on blankName.

Types

type EP

type EP struct {
	Entry

	Entries []*Entry `json:"entries"`
}

EP holds plenty of entries while also being an entry itself.

func NewEP

func NewEP(name, player string) *EP

NewEP generates an EP object with given parameters.

func (*EP) Add

func (ep *EP) Add(e *Entry)

Add appends an entry to the EP

func (*EP) GuessLetter

func (ep *EP) GuessLetter(l string)

GuessLetter tries to fill all instance of the given letter in all the entries' BlankName.

func (*EP) GuessWord

func (ep *EP) GuessWord(w string)

GuessWord tries to fill the given word in all the entries' BlankName. Only replaces the first instance of the word per entry if it exists.

type Entry

type Entry struct {
	Player

	// Usually the song or album's name
	Title string `json:"title"`

	// This represents the title as a sequence of "_", ready to be filled
	BlankTitle string `json:"blank_title"`
}

Entry represents a song, or album sent by a player.

func NewEntry

func NewEntry(title, player string) *Entry

NewEntry generates an Entry object with given parameters.

func (*Entry) GuessLetter

func (e *Entry) GuessLetter(l string)

GuessLetter tries to fill all instances of the given letter in the entry's BlankTitle. If it's already been guessed, nothing happens.

func (*Entry) GuessWord

func (e *Entry) GuessWord(w string)

GuessWord tries to fill the given word in the entry's BlankTitle. Only replaces the first instance of the word if it exists.

type Game

type Game struct {
	Category string `json:"category"`
}

Game represents the currently running game

type Guesses

type Guesses struct {
	Letters  []string `json:"letters"`
	Words    []string `json:"words"`
	Players  []Player `json:"players_guessing"`
	MaxTurns int      `json:"max_turns"`
}

Guesses keeps track of the many guesses players make during the game.

func NewGuesses

func NewGuesses(maxturns ...uint) *Guesses

NewGuesses returns a pointer to a Guesses type, with the given MaxTurns. If missing or given 0, it defaults to 3.

func (*Guesses) AddLetter

func (g *Guesses) AddLetter(l string)

AddLetter to the list of guesses.

func (*Guesses) AddPlayer

func (g *Guesses) AddPlayer(p Player)

AddPlayer a player to the end of a turn queue, and removes the first one.

func (*Guesses) AddWord

func (g *Guesses) AddWord(w string)

AddWord to the list of guesses.

func (*Guesses) Load

func (g *Guesses) Load(filename string) error

Load all the guesses from a JSON file.

func (*Guesses) RepeatedLetter

func (g *Guesses) RepeatedLetter(l string) bool

RepeatedLetter checks if a given letter exists in the list of guesses.

func (*Guesses) RepeatedWord

func (g *Guesses) RepeatedWord(w string) bool

RepeatedWord checks if a word exists in the list of guesses.

func (*Guesses) Save

func (g *Guesses) Save(filename string) error

Save all the guesses to a JSON file.

type Player

type Player struct {
	Name    string `json:"name"`
	Guessed bool   `json:"guessed"`
}

Player represents a user playing the game

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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