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

finishing up #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
107 changes: 107 additions & 0 deletions Casino/Blackjack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"use strict";
exports.__esModule = true;
var CardFactory_1 = require("./CardFactory");
var Dealer_1 = require("./Dealer");
var Blackjack = /** @class */ (function () {
function Blackjack(entryPlayer) {
this.betAmount = 0;
this.deck = CardFactory_1.CardFactory.createStandardDeck();
this.dealer = new Dealer_1["default"]();
this.player = entryPlayer;
}
Blackjack.prototype.startGame = function () {
};
Blackjack.prototype.outOfMoneyCheck = function () {
if (this.player.getBalance() < 10) {
return true;
}
return false;
};
Blackjack.prototype.preGameReset = function () {
this.player.setHand([]);
this.dealer.setHand([]);
this.player.setCanHit(true);
this.setBetAmount(0);
};
Blackjack.prototype.getBetAmount = function () {
return this.betAmount;
};
Blackjack.prototype.setBetAmount = function (amount) {
this.betAmount = amount;
};
Blackjack.prototype.runTurn = function () {
for (var i = 0; i < this.player.getHand.length; i++) {
//Tell them what they have
}
this.setBetAmount(10);
};
Blackjack.prototype.deal = function () {
var temp = this.deck.privateCards[0];
this.player.addToHand(temp);
this.deck.privateCards.shift();
};
Blackjack.prototype.dealToDealer = function () {
var temp = this.deck.privateCards[0];
this.dealer.addToHand(temp);
this.deck.privateCards.shift();
};
Blackjack.prototype.initialHand = function () {
this.deal;
this.deal;
this.dealToDealer;
this.dealToDealer;
};
Blackjack.prototype.bustCheck = function (player) {
var handValue = player.getHandValue();
if (handValue > 21) {
return true;
}
return false;
};
Blackjack.prototype.dealerHitCheck = function () {
if (this.dealer.getHandValue() > 16) {
return false;
}
return true;
};
Blackjack.prototype.dealerTurn = function () {
while (this.dealerHitCheck()) {
this.dealToDealer();
}
//tell them what the dealer has
};
Blackjack.prototype.winCheck = function () {
var playerHand = this.player.getHandValue();
if (playerHand == 21 || playerHand > this.dealer.getHandValue()) {
return true;
}
return false;
};
Blackjack.prototype.playerHitOption = function () {
var hitOrNot = this.runPlayerHit();
if (hitOrNot != null) {
return hitOrNot;
}
return hitOrNot;
};
Blackjack.prototype.runPlayerHit = function () {
while (this.player.canIHit()) {
if (this.player.getHandValue() > 21) {
//tell them they bust
break;
}
var hit;
if (hit) {
return true;
}
this.player.setCanHit(false);
return false;
}
};
Blackjack.prototype.setPlaying = function (isPlaying) {
this.isPlaying = isPlaying;
};
Blackjack.prototype.endGame = function () {
};
return Blackjack;
}());
138 changes: 138 additions & 0 deletions Casino/Blackjack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {Cards} from "./Card";
import {CardFactory} from "./CardFactory";
import {CardShuffler} from "./CardShuffler";
import Deck from "./Deck";
import BlackjackPlayer from "./BlackjackPlayer";
import Game from "./Game";
import Dealer from "./Dealer";

class Blackjack implements Game {
player: BlackjackPlayer;
deck: Deck;
dealer: Dealer;
isPlaying: Boolean;
betAmount: number = 0;

constructor(entryPlayer: BlackjackPlayer) {
this.deck = CardFactory.createStandardDeck();
this.dealer = new Dealer();
this.player = entryPlayer;
}

startGame() {
}

outOfMoneyCheck(): Boolean {
if(this.player.getBalance() < 10) {
return true;
}
return false;
}

preGameReset() {
this.player.setHand([]);
this.dealer.setHand([]);
this.player.setCanHit(true);
this.setBetAmount(0);

}

getBetAmount(): number {
return this.betAmount;
}

setBetAmount(amount: number) {
this.betAmount = amount;
}

runTurn() {
for(var i = 0; i < this.player.getHand.length; i++) {
//Tell them what they have
}
this.setBetAmount(10);
}

deal() {
var temp: Cards = this.deck.privateCards[0];
this.player.addToHand(temp);
this.deck.privateCards.shift();
}

dealToDealer() {
var temp: Cards = this.deck.privateCards[0];
this.dealer.addToHand(temp);
this.deck.privateCards.shift();
}

initialHand() {
this.deal;
this.deal;
this.dealToDealer;
this.dealToDealer;
}

bustCheck(player: BlackjackPlayer): Boolean {
var handValue: number = player.getHandValue();
if(handValue > 21) {
return true;
}
return false;
}

dealerHitCheck(): Boolean {
if(this.dealer.getHandValue() > 16) {
return false;
}
return true;
}

dealerTurn() {
while(this.dealerHitCheck()) {
this.dealToDealer();
}
//tell them what the dealer has
}

winCheck(): Boolean {
var playerHand: number = this.player.getHandValue();
if(playerHand == 21 || playerHand > this.dealer.getHandValue()) {
return true;
}
return false;
}

playerHitOption(): Boolean {
var hitOrNot: Boolean = this.runPlayerHit();
if(hitOrNot != null) {
return hitOrNot;
}
return hitOrNot;
}

runPlayerHit(): Boolean {
while(this.player.canIHit()) {
if(this.player.getHandValue() > 21) {
//tell them they bust
break;
}
var hit: Boolean;

if(hit) {
return true
}
this.player.setCanHit(false);
return false
}
}

setPlaying(isPlaying: Boolean) {
this.isPlaying = isPlaying;
}




endGame() {

}
}
63 changes: 63 additions & 0 deletions Casino/BlackjackPlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";
exports.__esModule = true;
var Wallet_1 = require("./Wallet");
var BlackjackPlayer = /** @class */ (function () {
function BlackjackPlayer(firstName, lastName, balance) {
this.firstName = firstName;
this.lastName = lastName;
this.wallet = new Wallet_1["default"](balance);
}
BlackjackPlayer.prototype.getName = function () {
return this.firstName + " " + this.lastName;
};
BlackjackPlayer.prototype.setName = function (firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
BlackjackPlayer.prototype.getBalance = function () {
return this.wallet.getBalance();
};
BlackjackPlayer.prototype.setHand = function (hand) {
this.hand = hand;
};
BlackjackPlayer.prototype.addToHand = function (card) {
this.hand.push(card);
};
BlackjackPlayer.prototype.getHand = function () {
return this.hand;
};
BlackjackPlayer.prototype.canIHit = function () {
return this.canHit;
};
BlackjackPlayer.prototype.setCanHit = function (bool) {
this.canHit = bool;
};
BlackjackPlayer.prototype.getHandValue = function () {
var handValue = 0;
var aceCounter = 0;
for (var i = 0; i < this.hand.length; i++) {
if (this.hand[i].getRank() == 1) {
aceCounter += 1;
handValue += 11;
}
else if (this.hand[i].getRank() > 9) {
handValue += 10;
}
else {
handValue += this.hand[i].getRank();
}
if (aceCounter > 0 && handValue > 21) {
handValue -= 10;
}
}
return handValue;
};
BlackjackPlayer.prototype.payoutWin = function (amount) {
this.wallet.add(amount);
};
BlackjackPlayer.prototype.payoutLoss = function (amount) {
this.wallet.subtract(amount);
};
return BlackjackPlayer;
}());
exports["default"] = BlackjackPlayer;
84 changes: 84 additions & 0 deletions Casino/BlackjackPlayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {Cards} from "./Card";
import {CardFactory} from "./CardFactory";
import {CardShuffler} from "./CardShuffler";
import Deck from "./Deck";
import Wallet from "./Wallet";

class BlackjackPlayer{
private hand: Array<Cards>;
private canHit: Boolean;
protected firstName: string;
protected lastName: string;
protected wallet: Wallet;

constructor(firstName: string, lastName: string, balance: number) {
this.firstName = firstName;
this.lastName = lastName;
this.wallet = new Wallet(balance);
}

getName(): string {
return this.firstName + " " + this.lastName;
}

setName(firstName: string, lastName: string) {
this.firstName = firstName;
this.lastName = lastName;
}

getBalance(): number {
return this.wallet.getBalance();
}

setHand(hand: Array<Cards>) {
this.hand = hand;
}

addToHand(card: Cards) {
this.hand.push(card);
}

getHand(): Array<Cards> {
return this.hand;
}

canIHit(): Boolean {
return this.canHit;
}

setCanHit(bool: Boolean) {
this.canHit = bool;
}

getHandValue(): number {
var handValue: number = 0;
var aceCounter: number = 0;

for(var i = 0; i < this.hand.length; i++) {
if(this.hand[i].getRank() == 1) {
aceCounter += 1;
handValue += 11;
} else if(this.hand[i].getRank() > 9) {
handValue += 10;
} else {
handValue += this.hand[i].getRank();
}

if(aceCounter > 0 && handValue > 21) {
handValue -= 10;
}
}
return handValue;
}

payoutWin(amount: number) {
this.wallet.add(amount);
}

payoutLoss(amount: number) {
this.wallet.subtract(amount);
}

}

export default BlackjackPlayer;
Loading