Skip to content

Instantly share code, notes, and snippets.

@wmantly
Created February 3, 2014 01:27
Embed
What would you like to do?
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