diff options
Diffstat (limited to 'go/client/challenges.go')
| -rw-r--r-- | go/client/challenges.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/go/client/challenges.go b/go/client/challenges.go new file mode 100644 index 00000000..7a9e1ace --- /dev/null +++ b/go/client/challenges.go @@ -0,0 +1,76 @@ +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()) +} |
