Guest User

Untitled

a guest
May 27th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. class NeighborhoodView: View() {
  2. // dependency injection
  3. private val controller: NeighborhoodController by inject()
  4.  
  5. // set up neighborhood
  6. override val root = gridpane {
  7. vgap = 15.0
  8. padding = insets(15)
  9. row {
  10. add(controller.grassPane())
  11. add(controller.grassPane())
  12. add(controller.housePane(Pos.BASELINE_LEFT))
  13. add(controller.verticalStreetPane())
  14. add(controller.housePane(Pos.BASELINE_CENTER))
  15. add(controller.verticalStreetPane())
  16. add(controller.housePane(Pos.BASELINE_RIGHT))
  17. add(controller.grassPane())
  18. }
  19. // you can add a lot more rows below as you like.
  20. // use this to check placement:
  21. // isGridLinesVisible = true
  22. }
  23. }
  24.  
  25. class Styles : Stylesheet() {
  26. companion object {
  27. val main by cssclass()
  28. val neighborhood by cssclass()
  29. }
  30.  
  31. init {
  32. main {
  33. backgroundColor += c("222222")
  34. }
  35.  
  36. neighborhood {
  37. backgroundColor += c("4E9830")
  38. prefWidth = 470.px
  39. prefHeight = 590.px
  40. }
  41. }
  42. }
  43.  
  44.  
  45. // in the controller package
  46. class NeighborhoodController: Controller() {
  47.  
  48. fun housePane(position: Pos): StackPane {
  49. val houseNum = (1..6).random()
  50.  
  51. return StackPane().apply {
  52. rectangle {
  53. fill = c("4E9830")
  54. width = 100.0
  55. height = 100.0
  56. }
  57. imageview("house$houseNum.png").apply {
  58. alignment = position
  59. }
  60. }
  61. }
  62.  
  63. fun grassPane(): StackPane {
  64. return StackPane().apply {
  65. rectangle {
  66. fill = c("4E9830")
  67. width = 100.0
  68. height = 100.0
  69. }
  70. }
  71. }
  72.  
  73. fun verticalStreetPane(): StackPane {
  74. return StackPane().apply {
  75. rectangle {
  76. fill = c("4E9830")
  77. width = 100.0
  78. height = 100.0
  79. }
  80. rectangle {
  81. fill = c("919191")
  82. width = 40.0
  83. height= 100.0
  84. }
  85. }
  86. }
  87.  
  88. private fun ClosedRange<Int>.random() = Random().nextInt(endInclusive - start) + start
  89.  
  90. }
Add Comment
Please, Sign In to add comment