Skip to content

Commit

Permalink
Add ScalaFX to gui creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nojipiz committed Sep 24, 2022
1 parent 5b48303 commit 609dd5e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions montecarlo_archery/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# sbt specific
dist/*
target/
target
lib_managed/
src_managed/
project/boot/
Expand Down
3 changes: 2 additions & 1 deletion montecarlo_archery/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lazy val root = project
scalaVersion := scala3Version,
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.scalanlp" %% "breeze" % "2.1.0"
"org.scalanlp" %% "breeze" % "2.1.0",
"org.scalafx" %% "scalafx" % "18.0.2-R29"
)
)
61 changes: 61 additions & 0 deletions montecarlo_archery/src/main/scala/view/StartView.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package view

import scalafx.Includes._
import scalafx.application.JFXApp3
import scalafx.scene.layout._
import scalafx.scene.control._
import scalafx.scene._
import scalafx.geometry._
import scalafx.geometry.Pos._
import scalafx.scene.paint.Color._
import viewmodel.ViewModel
import domain.Game
import domain.Game
import domain.GlobalResults
import domain.GlobalResults

object StartView extends JFXApp3 {

val viewModel = ViewModel()

override def start(): Unit = {
stage = new JFXApp3.PrimaryStage {
title.value = "Montecarlo Simulation"
scene = new Scene {
content = new BorderPane {
center = new HBox() {
children = Seq(GameAmountChooser(), WinnerTeam())
alignment = CenterLeft
}
}
}
}
}

def GameAmountChooser() = new HBox {
val gamesAmmountField = new TextField()
children = Seq(
new Label("Cantidad de juegos"),
gamesAmmountField,
new Button("Iniciar") {
onAction = _ => viewModel.startSimulation(gamesAmmountField.text)
}
)
}

def WinnerTeam() = new VBox {
val title = new Label("Equipo Ganador")
val winnerName = new Label("Ninguno")
val winnerScore = new Label("0")
viewModel.simulationGlobalResults.onChange { (_, _, results: GlobalResults) =>
results.winnerTeam match {
case Some(value) => {
winnerName.setText(value._1.toString())
winnerScore.setText(value._2.toString())
}
case _ => print("No value")
}
}
children = winnerName
}
}

0 comments on commit 609dd5e

Please sign in to comment.