Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Tile = function (set, val) {
- this.set = set;
- this.val = val;
- };
- var Tileset = function() {
- this.tiles = [];
- };
- var Hand = function () {
- this.tiles = [];
- };
- var Wall = function () {
- this.tiles = [];
- this.populate();
- this.shuffle();
- };
- var Player = function() {};
- var Game = function() {
- this.wall = new Wall;
- this.hand = new Hand;
- for (var i = 0; i < 13; i++) {
- this.hand.push(this.wall.pop());
- };
- };
- Tileset.prototype = {
- shuffle: function() {
- for (var i = this.tiles.length - 1; i > 0; i--) {
- var j = Math.floor(Math.random() * (i + 1));
- var temp = this.tiles[i];
- this.tiles[i] = this.tiles[j];
- this.tiles[j] = temp;
- }1
- return this.tiles;
- },
- push: function(tile) { return this.tiles.push(tile) },
- pop: function() { return this.tiles.pop() }
- };
- Wall.prototype = new Tileset;
- Hand.prototype = new Tileset;
- Wall.prototype.populate = function() {
- var sets = 'man pin sou honor'.split(' '),
- honors = 'haku hatsu chun e s w n'.split(' ');
- for (var i = 0; i < sets.length; i++) {
- if (sets[i] == 'honor') {
- for (var j = 0; j < honors.length; j++) {
- for (var k = 0; k < 4; k++) this.tiles.push(new Tile(sets[i], honors[j]));
- }
- } else {
- for (var j = 1; j < 10; j++) {
- for (var k = 0; k < 4; k++) this.tiles.push(new Tile(sets[i], j));
- }
- }
- }
- };
- game = new Game
- console.log(game.hand.tiles);
Advertisement
Add Comment
Please, Sign In to add comment