Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work in Progress #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Basic BlackJack Working
Garrett Arant authored and Garrett Arant committed Mar 26, 2018
commit fbdb51516c8934b08f5a85bd7f058cd0fa08299a
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -23,9 +23,13 @@ <h1>TypeScript Casino</h1>
</div>

<div id="buttons">
<button type="button" class="btn btn-primary" onclick="blackJack.hit()">HIT</button>
<!-- <button type="button" class="btn btn-primary" onclick="blackJack.hit()">HIT</button>
<button type="button" class="btn btn-primary" onclick="blackJack.stay()">STAY</button>
<button type="button" class="btn btn-primary" onclick="blackJack.play(), style.display = 'none'">START GAME</button>
<button type="button" class="btn btn-primary" onclick="blackJack.play(), style.display = 'none'">START GAME</button> -->
<button id="button1" style="display:block;" type="button" class="btn btn-primary" onclick="document.getElementById('button2').style.display = 'block'; document.getElementById('button3').style.display = 'block'; document.getElementById('button4').style.display = 'block';this.style.display = 'none'; blackJack.play();">START GAME</button>
<button id="button2" style="display:none;" type="button" class="btn btn-primary" onclick="style.display = 'block'; blackJack.hit();">HIT</button>
<button id="button3" style="display:none;" type="button" class="btn btn-primary" onclick="style.display = 'block'; blackJack.stay();">STAY</button>
<button id="button4" style="display:none;" type="button" class="btn btn-primary" onclick="style.display = 'block'; location.reload();">NEW GAME</button>
</div>
<div id="input">
<input type="text" name="user_input" id="user_input">
60 changes: 43 additions & 17 deletions js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/app.js.map
79 changes: 52 additions & 27 deletions ts/BlackJack.ts
Original file line number Diff line number Diff line change
@@ -40,14 +40,20 @@ class BlackJack {
public checkBlackJack(){
if(this.checkPlayerBlackJack()){
if(this.checkDealerBlackJack()){
this.println("It's a tie!");
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "It's a Push");
return true;
} else{
this.println("You win!");
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Win!");
return true;
}
} else if(this.checkDealerBlackJack()){
this.println("You lose!");
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Lose!");
return true;
} else return false;
}
@@ -58,32 +64,50 @@ class BlackJack {
}

public stay(){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>');

if(this.dealerHand.handValue() < 17){
this.dealerHand.addCard(this.gameDeck.draw());
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>');
} else if(this.dealerHand.handValue() > 17){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+'<br>');
}
//this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
//+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>');
//if(this.dealerHand.handValue() < 17){
if(this.dealerHand.handValue() < 17){
do{
this.dealerHand.addCard(this.gameDeck.draw())
} while(this.dealerHand.handValue() < 17){
if(this.dealerHand.handValue() > 22){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Win!");
}
if(this.dealerHand.handValue() < 22 && this.dealerHand.handValue() > this.playerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Lose!");
} else if(this.playerHand.handValue() < 22 && this.playerHand.handValue() > this.dealerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Win!");
} else if(this.playerHand.handValue() == this.dealerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "It's a Push");
}
}
}


if(this.dealerHand.handValue() < 22 && this.dealerHand.handValue() > this.playerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Lose");
} else if(this.playerHand.handValue() < 22 && this.playerHand.handValue() > this.dealerHand.handValue()){
if(this.dealerHand.handValue() < 22 && this.dealerHand.handValue() > this.playerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Win");
} else if(this.playerHand.handValue() == this.dealerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "It's a tie");
}
+ "You Lose!");
} else if(this.playerHand.handValue() < 22 && this.playerHand.handValue() > this.dealerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "You Win!");
} else if(this.playerHand.handValue() == this.dealerHand.handValue()){
this.println('<br>' +"Dealer's cards:" + this.dealerHand.handToString() + this.dealerHand.handValue() + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+ '<br>'
+ "It's a Push");
}
}


public checkPlayerBlackJack(){
return this.playerHand.handValue() === 21;
@@ -94,9 +118,10 @@ class BlackJack {
}

public hit(){
this.playerHand.addCard(this.gameDeck.draw());
let gameOver = this.checkBlackJack() || this.playerHand.handValue() > 21;
//this.playerHand.addCard(this.gameDeck.draw());
let gameOver = this.checkBlackJack() || this.playerHand.handValue() > 22;
if(!gameOver){
this.playerHand.addCard(this.gameDeck.draw());
this.println('<br>' +"Dealer's face up card is a " + this.dealerHand.handOfCards[0].toCardName + '<br>'
+ "Your cards: " + this.playerHand.handToString()+" Your hand value = "+ this.playerHand.handValue()+'<br>');
}