Created
February 3, 2014 01:27
-
-
Save wmantly/8777665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var texasHoldem = (function(){ | |
var game = { | |
pot_size: 0, | |
players: 0, | |
player: [], | |
bet: {}, | |
deck: [] | |
}; | |
function makeDeck() { | |
var deck = [], | |
shuffled = [], | |
suits = ["spades", "hearts", "diamonds", "clubs"]; | |
suits.forEach(function(suit) { | |
for (var number = 2; number < 15; number++) { | |
deck.push(new Card(suit, number)); | |
} | |
}); | |
return deck; | |
} | |
function deal() { | |
// starting deal | |
game.player.forEach(function(player) { | |
player.cards.push(game.deck.pop()); | |
bet(player, 1); | |
}); | |
return game; | |
} | |
function bet(player, bet) { | |
player.chips -= bet; | |
game.pot_size += bet; | |
return game; | |
} | |
function makeGame(players_array) { | |
game.player = players_array; | |
game.players = players_array.length; | |
game.deck = makeDeck(); | |
return this; | |
} | |
return { | |
makeGame: makeGame, | |
deal: deal | |
}; | |
})(); | |
function Player(name, chips, cards) { | |
this.name = name; | |
this.chips = chips; | |
this.cards = cards || []; | |
} | |
function Card(suit, number) { | |
this.suit = suit; | |
this.number = number; | |
} | |
var players_array = []; | |
players_array.push(new Player('billy', 1000)); | |
players_array.push(new Player('ro', 1000)); | |
exports.index = function(req, res){ | |
if(req.xhr){ | |
res.json(texasHoldem.deal(players_array)); | |
}else{ | |
res.render('index', {title: "game"}) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment