clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

feat/app-decomposition
puzzletea / games / hitori / gamemode.go
gamemode.go 1.9K
1package hitori23import (4 _ "embed"5 "math/rand/v2"67 "github.com/FelineStateMachine/puzzletea/game"8 "github.com/FelineStateMachine/puzzletea/gameentry"9 "github.com/FelineStateMachine/puzzletea/puzzle"10)1112//go:embed help.md13var HelpContent string1415type HitoriMode struct {16 game.BaseMode17 Size int18 BlackRatio float6419}2021var (22 _ game.Mode = HitoriMode{}23 _ game.Spawner = HitoriMode{}24 _ game.SeededSpawner = HitoriMode{}25)2627func NewMode(title, desc string, size int, blackRatio float64) HitoriMode {28 return HitoriMode{29 BaseMode: game.NewBaseMode(title, desc),30 Size: size,31 BlackRatio: blackRatio,32 }33}3435func (h HitoriMode) Spawn() (game.Gamer, error) {36 puzzle, err := Generate(h.Size, h.BlackRatio)37 if err != nil {38 return nil, err39 }40 return New(h, puzzle)41}4243func (h HitoriMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error) {44 puzzle, err := GenerateSeeded(h.Size, h.BlackRatio, rng)45 if err != nil {46 return nil, err47 }48 return New(h, puzzle)49}5051var Modes = []game.Mode{52 NewMode("Mini", "5\u00d75 grid, gentle introduction.", 5, 0.32),53 NewMode("Easy", "6\u00d76 grid, straightforward logic.", 6, 0.32),54 NewMode("Medium", "8\u00d78 grid, moderate challenge.", 8, 0.30),55 NewMode("Tricky", "9\u00d79 grid, requires careful deduction.", 9, 0.30),56 NewMode("Hard", "10\u00d710 grid, advanced logic chains.", 10, 0.30),57 NewMode("Expert", "12\u00d712 grid, maximum challenge.", 12, 0.28),58}5960var ModeDefinitions = gameentry.BuildModeDefs(Modes)6162var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{63 Name: "Hitori",64 Description: "Shade the cells to eliminate duplicates.",65 Modes: ModeDefinitions,66 DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 1, 2),67})6869var Entry = gameentry.NewEntry(gameentry.EntrySpec{70 Definition: Definition,71 Help: HelpContent,72 Import: game.AdaptImport(ImportModel),73 Modes: Modes,74 Print: PDFPrintAdapter,75})