Guest User

Untitled

a guest
Jun 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. class Tile(var value: Int = 0){
  2.  
  3. }
  4.  
  5. class Board() {
  6. var _tiles = Array<Tile>(100) {Tile()} //Represents a 10x10 playing board
  7.  
  8. var tiles
  9. get(x: Int, y: Int) {return _tiles[y * 10 + x]}
  10. set(x:Int, y: Int, value: Tile) {_tiles[y * 10 + x] = value}
  11.  
  12. }
  13.  
  14. fun main(args: Array<String>) {
  15. val board = Board()
  16. board.tiles[0,0].value = 42
  17. }
  18.  
  19. class Board() {
  20.  
  21. private var _tiles = Array<Tile>(100) { Tile() } //Represents a 10x10 playing board
  22.  
  23. operator fun get(x: Int, y: Int): Tile {
  24. return _tiles[y * 10 + x]
  25. }
  26.  
  27. operator fun set(x: Int, y: Int, value: Tile) {
  28. _tiles[y * 10 + x] = value
  29. }
  30.  
  31. }
  32.  
  33. val board = Board()
  34. board[0, 0].value = 42
  35. println(board[0, 0])
  36.  
  37. class Board {
  38. var tiles = Array(100) { Tile() } //Represents a 10x10 playing board
  39.  
  40. operator fun get(x: Int, y: Int) = tiles[y * 10 + x]
  41.  
  42. operator fun set(x: Int, y: Int, value: Tile) {
  43. tiles[y * 10 + x] = value
  44. }
  45.  
  46. }
  47.  
  48. fun main(args: Array<String>) {
  49. val board = Board()
  50. board[0, 0].value = 42
  51. }
  52.  
  53. val t: Tile = Tile(0)
  54. val tiles = Array(10) { Array<Tile>(10) { t } } // for initialization
  55. tiles[0][0] = Tile(5)
  56. tiles[0][1] = Tile(7)
  57. ....................
Add Comment
Please, Sign In to add comment