Skip to content

Commit

Permalink
fix start game in launcher controller
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoDiGirolamo committed Jul 25, 2023
1 parent c7e225e commit bb22cb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 15 additions & 1 deletion src/main/scala/controller/LauncherController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import model.infection.VirusConfiguration
import model.powerUp.{PowerUp, PowerUpType}
import model.world.Filters.given
import model.world.Region
import view.game.GameView

/**
* Class that represent the controller that bind the Game Model with the Launcher View
Expand All @@ -16,4 +17,17 @@ class LauncherController(val gameModel: GameModel):
*/
def getAllRegions: List[Region] = gameModel.world.getRegions


/**
* Start a game session
* @param startRegionName is the start region name
* @param virusName is the game virus name
*/
def startGame(startRegionName: String, virusName: String): Unit =
val gameEngine: GameEngine = new GameEngine(gameModel)
val gameView: GameView = new GameView(gameEngine)
gameEngine.setGameView(gameView)
new Thread {
override def run(): Unit =
gameView.start()
gameEngine.start(startRegionName, virusName)
}.start()
9 changes: 1 addition & 8 deletions src/main/scala/view/launcher/LauncherView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ class LauncherView(val launcherController: LauncherController):
constraints.gridy = constraints.gridy + 1
val btnStartGame: JButton = new JButton("Start game!")
btnStartGame.addActionListener((e: ActionEvent) => {
val gameEngine: GameEngine = new GameEngine(this.launcherController.gameModel)
val gameView: GameView = new GameView(gameEngine)
gameEngine.setGameView(gameView)
new Thread{
override def run(): Unit =
gameView.start()
gameEngine.start(lstRegions.getSelectedValue, txtVirusName.getText)
}.start()
this.launcherController.startGame(lstRegions.getSelectedValue, txtVirusName.getText)
this.frame.dispose()
})
btnStartGame.setEnabled(false)
Expand Down

0 comments on commit bb22cb9

Please sign in to comment.