Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Tile(var value: Int = 0){
- }
- class Board() {
- var _tiles = Array<Tile>(100) {Tile()} //Represents a 10x10 playing board
- var tiles
- get(x: Int, y: Int) {return _tiles[y * 10 + x]}
- set(x:Int, y: Int, value: Tile) {_tiles[y * 10 + x] = value}
- }
- fun main(args: Array<String>) {
- val board = Board()
- board.tiles[0,0].value = 42
- }
- class Board() {
- private var _tiles = Array<Tile>(100) { Tile() } //Represents a 10x10 playing board
- operator fun get(x: Int, y: Int): Tile {
- return _tiles[y * 10 + x]
- }
- operator fun set(x: Int, y: Int, value: Tile) {
- _tiles[y * 10 + x] = value
- }
- }
- val board = Board()
- board[0, 0].value = 42
- println(board[0, 0])
- class Board {
- var tiles = Array(100) { Tile() } //Represents a 10x10 playing board
- operator fun get(x: Int, y: Int) = tiles[y * 10 + x]
- operator fun set(x: Int, y: Int, value: Tile) {
- tiles[y * 10 + x] = value
- }
- }
- fun main(args: Array<String>) {
- val board = Board()
- board[0, 0].value = 42
- }
- val t: Tile = Tile(0)
- val tiles = Array(10) { Array<Tile>(10) { t } } // for initialization
- tiles[0][0] = Tile(5)
- tiles[0][1] = Tile(7)
- ....................
Add Comment
Please, Sign In to add comment