Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NeighborhoodView: View() {
- // dependency injection
- private val controller: NeighborhoodController by inject()
- // set up neighborhood
- override val root = gridpane {
- vgap = 15.0
- padding = insets(15)
- row {
- add(controller.grassPane())
- add(controller.grassPane())
- add(controller.housePane(Pos.BASELINE_LEFT))
- add(controller.verticalStreetPane())
- add(controller.housePane(Pos.BASELINE_CENTER))
- add(controller.verticalStreetPane())
- add(controller.housePane(Pos.BASELINE_RIGHT))
- add(controller.grassPane())
- }
- // you can add a lot more rows below as you like.
- // use this to check placement:
- // isGridLinesVisible = true
- }
- }
- class Styles : Stylesheet() {
- companion object {
- val main by cssclass()
- val neighborhood by cssclass()
- }
- init {
- main {
- backgroundColor += c("222222")
- }
- neighborhood {
- backgroundColor += c("4E9830")
- prefWidth = 470.px
- prefHeight = 590.px
- }
- }
- }
- // in the controller package
- class NeighborhoodController: Controller() {
- fun housePane(position: Pos): StackPane {
- val houseNum = (1..6).random()
- return StackPane().apply {
- rectangle {
- fill = c("4E9830")
- width = 100.0
- height = 100.0
- }
- imageview("house$houseNum.png").apply {
- alignment = position
- }
- }
- }
- fun grassPane(): StackPane {
- return StackPane().apply {
- rectangle {
- fill = c("4E9830")
- width = 100.0
- height = 100.0
- }
- }
- }
- fun verticalStreetPane(): StackPane {
- return StackPane().apply {
- rectangle {
- fill = c("4E9830")
- width = 100.0
- height = 100.0
- }
- rectangle {
- fill = c("919191")
- width = 40.0
- height= 100.0
- }
- }
- }
- private fun ClosedRange<Int>.random() = Random().nextInt(endInclusive - start) + start
- }
Add Comment
Please, Sign In to add comment