package main import ( "muhq.space/muhqs-game/go/activities" "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) type challenges struct { ui.Collection app *app playerName string } func NewChallengesMenu(app *app, playerName string) *challenges { m := &challenges{app: app, playerName: playerName} m.Width = app.windowWidth m.Height = app.windowHeight return m } var availChallenges map[string]func(string) *game.LocalState func init() { availChallenges = make(map[string]func(string) *game.LocalState) availChallenges["Missionary"] = game.NewMissionaryChallenge availChallenges["Cav. Archer"] = game.NewCavArcherChallenge availChallenges["Random"] = game.NewRandomChallenge } func (m *challenges) build() { i := 0 for ch, f := range availChallenges { m.AddWidget(ui.NewSimpleButton( (m.Width-START_BUTTON_WIDTH)/2, i*START_BUTTON_HEIGHT+50+i*25, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, ch, func(*ui.SimpleButton) { s := f(m.playerName) m.startChallenge(s) })) i = i + 1 } } func (m *challenges) Update() error { if m.Widgets() == nil { m.build() } if err := ui.Update(); err != nil { return err } return m.Collection.Update() } func (m *challenges) Layout(width, height int) (int, int) { return m.Width, m.Height } 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()) }