aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-01 18:46:32 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:45 +0100
commit21a87ffccae9950580a240180fd3703768ef450e (patch)
tree1cb83289216bd1e213d417812b4e09001ca89c09 /go/client
parent3fd15c9b83fff074b588ff9688f9e49aab38cd32 (diff)
downloadmuhqs-game-21a87ffccae9950580a240180fd3703768ef450e.tar.gz
muhqs-game-21a87ffccae9950580a240180fd3703768ef450e.zip
intermediate commit
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go114
-rw-r--r--go/client/main.go3
-rw-r--r--go/client/startMenu.go10
3 files changed, 60 insertions, 67 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 2f112593..00ef4153 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -253,12 +253,13 @@ func (g *Game) removeWidgetAt(idx int) {
}
func (g *Game) addActionChoice(perm game.Permanent, x, y int) {
- actions := perm.AvailActionPrototypes()
+ actions := perm.AvailActions()
if len(actions) > 0 {
g.selectedObject = perm
onClick := func(c *ui.Choice, x, y int) {
g.removeActionChoice()
- g.selectedObject = actions[c.GetChoosen(x, y)]
+ a := actions[c.GetChoosen(x, y)]
+ g.selectedObject = a
}
g.actionChoice = ui.NewActionChoice(x, y, actions, onClick)
g.addWidget(g.actionChoice)
@@ -363,78 +364,63 @@ func (g *Game) findObjectAt(x, y int) interface{} {
return nil
}
+func (g *Game) handleTargetSelection(obj interface{}) {
+ log.Println("Handle target selection")
+ a := g.selectedObject.(game.Action)
+ a.Targets().AddTarget(obj)
+
+ if !a.Targets().RequireTargets() {
+ log.Println("declare", a)
+ g.declareAction(a)
+ g.selectedObject = nil
+ }
+}
+
func (g *Game) handleSelection(obj interface{}, x, y int) {
if obj == nil {
fmt.Printf("No object found at cursor position (%d, %d)\n", x, y)
return
}
- switch obj := obj.(type) {
- case ui.Button:
- obj.Click(x, y)
+ if _, ok := g.selectedObject.(game.Action); ok {
+ g.handleTargetSelection(obj)
+ } else {
+ switch obj := obj.(type) {
+ case ui.Button:
+ obj.Click(x, y)
- case *game.Tile:
- tile := obj
- if g.selectedObject != nil {
- var action game.Action
- switch obj := g.selectedObject.(type) {
- case *game.MoveActionPrototype:
- action = obj.Specialize(g.gameState, tile)
- case *game.Card:
- if obj.IsPermanent() {
- action = game.NewPlayAction(g.activePlayer, obj, tile.Position)
- }
- }
- if action != nil {
- g.declareAction(action)
- g.selectedObject = nil
- g.mapView.HighlightTile(tile)
- }
- } else {
- g.mapView.HighlightTile(tile)
- }
+ case *game.Tile:
+ g.mapView.HighlightTile(obj)
- case game.Permanent:
- perm := obj
- if g.selectedObject == nil {
+ case game.Permanent:
+ perm := obj
g.addActionChoice(perm, x, y)
- } else {
- switch obj := g.selectedObject.(type) {
- case *game.AttackActionPrototype:
- action := obj.Specialize(g.gameState, perm)
- g.selectedObject = nil
- g.declareAction(action)
- g.mapView.HighlightPermanent(perm)
- }
- }
- case ui.HandCard:
- g.selectedObject = obj.C
+ case ui.HandCard:
+ g.selectedObject = game.NewPlayAction(g.activePlayer, obj.C)
+ g.handLayer.HighlightCard(obj.C)
- case *game.Card:
- if g.gameState.IsActivePlayer(g.activePlayer) &&
- g.gameState.ActivePhase == game.Phases.BuyPhase {
- g.declareAction(game.NewBuyAction(g.activePlayer, obj))
- }
+ case *game.Card:
+ if g.gameState.IsActivePlayer(g.activePlayer) &&
+ g.gameState.ActivePhase == game.Phases.BuyPhase {
+ g.declareAction(game.NewBuyAction(g.activePlayer, obj))
+ }
- default:
- log.Fatalf("Object of type %T not handled", obj)
+ default:
+ log.Fatalf("Object of type %T not handled", obj)
+ }
}
}
-func (g *Game) hightlightSelection(obj interface{}) {
- switch obj := g.selectedObject.(type) {
- case *game.MoveActionPrototype:
- g.mapView.HighlightTiles(obj.Unit.MoveRangeTiles(g.gameState.Map))
- case *game.AttackActionPrototype:
- perms := obj.Unit.AttackablePermanents(g.gameState.Map)
- g.mapView.HighlightPermanents(perms)
- case *game.Card:
- g.handLayer.HighlightCard(obj)
- if obj.IsPermanent() {
- spawnTiles := g.gameState.AvailableSpawnTiles(g.activePlayer, obj)
- g.mapView.HighlightTiles(spawnTiles)
- }
+func (g *Game) highlightTargets() {
+ a, ok := g.selectedObject.(game.Action)
+ if !ok {
+ return
+ }
+
+ options := a.Targets().NextOptions()
+ for _, option := range options {
+ g.AddHighlight(option)
}
}
@@ -489,6 +475,15 @@ func (g *Game) Update() error {
obj := g.findObjectAt(x, y)
+ scrollX, scrollY := ebiten.Wheel()
+ if scrollX != 0 || scrollY != 0 {
+ if scrollable, ok := obj.(ui.Scrollable); ok {
+ scrollable.Scroll(int(scrollX), int(scrollY))
+ }
+ }
+
+ g.highlightTargets()
+
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
if g.prompt != nil {
g.prompt.Add(obj)
@@ -496,7 +491,6 @@ func (g *Game) Update() error {
} else {
g.handleSelection(obj, x, y)
}
- g.hightlightSelection(obj)
} else if g.hoverDetector.startedHovering() && g.selectedObject == nil && obj != nil {
g.handleHover(obj, x, y)
} else if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
diff --git a/go/client/main.go b/go/client/main.go
index 63fcab00..3635404f 100644
--- a/go/client/main.go
+++ b/go/client/main.go
@@ -31,7 +31,7 @@ type app struct {
windowWidth int
windowHeight int
- active ebiten.Game
+ active ebiten.Game
running bool
}
@@ -63,7 +63,6 @@ func main() {
flag.StringVar(&startMenu.remote, "remote", "", "address of remote game to connect to")
flag.Parse()
-
ebiten.SetWindowSize(app.windowWidth, app.windowHeight)
ebiten.SetWindowTitle("Muhq's Game")
diff --git a/go/client/startMenu.go b/go/client/startMenu.go
index 07c4f92b..735753b0 100644
--- a/go/client/startMenu.go
+++ b/go/client/startMenu.go
@@ -10,12 +10,12 @@ import (
)
const (
- START_BUTTON_WIDTH = 150
+ START_BUTTON_WIDTH = 150
START_BUTTON_HEIGHT = 50
)
type StartMenu struct {
- app *app
+ app *app
width, height int
playerName string
@@ -31,10 +31,10 @@ func NewStartMenu(app *app) *StartMenu {
return m
}
-func (m *StartMenu) build () {
+func (m *StartMenu) build() {
m.widgets = append(m.widgets, ui.NewSimpleButton(
- (m.width - START_BUTTON_WIDTH) / 2,
- (m.height - START_BUTTON_HEIGHT) / 2,
+ (m.width-START_BUTTON_WIDTH)/2,
+ (m.height-START_BUTTON_HEIGHT)/2,
150,
50,
"Start",