diff options
Diffstat (limited to 'go/client')
| -rw-r--r-- | go/client/challenges.go | 76 | ||||
| -rw-r--r-- | go/client/startMenu.go | 17 |
2 files changed, 78 insertions, 15 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()) +} diff --git a/go/client/startMenu.go b/go/client/startMenu.go index 2c3225b9..aef43ab0 100644 --- a/go/client/startMenu.go +++ b/go/client/startMenu.go @@ -137,11 +137,9 @@ func (m *startMenu) build() { deckInput.Y+deckInput.Height+4*START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, - "Challenge", + "Challenges", func(*ui.SimpleButton) { - m.playerName = playerInput.Text() - s := game.NewRandomChallenge(m.playerName) - m.startChallenge(s) + activities.PushActivity(NewChallengesMenu(m.app, playerInput.Text())) })) } @@ -189,14 +187,3 @@ func (m *startMenu) startGame() { activities.PushActivity(g.Start()) } - -func (m *startMenu) 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()) -} |
