Skip to content

Commit

Permalink
feat: autostart game with blokus winnerclient
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Jul 7, 2021
1 parent d76f108 commit 6bb30ed
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/main/kotlin/sc/gui/controller/AppController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import javafx.beans.value.WritableValue
import mu.KLogging
import sc.gui.GameReadyEvent
import sc.gui.model.AppModel
import sc.gui.model.PlayerType
import sc.gui.model.TeamSettings
import sc.gui.model.ViewType
import sc.gui.model.ViewType.*
import sc.gui.view.*
Expand Down Expand Up @@ -32,8 +34,7 @@ class AppController: Controller() {
changeViewTo(GAME)
}
subscribe<CreateGame> {
if(model.currentView.get() != GAME_CREATION)
changeViewTo(GAME_CREATION)
fire(StartGameRequest(TeamSettings("Mensch", PlayerType.HUMAN), TeamSettings("Computer", PlayerType.COMPUTER_FINAL)))
}
subscribe<TerminateGame> {
changeViewTo(GAME_CREATION)
Expand Down
17 changes: 16 additions & 1 deletion src/main/kotlin/sc/gui/controller/ClientController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sc.plugin2021.SkipMove
import sc.plugin2021.util.GameRuleLogic
import tornadofx.Controller
import tornadofx.FXEvent
import java.io.File
import java.util.concurrent.CompletableFuture

data class StartGameRequest(val playerOneSettings: TeamSettings, val playerTwoSettings: TeamSettings): FXEvent()
Expand All @@ -41,8 +42,22 @@ class ClientController: Controller() {
PlayerType.HUMAN -> GuiClient(host, port, type, ::humanMoveRequest)
PlayerType.COMPUTER_EXAMPLE -> GuiClient(host, port, type, ::getSimpleMove)
PlayerType.COMPUTER -> ExecClient(host, port, teamSettings.executable.get())
PlayerType.COMPUTER_FINAL -> ExecClient(host, port,
File.createTempFile("software-challenge-gui-finalclient", null).apply {
val osName = System.getProperty("os.name").toLowerCase()
val os = when {
osName.contains("win") -> "windows.exe"
osName.contains("mac") -> "mac"
else -> "linux"
}

val out = outputStream()
resources.stream("/client/client-$os".also { println("starting $it from $this") })
.copyTo(out)
setExecutable(true)
out.close()
})
PlayerType.EXTERNAL -> ExternalClient(host, port)
else -> throw IllegalArgumentException("Cannot create game: Invalid playerType $type")
})
}
// TODO handle client start failures
Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/sc/gui/model/GameCreationModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ enum class PlayerType {
return "eigener Computerspieler, von GUI gestartet"
}
},
COMPUTER_FINAL {
override fun toString(): String {
return "Finalgewinner"
}
},
EXTERNAL {
override fun toString(): String {
return "eigener Computerspieler, manuell gestaret"
}
};
}

class TeamSettings {
val name = objectProperty("Team")
val type = objectProperty(PlayerType.HUMAN)
class TeamSettings(initialName: String = "Team", initialType: PlayerType = PlayerType.HUMAN) {
val name = objectProperty(initialName)
val type = objectProperty(initialType)
val executable = objectProperty<File>()

val isHuman
Expand Down
20 changes: 6 additions & 14 deletions src/main/kotlin/sc/gui/view/AppView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AppView : View("Software-Challenge Germany") {
val controller: AppController by inject()
private val gameFlowController: GameFlowController by inject()
private val gameController: GameController by inject()

private val sochaIcon = resources.imageview("/icon.png")

override val root = borderpane {
Expand Down Expand Up @@ -76,16 +77,13 @@ class AppView : View("Software-Challenge Germany") {
gameController.rotatePiece(Rotation.MIRROR)
}
}
item("Flippen", "R-Click oder CTRL").action {
item("Spiegeln", "R-Click oder CTRL").action {
gameController.flipPiece()
}
}
menu("Hilfe") {
item("Spielregeln", "Shortcut+S").action {
"https://cau-kiel-tech-inf.github.io/socha-enduser-docs/spiele/blokus/regeln.html".browseUrl()
}
item("Dokumentation", "Shortcut+D").action {
"https://cau-kiel-tech-inf.github.io/socha-enduser-docs/".browseUrl()
"https://docs.software-challenge.de/spiele/blokus/regeln.html".browseUrl()
}
item("Webseite", "Shortcut+I").action {
"https://www.software-challenge.de".browseUrl()
Expand Down Expand Up @@ -118,15 +116,7 @@ class AppView : View("Software-Challenge Germany") {
val gameTitle = "Blokus"
val version = resources.text("/version.txt")
val sochaTitle = "Software-Challenge GUI $version"
titleProperty.bind(controller.model.currentView.stringBinding {
when(it) {
ViewType.START -> sochaTitle
ViewType.GAME_CREATION -> "Neues Spiel - $sochaTitle"
ViewType.GAME_LOADING -> "Starte Spiel $gameTitle - $sochaTitle"
ViewType.GAME -> "Spiele $gameTitle - $sochaTitle"
null -> throw NoWhenBranchMatchedException("Current view can't be null!")
}
})
title = "Spiele $gameTitle - $sochaTitle"

controller.model.isDarkMode.listenImmediately { value ->
if (value) {
Expand All @@ -137,6 +127,8 @@ class AppView : View("Software-Challenge Germany") {
root.addClass(AppStyle.lightColorSchema)
}
}

fire(CreateGame)
}
}

Expand Down
Binary file added src/main/resources/client/client-linux
Binary file not shown.
Binary file added src/main/resources/client/client-mac
Binary file not shown.
Binary file added src/main/resources/client/client-windows.exe
Binary file not shown.

0 comments on commit 6bb30ed

Please sign in to comment.