Skip to content

Commit

Permalink
feat(mq): allow manual acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Oct 2, 2023
1 parent fa59d7b commit 9e479d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/sc/gui/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ val guideMq = """
- Das Label "S" an den Schiffen ist die aktuelle Geschwindigkeit
- Das Label "M" am aktuellen Schiff sind die offenen Bewegungspunkte
(Bei Bestätigung des Zuges wird aus diesen automatisch die nötige Beschleunigungsaktion berechnet)
- Optional kann man am Beginn des Zuges manuell über die Knöpfe + und - beschleunigen.
- Bewegungen menschlicher Spieler können über die Knöpfe oder die korrespondierenden Buchstabentasten erfolgen
- Mit der Taste "S" wird der aktuelle Zug abgeschickt, mit "C" zurückgesetzt
- Kohle wird automatisch abgezogen anhand der Regeln
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/sc/gui/view/GameCreationView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class GameCreationView: View() {

override val root = borderpane {
padding = Insets(AppStyle.spacing)
top = hbox(AppStyle.spacing, Pos.CENTER_RIGHT) {
button("Replay laden").action { selectReplay() }
}
center = form {
alignment = Pos.CENTER
label("Willkommen bei der Software-Challenge!") {
Expand Down Expand Up @@ -55,17 +58,14 @@ class GameCreationView: View() {
}
}
}
top = hbox(AppStyle.spacing, Pos.CENTER_RIGHT) {
button("Replay laden").action { selectReplay() }
}
bottom = hbox(AppStyle.spacing, Pos.CENTER_RIGHT) {
button("Erstellen") {
action {
playerSettingsModels.all { it.commit() }
fire(StartGame(playerSettingsModels.map { it.item }))
}
enableWhen(Bindings.and(playerSettingsModels[0].valid, playerSettingsModels[1].valid))
}
}.requestFocus()
}
}
}
Expand Down
35 changes: 27 additions & 8 deletions src/main/kotlin/sc/gui/view/MississippiBoard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class MississippiBoard: View() {
state.board.forEachField { cubeCoordinates, field ->
(state.board.getFieldCurrentDirection(cubeCoordinates)?.let { dir ->
createPiece("stream").also { it.rotate = dir.angle.toDouble() }
} ?: createPiece((if(field == Field.GOAL) Field.WATER else field).toString().lowercase())).also { piece ->
} ?: createPiece((if(field == Field.GOAL) Field.WATER else field)
.toString().lowercase())).also { piece ->
if(field.isEmpty) {
piece.viewOrder++
val push = pushes.firstOrNull { state.currentShip.position + it.direction.vector == cubeCoordinates }
Expand Down Expand Up @@ -206,16 +207,27 @@ class MississippiBoard: View() {
addPiece(VBox().apply {
translateX = -(AppStyle.spacing * 5)
translateY = gridSize / 10
if(humanMove.all { it is Accelerate }) {
val acc = (humanMove.firstOrNull() as? Accelerate)?.acc ?: 0
hbox {
if(ship.speed < 6 && acc > -1)
button("+") { action { addHumanAction(Accelerate(1)) } }
if(ship.speed > 1 && acc < 1)
button("-") { action { addHumanAction(Accelerate(-1)) } }
}
}
if(ship.canTurn())
button("↺ A") { action { addHumanAction(Turn(ship.direction - 1)) } }
if(ship.canAdvance())
button("→ W") { action { addHumanAction(Advance(1)) } }
if(ship.canTurn())
button("↻ D") { action { addHumanAction(Turn(ship.direction + 1)) } }
if(!isHumanMoveIncomplete())
button("✓ S") { action { confirmHumanMove() } }
if(humanMove.isNotEmpty())
button("╳ C") { action { cancelHumanMove() } }
hbox {
if(!isHumanMoveIncomplete())
button("✓ S") { action { confirmHumanMove() } }
if(humanMove.isNotEmpty())
button("╳ C") { action { cancelHumanMove() } }
}
}, ship.position)
}
}
Expand All @@ -229,7 +241,7 @@ class MississippiBoard: View() {

val newState = state.clone()
val ship = newState.currentShip
val extraMovement = ship.maxAcc
val extraMovement = ship.maxAcc.takeUnless { humanMove.firstOrNull() is Accelerate } ?: 0
// Continual Advance on current
val currentAdvance = humanMove.lastOrNull() is Advance && action is Advance &&
state.isCurrentShipOnCurrent() && state.board.doesFieldHaveCurrent(state.currentShip.position + state.currentShip.direction.vector * action.distance)
Expand All @@ -240,7 +252,10 @@ class MississippiBoard: View() {
alert(Alert.AlertType.ERROR, it.message)
} ?: run {
ship.movement -= extraMovement
humanMove.add(action)
if(action is Accelerate && humanMove.isNotEmpty())
humanMove[0] = humanMove[0] as Accelerate + action
else
humanMove.add(action)
gameModel.gameState.set(newState)
}
}
Expand All @@ -251,7 +266,11 @@ class MississippiBoard: View() {
}

private fun isHumanMoveIncomplete() =
humanMove.none { it is Advance } || gameState?.let { state -> state.currentShip.movement > state.currentShip.freeAcc + state.currentShip.coal || state.mustPush } ?: true
humanMove.none { it is Advance } || gameState?.let { state ->
state.currentShip.movement > state.currentShip.freeAcc + state.currentShip.coal ||
humanMove.first() is Accelerate && state.currentShip.movement != 0 ||
state.mustPush
} ?: true

private fun confirmHumanMove() {
if(awaitingHumanMove() && isHumanMoveIncomplete()) {
Expand Down

0 comments on commit 9e479d4

Please sign in to comment.