clone

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

feat/app-decomposition
puzzletea / games / hashiwokakero / gamemode.go
gamemode.go 2.5K
1package hashiwokakero23import (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 HashiMode struct {16 game.BaseMode17 Width int18 Height int19 MinIslands int20 MaxIslands int21}2223var (24 _ game.Mode = HashiMode{}25 _ game.Spawner = HashiMode{}26 _ game.SeededSpawner = HashiMode{}27)2829func NewMode(title, description string, width, height, minIslands, maxIslands int) HashiMode {30 return HashiMode{31 BaseMode: game.NewBaseMode(title, description),32 Width: width,33 Height: height,34 MinIslands: minIslands,35 MaxIslands: maxIslands,36 }37}3839func (h HashiMode) Spawn() (game.Gamer, error) {40 puzzle, err := GeneratePuzzle(h)41 if err != nil {42 return nil, err43 }44 return New(h, puzzle), nil45}4647func (h HashiMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error) {48 puzzle, err := GeneratePuzzleSeeded(h, rng)49 if err != nil {50 return nil, err51 }52 return New(h, puzzle), nil53}5455var Modes = []game.Mode{56 NewMode("Easy 7x7", "7x7 grid with 8-10 islands.", 7, 7, 8, 10),57 NewMode("Medium 7x7", "7x7 grid with 12-15 islands.", 7, 7, 12, 15),58 NewMode("Hard 7x7", "7x7 grid with 17-20 islands.", 7, 7, 17, 20),59 NewMode("Easy 9x9", "9x9 grid with 12-16 islands.", 9, 9, 12, 16),60 NewMode("Medium 9x9", "9x9 grid with 20-24 islands.", 9, 9, 20, 24),61 NewMode("Hard 9x9", "9x9 grid with 28-32 islands.", 9, 9, 28, 32),62 NewMode("Easy 11x11", "11x11 grid with 18-24 islands.", 11, 11, 18, 24),63 NewMode("Medium 11x11", "11x11 grid with 30-36 islands.", 11, 11, 30, 36),64 NewMode("Hard 11x11", "11x11 grid with 42-48 islands.", 11, 11, 42, 48),65 NewMode("Easy 13x13", "13x13 grid with 25-34 islands.", 13, 13, 25, 34),66 NewMode("Medium 13x13", "13x13 grid with 42-51 islands.", 13, 13, 42, 51),67 NewMode("Hard 13x13", "13x13 grid with 59-68 islands.", 13, 13, 59, 68),68}6970var ModeDefinitions = gameentry.BuildModeDefs(Modes)7172var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{73 Name: "Hashiwokakero",74 Description: "Connect the islands with bridges.",75 Aliases: []string{"hashi", "bridges"},76 Modes: ModeDefinitions,77 DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 3, 1),78})7980var Entry = gameentry.NewEntry(gameentry.EntrySpec{81 Definition: Definition,82 Help: HelpContent,83 Import: game.AdaptImport(ImportModel),84 Modes: Modes,85 Print: PDFPrintAdapter,86})