diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..0c0d8663 --- /dev/null +++ b/.vscode/tasks.json @@ -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 + } + }, + ] +} \ No newline at end of file diff --git a/app/app.ts b/app/app.ts new file mode 100644 index 00000000..b6ea2d9e --- /dev/null +++ b/app/app.ts @@ -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); +// } +// } \ No newline at end of file diff --git a/app/cardgames/blackjack/blackjackengine.ts b/app/cardgames/blackjack/blackjackengine.ts new file mode 100644 index 00000000..5e00bd5a --- /dev/null +++ b/app/cardgames/blackjack/blackjackengine.ts @@ -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; + } + +} \ No newline at end of file diff --git a/app/cardgames/blackjack/blackjackgame.ts b/app/cardgames/blackjack/blackjackgame.ts new file mode 100644 index 00000000..d7875616 --- /dev/null +++ b/app/cardgames/blackjack/blackjackgame.ts @@ -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 { + + _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; + } + +} \ No newline at end of file diff --git a/app/cardgames/blackjack/blackjackplayer.ts b/app/cardgames/blackjack/blackjackplayer.ts new file mode 100644 index 00000000..2406fff0 --- /dev/null +++ b/app/cardgames/blackjack/blackjackplayer.ts @@ -0,0 +1,127 @@ +import { CardPlayer } from "../cardplayer"; +import { Gambler } from "../../gamblerinterface"; +import { Escrow } from "../../escrow"; +import { Profile } from "../../profile"; +import { Card } from "../utilities/card"; + +export class BlackJackPlayer extends CardPlayer implements Gambler { + + private _escrow: Escrow; + + constructor(someProfile: Profile) { + super(someProfile); + this._escrow = new Escrow(); + } + + bet(betAmount: number) { + let accountBalance = this.profile.balance; + + if (betAmount > accountBalance) { + // print insufficient funds + return false; + } else { + this.profile.balance = accountBalance - betAmount; + this.escrow.balance = betAmount; + return true; + } + } + + win() { + this.profile.balance = this.profile.balance + (this._escrow.balance * 2); + this.escrow.balance = 0; + } + + lose() { + this.escrow.balance = 0; + } + + push() { + this.profile.balance = this.profile.balance + this._escrow.balance; + this._escrow.balance = 0; + } + + scoreHand(): number { + let handScore: number = 0; + for (var i = 0; i < this.hand.length; i++) { + handScore += this.scoreCard(this.hand[i]); + } + + if (handScore > 21) { + this.isBusted = true; + } + + return handScore; + } + + scoreCard(anyCard: Card): number { + let cardScore = 0; + + switch(anyCard.rank) { + case "A": + cardScore = 11; + break; + case "2": + cardScore = 2; + break; + case "3": + cardScore = 3; + break; + case "4": + cardScore = 4; + break; + case "5": + cardScore = 5; + break; + case "6": + cardScore = 6; + break; + case "7": + cardScore = 7; + break; + case "8": + cardScore = 8; + break; + case "9": + cardScore = 9; + break; + case "10": + cardScore = 10; + break; + case "J": + cardScore = 10; + break; + case "Q": + cardScore = 10; + break; + case "K": + cardScore = 10; + break; + } + return cardScore; + } + + get hasStood() { + return this.hasStood; + } + + set hasStood(stoodStatus: boolean) { + this.hasStood = stoodStatus; + } + + get isBusted() { + return this.isBusted; + } + + set isBusted(bustedStatus: boolean) { + this.isBusted = bustedStatus; + } + + get escrow() { + return this._escrow; + } + + set escrow(newEscrow: Escrow) { + this._escrow = newEscrow; + } + +} \ No newline at end of file diff --git a/app/cardgames/cardgame.ts b/app/cardgames/cardgame.ts new file mode 100644 index 00000000..d80386cd --- /dev/null +++ b/app/cardgames/cardgame.ts @@ -0,0 +1,22 @@ +import {CasinoGame} from "../casinogame"; +import { Player } from "../player"; +import { Deck } from "./utilities/deck"; +import { Profile } from "../profile"; +import { CardPlayer } from "./cardplayer"; + +export class CardGame implements CasinoGame { + + _player: CardPlayer; + + constructor(aProfile: Profile) { + this._player = new CardPlayer(aProfile); + } + + + startGame() { + } + + endGame() { + } + +} \ No newline at end of file diff --git a/app/cardgames/cardplayer.ts b/app/cardgames/cardplayer.ts new file mode 100644 index 00000000..e89aec8d --- /dev/null +++ b/app/cardgames/cardplayer.ts @@ -0,0 +1,20 @@ +import { Player } from "../player"; +import { Card } from "../cardgames/utilities/card"; +import { Profile } from "../profile"; + +export class CardPlayer extends Player { + _hand: Card[]; + + constructor(theProfile: Profile) { + super(theProfile); + this._hand = new Array(); + } + + get hand() { + return this._hand; + } + + set hand(newHand: Card[]) { + this._hand = newHand; + } +} \ No newline at end of file diff --git a/app/cardgames/gofish/gofishengine.ts b/app/cardgames/gofish/gofishengine.ts new file mode 100644 index 00000000..c8a9088c --- /dev/null +++ b/app/cardgames/gofish/gofishengine.ts @@ -0,0 +1,24 @@ +import { GameEngine } from "../../gameengine"; +import { GoFishGame } from "./gofishgame"; +import { GoFishPlayer } from "./gofishplayer"; + +class GoFishEngine extends GameEngine { + + _game: GoFishGame; + _player: GoFishPlayer; + + constructor(game: GoFishGame, player: GoFishPlayer) { + super(game, player); + this._game = game; + this._player = player; + } + + run() { + + } + + endGame() { + + } + +} diff --git a/app/cardgames/gofish/gofishgame.ts b/app/cardgames/gofish/gofishgame.ts new file mode 100644 index 00000000..22757320 --- /dev/null +++ b/app/cardgames/gofish/gofishgame.ts @@ -0,0 +1,5 @@ +import {CardGame} from "../cardgame" + +export class GoFishGame extends CardGame { + +} \ No newline at end of file diff --git a/app/cardgames/gofish/gofishplayer.ts b/app/cardgames/gofish/gofishplayer.ts new file mode 100644 index 00000000..960c8054 --- /dev/null +++ b/app/cardgames/gofish/gofishplayer.ts @@ -0,0 +1,5 @@ +import {CardPlayer} from "../cardplayer" + +export class GoFishPlayer extends CardPlayer { + +} \ No newline at end of file diff --git a/app/cardgames/utilities/card.ts b/app/cardgames/utilities/card.ts new file mode 100644 index 00000000..30e1d58e --- /dev/null +++ b/app/cardgames/utilities/card.ts @@ -0,0 +1,31 @@ +export class Card { + + private _suit: string; + private _rank: string; + + constructor(theSuit: string, theRank: string) { + this._suit = theSuit; + this._rank = theRank; + } + + get suit(): string { + return this._suit; + } + + set suit(newSuit: string) { + this._suit = newSuit; + } + + get rank(): string { + return this._rank; + } + + set rank(newRank: string) { + this._rank = newRank; + } + + toPrint() { + return this._rank + " of " + this._suit; + } + +} \ No newline at end of file diff --git a/app/cardgames/utilities/deck.ts b/app/cardgames/utilities/deck.ts new file mode 100644 index 00000000..bf296014 --- /dev/null +++ b/app/cardgames/utilities/deck.ts @@ -0,0 +1,51 @@ +import {Card} from "./card" + +export class Deck { + + private _cardDeck: Card[] = new Array(); + + constructor() { + this.buildDeck(); + this.shuffle(); + } + + get deck() { + return this._cardDeck; + } + + set deck(newDeck: Card[]) { + this._cardDeck = newDeck; + } + + deal() { + let card = this._cardDeck[this._cardDeck.length-1]; + this._cardDeck.splice(this._cardDeck.length-1, 1); + // console.log(card); + return card; + } + + buildDeck() { + let cards = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + let suits = ["diamonds", "hearts", "spades", "clubs"]; + for (var i =0; i < suits.length; i++) { + for (var j = 0; j < cards.length; j++) { + let card = new Card(suits[i], cards[j]); + this._cardDeck.push(card); + } + } + } + + shuffle() { + for (var i = 0; i < 1000; i++) { + let location1 = Math.floor((Math.random() * this._cardDeck.length)); + let location2 = Math.floor((Math.random() * this._cardDeck.length)); + let temp = this._cardDeck[location1]; + this._cardDeck[location1] = this._cardDeck[location2]; + this._cardDeck[location2] = temp; + } + } + +} + +let myDeck = new Deck(); +console.log(myDeck.deal()); \ No newline at end of file diff --git a/app/casinogame.ts b/app/casinogame.ts new file mode 100644 index 00000000..7ab4632e --- /dev/null +++ b/app/casinogame.ts @@ -0,0 +1,8 @@ +import { Player } from "./player"; + +export interface CasinoGame { + _player: Player; + + startGame: () => void; + endGame: () => void; +} \ No newline at end of file diff --git a/app/escrow.ts b/app/escrow.ts new file mode 100644 index 00000000..216a71e3 --- /dev/null +++ b/app/escrow.ts @@ -0,0 +1,15 @@ +export class Escrow { + private _balance: number; + + constructor() { + this._balance = 0; + } + + get balance() { + return this._balance; + } + + set balance(newBalance: number) { + this._balance = newBalance; + } +} \ No newline at end of file diff --git a/app/gamblerinterface.ts b/app/gamblerinterface.ts new file mode 100644 index 00000000..5265fbf1 --- /dev/null +++ b/app/gamblerinterface.ts @@ -0,0 +1,11 @@ +import {Escrow} from "./escrow" + +export interface Gambler { + hasStood: boolean; + isBusted: boolean; + escrow: Escrow; + + bet: (amout: number) => boolean; + win: () => void; + lose: () => void; +} \ No newline at end of file diff --git a/app/gameengine.ts b/app/gameengine.ts new file mode 100644 index 00000000..c9dc8e09 --- /dev/null +++ b/app/gameengine.ts @@ -0,0 +1,25 @@ +import { CasinoGame } from "./casinogame"; +import { Player } from "./player"; + +export class GameEngine { + + _game: CasinoGame; + _player: Player; + + constructor(aGame: CasinoGame, aPlayer: Player) { + this._game = aGame; + this._player = aPlayer; + } + + // game: () => CasinoGame; + // get game() { + // return this._game; + // } + + // set game(newGame: CasinoGame) { + // this._game = newGame; + // } + + // player: () => Player; + +} \ No newline at end of file diff --git a/app/house.ts b/app/house.ts new file mode 100644 index 00000000..df0ca23b --- /dev/null +++ b/app/house.ts @@ -0,0 +1,57 @@ +import { Profile } from "./profile"; +import { MainMenu } from "./mainmenu"; + +export class House implements MainMenu { + + private _profiles: Profile[] = new Array(); + static _houseProfile: Profile = new Profile("HOUSE", 0, 1); + + constructor() { + this._profiles.push(this.houseProfile); + } + + createProfile(name: string, balance: number) { + let newProfile = new Profile(name, balance, this._profiles.length); + this._profiles.push(newProfile); + } + + // selectProfileFromExisting(name: string) { + // for (var i = 0; i < this._profiles.length; i++) { + // if (this._profiles[i].username == name) { + // return this._profiles[i]; + // } + // } + // } + + removeProfile(id: number) { + let index = 0; + for (var i = 0; i < this._profiles.length; i++) { + if (this._profiles[i].id == id) { + index = i; + } + } + this._profiles.splice(index, 1); + } + + startCasino() { + + + } + + gameSeelction() { + + } + + get profiles() { + return this._profiles; + } + + set profiles(newProfiles: Profile[]) { + this._profiles = newProfiles; + } + + get houseProfile(): Profile { + return this.houseProfile; + } + +} \ No newline at end of file diff --git a/app/mainmenu.ts b/app/mainmenu.ts new file mode 100644 index 00000000..ff7f20aa --- /dev/null +++ b/app/mainmenu.ts @@ -0,0 +1,9 @@ +import { Profile } from "./profile"; + +export interface MainMenu { + createProfile: (username: string, balance: number) => void; + // selectProfileFromExisting: (string) => Profile; + removeProfile: (id: number) => void; + startCasino: () => void; + gameSeelction: () => void; +} \ No newline at end of file diff --git a/app/player.ts b/app/player.ts new file mode 100644 index 00000000..6e72d5f3 --- /dev/null +++ b/app/player.ts @@ -0,0 +1,38 @@ +import {Profile} from "./profile" + +export abstract class Player { + + private _profile: Profile; + private _name: string; + private _id: number; + + constructor(theProfile: Profile) { + this._profile = theProfile; + this._name = this._profile.username; + this._id = this._profile.id; + } + + get profile() { + return this._profile; + } + + set profile(newProfile: Profile) { + this._profile = newProfile; + } + + get name() { + return this._name; + } + + set name(newName: string) { + this._name = newName; + } + + get id() { + return this._id; + } + + set id(newId: number) { + this._id = newId; + } +} \ No newline at end of file diff --git a/app/playerinterface.ts b/app/playerinterface.ts new file mode 100644 index 00000000..35edb0fa --- /dev/null +++ b/app/playerinterface.ts @@ -0,0 +1,11 @@ +import {Profile} from "./profile" + +interface PlayerInterface { + _name: string; + _id: number; + _profile: Profile; + + name: () => string; + id: () => number; + profile: () => Profile; +} \ No newline at end of file diff --git a/app/profile.ts b/app/profile.ts new file mode 100644 index 00000000..1431636b --- /dev/null +++ b/app/profile.ts @@ -0,0 +1,38 @@ +export class Profile { + + private _id: number; + private _username: string; + private _balance: number; + + + constructor(theUsername: string, theBalance: number, theId: number) { + this._username = theUsername; + this._balance = theBalance; + this._id = theId; + } + + get id(): number { + return this._id; + } + + set id(newId: number) { + this._id = newId; + } + + get username(): string { + return this._username; + } + + set username(newUsername: string) { + this._username = newUsername; + } + + get balance(): number { + return this._balance; + } + + set balance(newBalance: number) { + this._balance = newBalance; + } + +} \ No newline at end of file diff --git a/app/ui.ts b/app/ui.ts new file mode 100644 index 00000000..c29b7d24 --- /dev/null +++ b/app/ui.ts @@ -0,0 +1,12 @@ +export class UI { + + constructor() { + + } + + display(someString: string) { + document.getElementById("display")!.innerHTML = someString; + } + + +} \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..53daf566 --- /dev/null +++ b/js/app.js @@ -0,0 +1,51 @@ +"use strict"; +// python -m SimpleHTTPServer 8000 +Object.defineProperty(exports, "__esModule", { value: true }); +const ui_1 = require("./ui"); +class App { + constructor(theHouse) { + this._theHouse = theHouse; + this._ui = new ui_1.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); +// } +// } diff --git a/js/cardgames/blackjack/blackjackengine.js b/js/cardgames/blackjack/blackjackengine.js new file mode 100644 index 00000000..2c18fe72 --- /dev/null +++ b/js/cardgames/blackjack/blackjackengine.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const gameengine_1 = require("../../gameengine"); +class BlackJackEngine extends gameengine_1.GameEngine { + constructor(game, player) { + 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; + } +} diff --git a/js/cardgames/blackjack/blackjackgame.js b/js/cardgames/blackjack/blackjackgame.js new file mode 100644 index 00000000..3a9e3e28 --- /dev/null +++ b/js/cardgames/blackjack/blackjackgame.js @@ -0,0 +1,116 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const cardgame_1 = require("../cardgame"); +const blackjackplayer_1 = require("./blackjackplayer"); +const house_1 = require("../../house"); +class BlackJackGame extends cardgame_1.CardGame { + constructor(aProfile) { + super(aProfile); + this._player = new blackjackplayer_1.BlackJackPlayer(aProfile); + this._dealer = new blackjackplayer_1.BlackJackPlayer(house_1.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) { + // 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) { + 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) { + 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) { + 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) { + this._player = newPlayer; + } + get dealer() { + return this._dealer; + } + get cardDeck() { + return this.cardDeck; + } + set cardDeck(newDeck) { + this.cardDeck = newDeck; + } +} +exports.BlackJackGame = BlackJackGame; diff --git a/js/cardgames/blackjack/blackjackplayer.js b/js/cardgames/blackjack/blackjackplayer.js new file mode 100644 index 00000000..ea1148b1 --- /dev/null +++ b/js/cardgames/blackjack/blackjackplayer.js @@ -0,0 +1,107 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const cardplayer_1 = require("../cardplayer"); +const escrow_1 = require("../../escrow"); +class BlackJackPlayer extends cardplayer_1.CardPlayer { + constructor(someProfile) { + super(someProfile); + this._escrow = new escrow_1.Escrow(); + } + bet(betAmount) { + let accountBalance = this.profile.balance; + if (betAmount > accountBalance) { + // print insufficient funds + return false; + } + else { + this.profile.balance = accountBalance - betAmount; + this.escrow.balance = betAmount; + return true; + } + } + win() { + this.profile.balance = this.profile.balance + (this._escrow.balance * 2); + this.escrow.balance = 0; + } + lose() { + this.escrow.balance = 0; + } + push() { + this.profile.balance = this.profile.balance + this._escrow.balance; + this._escrow.balance = 0; + } + scoreHand() { + let handScore = 0; + for (var i = 0; i < this.hand.length; i++) { + handScore += this.scoreCard(this.hand[i]); + } + if (handScore > 21) { + this.isBusted = true; + } + return handScore; + } + scoreCard(anyCard) { + let cardScore = 0; + switch (anyCard.rank) { + case "A": + cardScore = 11; + break; + case "2": + cardScore = 2; + break; + case "3": + cardScore = 3; + break; + case "4": + cardScore = 4; + break; + case "5": + cardScore = 5; + break; + case "6": + cardScore = 6; + break; + case "7": + cardScore = 7; + break; + case "8": + cardScore = 8; + break; + case "9": + cardScore = 9; + break; + case "10": + cardScore = 10; + break; + case "J": + cardScore = 10; + break; + case "Q": + cardScore = 10; + break; + case "K": + cardScore = 10; + break; + } + return cardScore; + } + get hasStood() { + return this.hasStood; + } + set hasStood(stoodStatus) { + this.hasStood = stoodStatus; + } + get isBusted() { + return this.isBusted; + } + set isBusted(bustedStatus) { + this.isBusted = bustedStatus; + } + get escrow() { + return this._escrow; + } + set escrow(newEscrow) { + this._escrow = newEscrow; + } +} +exports.BlackJackPlayer = BlackJackPlayer; diff --git a/js/cardgames/cardgame.js b/js/cardgames/cardgame.js new file mode 100644 index 00000000..9fa8b7ca --- /dev/null +++ b/js/cardgames/cardgame.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const cardplayer_1 = require("./cardplayer"); +class CardGame { + constructor(aProfile) { + this._player = new cardplayer_1.CardPlayer(aProfile); + } + startGame() { + } + endGame() { + } +} +exports.CardGame = CardGame; diff --git a/js/cardgames/cardplayer.js b/js/cardgames/cardplayer.js new file mode 100644 index 00000000..7a07868f --- /dev/null +++ b/js/cardgames/cardplayer.js @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const player_1 = require("../player"); +class CardPlayer extends player_1.Player { + constructor(theProfile) { + super(theProfile); + this._hand = new Array(); + } + get hand() { + return this._hand; + } + set hand(newHand) { + this._hand = newHand; + } +} +exports.CardPlayer = CardPlayer; diff --git a/js/cardgames/gofish/gofishengine.js b/js/cardgames/gofish/gofishengine.js new file mode 100644 index 00000000..b58f0511 --- /dev/null +++ b/js/cardgames/gofish/gofishengine.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const gameengine_1 = require("../../gameengine"); +class GoFishEngine extends gameengine_1.GameEngine { + constructor(game, player) { + super(game, player); + this._game = game; + this._player = player; + } + run() { + } + endGame() { + } +} diff --git a/js/cardgames/gofish/gofishgame.js b/js/cardgames/gofish/gofishgame.js new file mode 100644 index 00000000..bee8eaad --- /dev/null +++ b/js/cardgames/gofish/gofishgame.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const cardgame_1 = require("../cardgame"); +class GoFishGame extends cardgame_1.CardGame { +} +exports.GoFishGame = GoFishGame; diff --git a/js/cardgames/gofish/gofishplayer.js b/js/cardgames/gofish/gofishplayer.js new file mode 100644 index 00000000..37874e25 --- /dev/null +++ b/js/cardgames/gofish/gofishplayer.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const cardplayer_1 = require("../cardplayer"); +class GoFishPlayer extends cardplayer_1.CardPlayer { +} +exports.GoFishPlayer = GoFishPlayer; diff --git a/js/cardgames/utilities/card.js b/js/cardgames/utilities/card.js new file mode 100644 index 00000000..3b0fb055 --- /dev/null +++ b/js/cardgames/utilities/card.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class Card { + constructor(theSuit, theRank) { + this._suit = theSuit; + this._rank = theRank; + } + get suit() { + return this._suit; + } + set suit(newSuit) { + this._suit = newSuit; + } + get rank() { + return this._rank; + } + set rank(newRank) { + this._rank = newRank; + } + toPrint() { + return this._rank + " of " + this._suit; + } +} +exports.Card = Card; diff --git a/js/cardgames/utilities/deck.js b/js/cardgames/utilities/deck.js new file mode 100644 index 00000000..36370e0f --- /dev/null +++ b/js/cardgames/utilities/deck.js @@ -0,0 +1,44 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const card_1 = require("./card"); +class Deck { + constructor() { + this._cardDeck = new Array(); + this.buildDeck(); + this.shuffle(); + } + get deck() { + return this._cardDeck; + } + set deck(newDeck) { + this._cardDeck = newDeck; + } + deal() { + let card = this._cardDeck[this._cardDeck.length - 1]; + this._cardDeck.splice(this._cardDeck.length - 1, 1); + // console.log(card); + return card; + } + buildDeck() { + let cards = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + let suits = ["diamonds", "hearts", "spades", "clubs"]; + for (var i = 0; i < suits.length; i++) { + for (var j = 0; j < cards.length; j++) { + let card = new card_1.Card(suits[i], cards[j]); + this._cardDeck.push(card); + } + } + } + shuffle() { + for (var i = 0; i < 1000; i++) { + let location1 = Math.floor((Math.random() * this._cardDeck.length)); + let location2 = Math.floor((Math.random() * this._cardDeck.length)); + let temp = this._cardDeck[location1]; + this._cardDeck[location1] = this._cardDeck[location2]; + this._cardDeck[location2] = temp; + } + } +} +exports.Deck = Deck; +let myDeck = new Deck(); +console.log(myDeck.deal()); diff --git a/js/casinogame.js b/js/casinogame.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/js/casinogame.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/js/escrow.js b/js/escrow.js new file mode 100644 index 00000000..6248ba2f --- /dev/null +++ b/js/escrow.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class Escrow { + constructor() { + this._balance = 0; + } + get balance() { + return this._balance; + } + set balance(newBalance) { + this._balance = newBalance; + } +} +exports.Escrow = Escrow; diff --git a/js/gamblerinterface.js b/js/gamblerinterface.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/js/gamblerinterface.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/js/gameengine.js b/js/gameengine.js new file mode 100644 index 00000000..cd88fb5b --- /dev/null +++ b/js/gameengine.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class GameEngine { + constructor(aGame, aPlayer) { + this._game = aGame; + this._player = aPlayer; + } +} +exports.GameEngine = GameEngine; diff --git a/js/house.js b/js/house.js new file mode 100644 index 00000000..7b3e12c3 --- /dev/null +++ b/js/house.js @@ -0,0 +1,44 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const profile_1 = require("./profile"); +class House { + constructor() { + this._profiles = new Array(); + this._profiles.push(this.houseProfile); + } + createProfile(name, balance) { + let newProfile = new profile_1.Profile(name, balance, this._profiles.length); + this._profiles.push(newProfile); + } + // selectProfileFromExisting(name: string) { + // for (var i = 0; i < this._profiles.length; i++) { + // if (this._profiles[i].username == name) { + // return this._profiles[i]; + // } + // } + // } + removeProfile(id) { + let index = 0; + for (var i = 0; i < this._profiles.length; i++) { + if (this._profiles[i].id == id) { + index = i; + } + } + this._profiles.splice(index, 1); + } + startCasino() { + } + gameSeelction() { + } + get profiles() { + return this._profiles; + } + set profiles(newProfiles) { + this._profiles = newProfiles; + } + get houseProfile() { + return this.houseProfile; + } +} +House._houseProfile = new profile_1.Profile("HOUSE", 0, 1); +exports.House = House; diff --git a/js/mainmenu.js b/js/mainmenu.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/js/mainmenu.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/js/player.js b/js/player.js new file mode 100644 index 00000000..e10d36be --- /dev/null +++ b/js/player.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class Player { + constructor(theProfile) { + this._profile = theProfile; + this._name = this._profile.username; + this._id = this._profile.id; + } + get profile() { + return this._profile; + } + set profile(newProfile) { + this._profile = newProfile; + } + get name() { + return this._name; + } + set name(newName) { + this._name = newName; + } + get id() { + return this._id; + } + set id(newId) { + this._id = newId; + } +} +exports.Player = Player; diff --git a/js/playerinterface.js b/js/playerinterface.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/js/playerinterface.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/js/profile.js b/js/profile.js new file mode 100644 index 00000000..5f875aa9 --- /dev/null +++ b/js/profile.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class Profile { + constructor(theUsername, theBalance, theId) { + this._username = theUsername; + this._balance = theBalance; + this._id = theId; + } + get id() { + return this._id; + } + set id(newId) { + this._id = newId; + } + get username() { + return this._username; + } + set username(newUsername) { + this._username = newUsername; + } + get balance() { + return this._balance; + } + set balance(newBalance) { + this._balance = newBalance; + } +} +exports.Profile = Profile; diff --git a/js/ui.js b/js/ui.js new file mode 100644 index 00000000..4a0bcef8 --- /dev/null +++ b/js/ui.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class UI { + constructor() { + } + display(someString) { + document.getElementById("display").innerHTML = someString; + } +} +exports.UI = UI; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..243bdb28 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,81 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./js", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + "watch": true, + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + }, + "files": [ + "app/cardgames/blackjack/blackjackengine.ts", + "app/cardgames/blackjack/blackjackgame.ts", + "app/cardgames/blackjack/blackjackplayer.ts", + "app/cardgames/gofish/gofishengine.ts", + "app/cardgames/gofish/gofishgame.ts", + "app/cardgames/gofish/gofishplayer.ts", + "app/cardgames/utilities/card.ts", + "app/cardgames/utilities/deck.ts", + "app/cardgames/cardgame.ts", + "app/cardgames/cardplayer.ts", + "app/app.ts", + "app/casinogame.ts", + "app/escrow.ts", + "app/gamblerinterface.ts", + "app/gameengine.ts", + "app/house.ts", + "app/mainmenu.ts", + "app/player.ts", + "app/playerinterface.ts", + "app/profile.ts", + "app/ui.ts" + ] + +} \ No newline at end of file