package main import ( "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/activities" "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) var availChallenges = map[string]func(string) *game.LocalState{ "Missionary": game.NewMissionaryChallenge, "Cav. Archer": game.NewCavArcherChallenge, "Random": game.NewRandomChallenge, } type challenges struct { bl *activities.ButtonList app *app playerName string } func newChallengesMenu(app *app, playerName string) *challenges { var m *challenges labels := make([]string, 0, len(availChallenges)) handlers := make([]func(*ui.SimpleButton), 0, len(availChallenges)) for k, start := range availChallenges { labels = append(labels, k) handlers = append(handlers, func(*ui.SimpleButton) { s := start(m.playerName) m.startChallenge(s) }) } m = &challenges{ bl: activities.NewButtonList(app.windowWidth, app.windowHeight, labels, handlers), app: app, playerName: playerName, } return m } func (m *challenges) startChallenge(state game.State) { g := newGame(m.app, state) g.initMapUi() p := state.PlayerByName(m.playerName) g.activePlayerId = p.Id g.initPlayerUi(p) activities.PushActivity(g.Start()) } func (c *challenges) Draw(screen *ebiten.Image) { c.bl.Draw(screen) } func (c *challenges) Layout(w, h int) (int, int) { return c.bl.Layout(w, h) } func (c *challenges) Update() error { return c.bl.Update() }