Skip to content

Commit 131fa08

Browse files
feat(blokus): human can skip turn (#124)
1 parent 1f01202 commit 131fa08

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/main/kotlin/sc/gui/controller/BlokusController.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import javafx.beans.property.Property
77
import javafx.beans.value.ObservableValue
88
import org.slf4j.LoggerFactory
99
import sc.api.plugins.Coordinates
10+
import sc.api.plugins.IMove
1011
import sc.api.plugins.Team
1112
import sc.gui.GameOverEvent
1213
import sc.gui.GameReadyEvent
@@ -254,6 +255,12 @@ class BlokusController : Controller() {
254255
fun scroll(deltaY: Double) {
255256
currentPiece.get().scroll(deltaY)
256257
}
258+
259+
fun sendHumanMove(move: IMove) {
260+
fire(HumanMoveAction(move.also {
261+
logger.debug("Human Move: {}", it)
262+
}))
263+
}
257264

258265
companion object {
259266
private val logger = LoggerFactory.getLogger(BlokusController::class.java)

src/main/kotlin/sc/gui/view/PlayerOneView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import javafx.geometry.Pos
66
import sc.api.plugins.Team
77
import sc.gui.controller.BlokusController
88
import sc.gui.model.GameModel
9+
import sc.gui.view.game.SkipMoveButton
910
import sc.plugin2027.Color
1011
import tornadofx.*
1112

@@ -29,6 +30,7 @@ class PlayerOneView(gameController: BlokusController, gridSize: DoubleBinding):
2930
gameController.validPieces.getValue(Color.RED),
3031
gridSize
3132
))
33+
add(SkipMoveButton(gameController, gridSize, Team.ONE))
3234
// Run this later since scene is not ready yet
3335
runLater {
3436
this.padding = Insets(0.0, 0.0, 0.0, 0.0)

src/main/kotlin/sc/gui/view/PlayerTwoView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import javafx.geometry.Pos
66
import sc.api.plugins.Team
77
import sc.gui.controller.BlokusController
88
import sc.gui.model.GameModel
9+
import sc.gui.view.game.SkipMoveButton
910
import sc.plugin2027.Color
1011
import tornadofx.*
1112

@@ -29,6 +30,7 @@ class PlayerTwoView(gameController: BlokusController, gridSize: DoubleBinding):
2930
gameController.validPieces.getValue(Color.GREEN),
3031
gridSize
3132
))
33+
add(SkipMoveButton(gameController, gridSize, Team.TWO))
3234
// Run this later since scene is not ready yet
3335
runLater {
3436
this.padding = Insets(0.0, 0.0, 0.0, 0.0)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package sc.gui.view.game
2+
3+
import javafx.beans.binding.Bindings
4+
import javafx.beans.binding.DoubleBinding
5+
import javafx.scene.control.Button
6+
import sc.api.plugins.Team
7+
import sc.gui.controller.BlokusController
8+
import sc.plugin2027.SkipMove
9+
import tornadofx.onLeftClick
10+
11+
class SkipMoveButton(
12+
private val gameController: BlokusController,
13+
gridSize: DoubleBinding,
14+
team: Team
15+
) : Button("Aussetzen") {
16+
17+
init {
18+
prefWidthProperty().bind(gridSize.multiply(5))
19+
// Disable button if the current turn is not from a human player,
20+
// we cannot skip (i.e. the first round),
21+
// or if it is not our turn.
22+
disableProperty().bind(Bindings.createBooleanBinding(
23+
{ !(gameController.isHumanTurn.value && gameController.canSkip.value && gameController.currentColor.value.team == team) },
24+
gameController.isHumanTurn,
25+
gameController.canSkip,
26+
gameController.currentColor
27+
))
28+
onLeftClick {
29+
gameController.sendHumanMove(SkipMove(gameController.currentColor.value))
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)