Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A map

  • Loading branch information...
commit 8158792024fb0265e6124ffd4372b651d021b5be 1 parent 655d46f
John Nilsson authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 Map.coffee
32 Map.coffee
View
@@ -0,0 +1,32 @@
+###
+# A simple map
+###
+
+
+class Tile
+ constructor: (@x,@y) ->
+ toString: -> "<#{@x},#{@y}>"
+
+class Map
+ constructor: (width, height) ->
+ @tiles = new Array height
+ for row in [0...height]
+ @tiles[row] = new Array width
+ for col in [0...width]
+ t = new Tile row, col
+
+ if col > 0
+ t.left = @tiles[row][col-1]
+ t.left.right = t
+
+ if col == width - 1
+ @tiles[row][0].left = t
+
+ if row > 0
+ t.up = @tiles[row-1][col]
+ t.up.down = t
+
+ if row == height - 1
+ @tiles[0][col].up = t
+
+ @tiles[row][col] = t
Please sign in to comment.
Something went wrong with that request. Please try again.