Guest User

Untitled

a guest
Dec 1st, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Tile
  2.   constructor: (@set, @val) -> 
  3.  
  4. class Tileset
  5.   constructor: (@tiles = []) ->
  6.   shuffle: ->
  7.     for i in [this.tiles.length - 1 ... 0]
  8.       j = Math.floor(Math.random() * (i + 1))
  9.       temp = this.tiles[i]
  10.       this.tiles[i] = this.tiles[j]
  11.       this.tiles[j] = temp
  12.     this.tiles;
  13.   push: (tile) -> this.tiles.push(tile)
  14.   pop: () -> this.tiles.pop()
  15.  
  16. class Hand extends Tileset
  17.   constructor: (@tiles = []) ->
  18.  
  19. class Wall extends Tileset
  20.   constructor: (@tiles = []) ->
  21.     @populate()
  22.     @shuffle()
  23.   populate: ->
  24.     sets = 'man pin sou honor'.split(' ')
  25.     honors = 'haku hatsu chun e s w n'.split(' ')
  26.     for i in [0...sets.length]
  27.        if sets[i] == 'honor'
  28.          for j in [0...honors.length]
  29.            for k in [0...4]
  30.              @tiles.push new Tile(sets[i], honors[j])
  31.        else
  32.          for j in [1...10]
  33.            for k in [0...4]
  34.              @tiles.push new Tile(sets[i], j)
  35.  
  36. class Player
  37.   constructor: ->
  38.  
  39. class Game
  40.   constructor: ->
  41.     @wall = new Wall
  42.     @hand = new Hand
  43.     for i in [0...13]
  44.       @hand.push(this.wall.pop())    
  45.  
  46.      
  47. game = new Game
  48. console.log(game.hand.tiles);
Advertisement
Add Comment
Please, Sign In to add comment