Last active
January 30, 2016 02:55
-
-
Save alejandrorangel/80f2be09538e6d0f457c to your computer and use it in GitHub Desktop.
Poker Game in Node.js
This file contains 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
include Hand; | |
var createDeck = function(){ | |
var mDeck = []; | |
//cuatro colores | |
for(var m = 1; m <=4; m++){ | |
var mSimbol = createSimbol(m); | |
//son 13 cartas A,2,3,4,5,6,7,8,9,10,J,Q,K | |
for(var n = 1; n <=13; n++){ | |
mDeck.push(new Card(mSimbol, n)); | |
} | |
} | |
return mDeck; | |
} | |
//esto se puede mejorar pero fue lo primero que se me vino a la mente | |
var createSimbol = function(mCounter){ | |
var mSimbol = {}; | |
switch(mCounter){ | |
case 1: | |
mSimbol.kind = "spades"; | |
mSimbol.color = "black"; | |
break; | |
case 2: | |
mSimbol.kind = "clubs"; | |
mSimbol.color = "black"; | |
break; | |
case 3: | |
mSimbol.kind = "hearts"; | |
mSimbol.color = "red"; | |
break; | |
case 4: | |
mSimbol.kind = "diamond"; | |
mSimbol.color = "red"; | |
break; | |
//falta un default; | |
} | |
return mSimbol; | |
} |
This file contains 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
Class Card { | |
constructor(simbol, value) { | |
this.simbol = simbol; | |
this.value = value; | |
} | |
get kind () { | |
//wtf? | |
return simbol.kind; | |
} | |
get color(){ | |
return simbol.color; | |
} | |
get value(){ | |
//aqui se puede parsear para regresar A o J, Q, K | |
return value; | |
} | |
} |
This file contains 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
include Card; | |
//podria ser jugadores tambien no lo se todavia; | |
Class Hand { | |
//se necesitan 2 cartas | |
constructor(cards) { | |
this.cards = cards; | |
} | |
get cards(){ | |
return cards; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment