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

VVG #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

VVG #36

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
18 changes: 18 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
]
}
81 changes: 81 additions & 0 deletions app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// python -m SimpleHTTPServer 8000

import { House } from "./house";
import { UI } from "./ui";

class App {
private _theHouse: House;
private _ui: UI;

constructor(theHouse: House) {
this._theHouse = theHouse;
this._ui = new UI();
}

get theHouse() {
return this._theHouse;
}

get theUI() {
return this._ui;
}

}

// let theHouse = new House();
// let myCasino = new App(theHouse);

// myCasino.theUI.display("Welcome to the Casino!");


let first = "Larry";
let last = "Legend";
let full = first + " " + last;
document.getElementById("display")!.innerHTML = full;


// document.getElementById("display")!.innerHTML = "Hello";
// document.getElementById("display")!.innerHTML = testPrint;




// function startCasino() {



// // document.getElementById("display")!.innerHTML = "Hello";


// // let displayElement: HTMLElement | null = document.getElementById('display');
// // displayElement!.innerText = 'Welcome to the Casino';
// }


// document.getElementById('startCasino')!.addEventListener('click', startCasino);

// constructor(){
// this.chooseGame = this.chooseGame.bind(this);
// }

// start() {
// UI.display("What game do you want to play?");
// UI.display("Black Jack or Go Fish?");
// UI.button.addEventListener("click", this.chooseGame);
// }

// chooseGame(): void {
// UI.button.removeEventListener("click", this.chooseGame);
// if (UI.lastInput === "Black Jack") {

// BlackJack.start();

// }
// else if (UI.lastInput === "Go Fish") {
// GoFish.start();

// }
// else {
// UI.button.addEventListener("click", this.chooseGame);
// }
// }
39 changes: 39 additions & 0 deletions app/cardgames/blackjack/blackjackengine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { GameEngine } from "../../gameengine";
import { BlackJackGame } from "./blackjackgame";
import { BlackJackPlayer } from "./blackjackplayer";

class BlackJackEngine extends GameEngine {

_game: BlackJackGame;
_player: BlackJackPlayer;
_keepPlaying: boolean;

constructor(game: BlackJackGame, player: BlackJackPlayer) {
super(game, player);
this._game = game;
this._player = player;
this._keepPlaying = true;
}

run() {
// display a welcome message

while(this.keepPlaying === true) {
this._game.playOneRound();

//ask if player wants to play another round
//set keepPlaying status
}
this.endGame();
}

endGame() {
// game over
// back to menu
}

get keepPlaying() {
return this._keepPlaying;
}

}
138 changes: 138 additions & 0 deletions app/cardgames/blackjack/blackjackgame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { CardGame } from "../cardgame";
import { BlackJackPlayer } from "./blackjackplayer";
import { Profile } from "../../profile";
import { Deck } from "../../cardgames/utilities/deck";
import { House } from "../../house";
import { CasinoGame } from "../../casinogame";

export class BlackJackGame extends CardGame implements CasinoGame<BlackJackPlayer> {

_players: BlackJackPlayer[];
_player: BlackJackPlayer;
_dealer: BlackJackPlayer;

constructor(aProfile: Profile) {
super(aProfile);
this._player = new BlackJackPlayer(aProfile);
this._dealer = new BlackJackPlayer(House._houseProfile);
this._players = new Array();
this._players.push(this._player);
this._players.push(this._dealer);
}

playOneRound() {
this.placeBets();
this.deal();
this.playerTurn(this._player);
if (this._player.isBusted === false) {
this.dealerTurn(this._dealer);
}
if (this._player.isBusted === false && this._dealer.isBusted === false) {
this.decideWinner();
}
}

deal() {
for (var i = 0; i < this._players.length; i++) {
let card1 = this.cardDeck.deal();
this._players[i]._hand.push(card1);
let card2 = this.cardDeck.deal();
this._players[i]._hand.push(card2);
}
// need to display players 2 cards and 1/2 of dealers
}

playerTurn(currentPlayer: BlackJackPlayer) {
// dispaly the players score
currentPlayer.scoreHand();

while (currentPlayer.hasStood === false && currentPlayer.isBusted === false) {
// ask player hit or stand
// if hit, calculate score
currentPlayer.scoreHand();
// if stand, mark as stood
currentPlayer.hasStood = true;
}

if (this._player.isBusted === true) {
// display that the player busted and lost their bet
this._player.lose();
}
}

dealerTurn(theDealer: BlackJackPlayer) {
this.revealDealerCard();

// display the dealer's score
theDealer.scoreHand();

while (theDealer.hasStood === false && theDealer.isBusted === false) {
if (theDealer.scoreHand() < 17) {
this.hit(theDealer);
} else if (theDealer.scoreHand() > 21) {
// display that the dealer busted
this._dealer.isBusted = true;
// display that the player wins
this._player.win();
} else {
theDealer.hasStood = true;
}
}
}

hit(aBlackJackPlayer: BlackJackPlayer) {
let hitCard = this.cardDeck.deal();
aBlackJackPlayer._hand.push(hitCard);
// need to display card
}

placeBets() {
// ask the player how much to bet
let playersBet = 0;
this._player.bet(playersBet);
}

calculateScore(aBlackJackPlayer: BlackJackPlayer) {
aBlackJackPlayer.hand
}

revealDealerCard() {
// display 2nd card from dealer's hand
this._dealer._hand[1];
}

decideWinner() {

if (this._player.scoreHand() === this._dealer.scoreHand()) {
// display that it is a push
this._player.push();
} else if (this._player.scoreHand() > this._dealer.scoreHand()) {
// display that the player wins
this._player.win();
} else {
// display that the dealer wins
this._player.lose();
}
}

get player() {
return this._player;
}

set player(newPlayer: BlackJackPlayer) {
this._player = newPlayer;
}

get dealer() {
return this._dealer;
}

get cardDeck() {
return this.cardDeck;
}

set cardDeck(newDeck: Deck) {
this.cardDeck = newDeck;
}

}
Loading