-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblackjack.ts
132 lines (111 loc) · 3.74 KB
/
blackjack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var readline_sync = require("readline-sync");
//var userName = readline_sync.question("What is your REAL name? ");
//console.log("Hello " + userName + "!");
import deck = require("./blackjackhelpers");
var game = function(): void {
console.log("GAME BEGIN");
//Create & Shuffle Deck
var currentDeck = deck.shuffle(deck.getDeck());
// 1. Show them their 2 cards and dealer 1 card
var playerCards = [deck.drawCard(currentDeck), deck.drawCard(currentDeck)];
var dealerCards = [deck.drawCard(currentDeck), deck.drawCard(currentDeck)];
console.log(
"You drew a " +
playerCards[0].name +
" of " +
playerCards[0].suit +
" and a " +
playerCards[1].name +
" of " +
playerCards[1].suit +
". Your total is " +
deck.getSum(playerCards) +
"."
);
console.log(
"Dealer shows a " + dealerCards[0].name + " of " + dealerCards[0].suit + "."
);
// 2. Ask if they want to hit / stay OR SPLIT
if (playerCards[0].name === playerCards[1].name) {
var splitQuestion = readline_sync.question("Would you like to split?");
if (splitQuestion === "yes") {
console.log(
"Too Damn Bad. This Program does not have that capability."
);
} else if (splitQuestion === "no") {
console.log("Good, I was not going to let you anyways.");
} else {
console.log("YOU ARE A FUCKING MORON.");
}
}
while (deck.getSum(playerCards) < 21) {
var introQuestion = readline_sync.question(
"Would you like to stay or hit?"
);
// 3a. if hit, show them another card
// 3b. if stay, dealer shows 2nd card
if (introQuestion === "hit") {
playerCards.push(deck.drawCard(currentDeck));
var playerSum = deck.getSum(playerCards);
console.log(
"You drew a " +
playerCards[playerCards.length - 1].name +
" of " +
playerCards[playerCards.length - 1].suit +
". Your total is " +
playerSum +
"."
);
} else if (introQuestion === "stay") {
break;
} else {
console.log("YOU ARE A FUKIN MORON.");
}
}
//Dealer's Turn
var dealerSum = deck.getSum(dealerCards);
var playerSum = deck.getSum(playerCards);
console.log(
"The Dealer flipped over a " +
dealerCards[1].name +
" of " +
dealerCards[1].suit +
"."
);
while (deck.getSum(dealerCards) < 17 && playerSum < 21) {
var currentCard = deck.drawCard(currentDeck);
dealerCards.push(currentCard);
console.log(
"The Dealer drew a " + currentCard.name + " of " + currentCard.suit + "."
);
dealerSum = deck.getSum(dealerCards);
}
if (playerSum > 21) {
console.log("You Lose :(");
} else if (dealerSum > playerSum && dealerSum < 21) {
console.log("The dealer's total is " + dealerSum + ". You Lose Big Boy!");
} else if (playerSum === 21 && dealerSum !== 21) {
console.log("The dealer's total is " + dealerSum + ". You Win Big Banana!");
} else if (playerSum === dealerSum) {
console.log("The dealer's total is " + dealerSum + ". PUSH");
} else if (dealerSum > playerSum && dealerSum <= 21) {
console.log("The dealer's total is " + dealerSum + ". You Lose Bitch.");
} else if (dealerSum > playerSum && dealerSum > 21) {
console.log("The dealer's total is " + dealerSum + ". You win.");
} else {
console.log("The dealer's total is " + dealerSum + ". YOU WIN!");
}
// 4a. Check if player busted
// 4b. Check if dealer busted
// 4c. Check if player got blackjack
// 4d. Check if dealer got blackjack
// 4e. Check if tied
// 4f. Check if player sum > dealer sum
// 5. Print win/lose
//console.log(playerSum);
//console.log(dealerSum);
//deal with Aces
//fix face card values
};
game();
//console.log(deck.getDeck());