From 2850fa44c7c3ec12fb8160734a7132b0c495c66c Mon Sep 17 00:00:00 2001 From: Vincent Gasbarro Date: Mon, 26 Mar 2018 08:58:24 -0400 Subject: [PATCH 1/2] first commit --- .vscode/tasks.json | 18 +++ app/app.ts | 91 +++++++++++++ app/cardgames/blackjack/blackjackengine.ts | 39 ++++++ app/cardgames/blackjack/blackjackgame.ts | 138 ++++++++++++++++++++ app/cardgames/blackjack/blackjackplayer.ts | 127 +++++++++++++++++++ app/cardgames/cardgame.ts | 22 ++++ app/cardgames/cardplayer.ts | 20 +++ app/cardgames/gofish/gofishengine.ts | 24 ++++ app/cardgames/gofish/gofishgame.ts | 5 + app/cardgames/gofish/gofishplayer.ts | 5 + app/cardgames/utilities/card.ts | 31 +++++ app/cardgames/utilities/deck.ts | 51 ++++++++ app/casinogame.ts | 8 ++ app/escrow.ts | 15 +++ app/gamblerinterface.ts | 11 ++ app/gameengine.ts | 25 ++++ app/house.ts | 57 +++++++++ app/mainmenu.ts | 9 ++ app/player.ts | 38 ++++++ app/playerinterface.ts | 11 ++ app/profile.ts | 38 ++++++ app/ui.ts | 12 ++ js/app.js | 48 +++++++ js/cardgames/blackjack/blackjackengine.js | 44 +++++++ js/cardgames/blackjack/blackjackgame.js | 141 +++++++++++++++++++++ js/cardgames/blackjack/blackjackplayer.js | 132 +++++++++++++++++++ js/cardgames/cardgame.js | 14 ++ js/cardgames/cardplayer.js | 33 +++++ js/cardgames/gofish/gofishengine.js | 27 ++++ js/cardgames/gofish/gofishgame.js | 21 +++ js/cardgames/gofish/gofishplayer.js | 21 +++ js/cardgames/utilities/card.js | 33 +++++ js/cardgames/utilities/deck.js | 49 +++++++ js/casinogame.js | 2 + js/escrow.js | 19 +++ js/gamblerinterface.js | 2 + js/gameengine.js | 10 ++ js/house.js | 53 ++++++++ js/mainmenu.js | 2 + js/player.js | 41 ++++++ js/playerinterface.js | 2 + js/profile.js | 41 ++++++ js/ui.js | 11 ++ tsconfig.json | 81 ++++++++++++ 44 files changed, 1622 insertions(+) create mode 100644 .vscode/tasks.json create mode 100644 app/app.ts create mode 100644 app/cardgames/blackjack/blackjackengine.ts create mode 100644 app/cardgames/blackjack/blackjackgame.ts create mode 100644 app/cardgames/blackjack/blackjackplayer.ts create mode 100644 app/cardgames/cardgame.ts create mode 100644 app/cardgames/cardplayer.ts create mode 100644 app/cardgames/gofish/gofishengine.ts create mode 100644 app/cardgames/gofish/gofishgame.ts create mode 100644 app/cardgames/gofish/gofishplayer.ts create mode 100644 app/cardgames/utilities/card.ts create mode 100644 app/cardgames/utilities/deck.ts create mode 100644 app/casinogame.ts create mode 100644 app/escrow.ts create mode 100644 app/gamblerinterface.ts create mode 100644 app/gameengine.ts create mode 100644 app/house.ts create mode 100644 app/mainmenu.ts create mode 100644 app/player.ts create mode 100644 app/playerinterface.ts create mode 100644 app/profile.ts create mode 100644 app/ui.ts create mode 100644 js/app.js create mode 100644 js/cardgames/blackjack/blackjackengine.js create mode 100644 js/cardgames/blackjack/blackjackgame.js create mode 100644 js/cardgames/blackjack/blackjackplayer.js create mode 100644 js/cardgames/cardgame.js create mode 100644 js/cardgames/cardplayer.js create mode 100644 js/cardgames/gofish/gofishengine.js create mode 100644 js/cardgames/gofish/gofishgame.js create mode 100644 js/cardgames/gofish/gofishplayer.js create mode 100644 js/cardgames/utilities/card.js create mode 100644 js/cardgames/utilities/deck.js create mode 100644 js/casinogame.js create mode 100644 js/escrow.js create mode 100644 js/gamblerinterface.js create mode 100644 js/gameengine.js create mode 100644 js/house.js create mode 100644 js/mainmenu.js create mode 100644 js/player.js create mode 100644 js/playerinterface.js create mode 100644 js/profile.js create mode 100644 js/ui.js create mode 100644 tsconfig.json 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..76a35f81 --- /dev/null +++ b/app/app.ts @@ -0,0 +1,91 @@ +// python -m SimpleHTTPServer 8000 +// import {Deck} from "./cardgames/utilities/deck" + +// function legend() { +// let first = "Larry"; +// let last = "Legend"; +// let full = first + " " + last; +// document.getElementById("display")!.innerHTML = full; +// } + +// legend(); + +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..5af041df --- /dev/null +++ b/js/app.js @@ -0,0 +1,48 @@ +"use strict"; +// python -m SimpleHTTPServer 8000 +// import {Deck} from "./cardgames/utilities/deck" +Object.defineProperty(exports, "__esModule", { value: true }); +function legend() { + var first = "Larry"; + var last = "Legend"; + var full = first + " " + last; + document.getElementById("display").innerHTML = full; +} +legend(); +var ui_1 = require("./ui"); +var App = /** @class */ (function () { + function App(theHouse) { + this._theHouse = theHouse; + this._ui = new ui_1.UI(); + } + Object.defineProperty(App.prototype, "theHouse", { + get: function () { + return this._theHouse; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(App.prototype, "theUI", { + get: function () { + return this._ui; + }, + enumerable: true, + configurable: true + }); + return App; +}()); +// let theHouse = new House(); +// let myCasino = new App(theHouse); +// myCasino.theUI.display("Welcome to the Casino!"); +var first = "Larry"; +var last = "Legend"; +var 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); diff --git a/js/cardgames/blackjack/blackjackengine.js b/js/cardgames/blackjack/blackjackengine.js new file mode 100644 index 00000000..2a1629c1 --- /dev/null +++ b/js/cardgames/blackjack/blackjackengine.js @@ -0,0 +1,44 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var gameengine_1 = require("../../gameengine"); +var BlackJackEngine = /** @class */ (function (_super) { + __extends(BlackJackEngine, _super); + function BlackJackEngine(game, player) { + var _this = _super.call(this, game, player) || this; + _this._game = game; + _this._player = player; + _this._keepPlaying = true; + return _this; + } + BlackJackEngine.prototype.run = function () { + // display a welcome message + while (this.keepPlaying === true) { + this._game.playOneRound(); + //ask if player wants to play another round + //set keepPlaying status + } + this.endGame(); + }; + BlackJackEngine.prototype.endGame = function () { + // game over + // back to menu + }; + Object.defineProperty(BlackJackEngine.prototype, "keepPlaying", { + get: function () { + return this._keepPlaying; + }, + enumerable: true, + configurable: true + }); + return BlackJackEngine; +}(gameengine_1.GameEngine)); diff --git a/js/cardgames/blackjack/blackjackgame.js b/js/cardgames/blackjack/blackjackgame.js new file mode 100644 index 00000000..29f288ce --- /dev/null +++ b/js/cardgames/blackjack/blackjackgame.js @@ -0,0 +1,141 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var cardgame_1 = require("../cardgame"); +var blackjackplayer_1 = require("./blackjackplayer"); +var house_1 = require("../../house"); +var BlackJackGame = /** @class */ (function (_super) { + __extends(BlackJackGame, _super); + function BlackJackGame(aProfile) { + var _this = _super.call(this, aProfile) || this; + _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); + return _this; + } + BlackJackGame.prototype.playOneRound = function () { + 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(); + } + }; + BlackJackGame.prototype.deal = function () { + for (var i = 0; i < this._players.length; i++) { + var card1 = this.cardDeck.deal(); + this._players[i]._hand.push(card1); + var card2 = this.cardDeck.deal(); + this._players[i]._hand.push(card2); + } + // need to display players 2 cards and 1/2 of dealers + }; + BlackJackGame.prototype.playerTurn = function (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(); + } + }; + BlackJackGame.prototype.dealerTurn = function (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; + } + } + }; + BlackJackGame.prototype.hit = function (aBlackJackPlayer) { + var hitCard = this.cardDeck.deal(); + aBlackJackPlayer._hand.push(hitCard); + // need to display card + }; + BlackJackGame.prototype.placeBets = function () { + // ask the player how much to bet + var playersBet = 0; + this._player.bet(playersBet); + }; + BlackJackGame.prototype.calculateScore = function (aBlackJackPlayer) { + aBlackJackPlayer.hand; + }; + BlackJackGame.prototype.revealDealerCard = function () { + // display 2nd card from dealer's hand + this._dealer._hand[1]; + }; + BlackJackGame.prototype.decideWinner = function () { + 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(); + } + }; + Object.defineProperty(BlackJackGame.prototype, "player", { + get: function () { + return this._player; + }, + set: function (newPlayer) { + this._player = newPlayer; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BlackJackGame.prototype, "dealer", { + get: function () { + return this._dealer; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BlackJackGame.prototype, "cardDeck", { + get: function () { + return this.cardDeck; + }, + set: function (newDeck) { + this.cardDeck = newDeck; + }, + enumerable: true, + configurable: true + }); + return BlackJackGame; +}(cardgame_1.CardGame)); +exports.BlackJackGame = BlackJackGame; diff --git a/js/cardgames/blackjack/blackjackplayer.js b/js/cardgames/blackjack/blackjackplayer.js new file mode 100644 index 00000000..ac431f6c --- /dev/null +++ b/js/cardgames/blackjack/blackjackplayer.js @@ -0,0 +1,132 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var cardplayer_1 = require("../cardplayer"); +var escrow_1 = require("../../escrow"); +var BlackJackPlayer = /** @class */ (function (_super) { + __extends(BlackJackPlayer, _super); + function BlackJackPlayer(someProfile) { + var _this = _super.call(this, someProfile) || this; + _this._escrow = new escrow_1.Escrow(); + return _this; + } + BlackJackPlayer.prototype.bet = function (betAmount) { + var accountBalance = this.profile.balance; + if (betAmount > accountBalance) { + // print insufficient funds + return false; + } + else { + this.profile.balance = accountBalance - betAmount; + this.escrow.balance = betAmount; + return true; + } + }; + BlackJackPlayer.prototype.win = function () { + this.profile.balance = this.profile.balance + (this._escrow.balance * 2); + this.escrow.balance = 0; + }; + BlackJackPlayer.prototype.lose = function () { + this.escrow.balance = 0; + }; + BlackJackPlayer.prototype.push = function () { + this.profile.balance = this.profile.balance + this._escrow.balance; + this._escrow.balance = 0; + }; + BlackJackPlayer.prototype.scoreHand = function () { + var 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; + }; + BlackJackPlayer.prototype.scoreCard = function (anyCard) { + var 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; + }; + Object.defineProperty(BlackJackPlayer.prototype, "hasStood", { + get: function () { + return this.hasStood; + }, + set: function (stoodStatus) { + this.hasStood = stoodStatus; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BlackJackPlayer.prototype, "isBusted", { + get: function () { + return this.isBusted; + }, + set: function (bustedStatus) { + this.isBusted = bustedStatus; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BlackJackPlayer.prototype, "escrow", { + get: function () { + return this._escrow; + }, + set: function (newEscrow) { + this._escrow = newEscrow; + }, + enumerable: true, + configurable: true + }); + return BlackJackPlayer; +}(cardplayer_1.CardPlayer)); +exports.BlackJackPlayer = BlackJackPlayer; diff --git a/js/cardgames/cardgame.js b/js/cardgames/cardgame.js new file mode 100644 index 00000000..edf4e5cc --- /dev/null +++ b/js/cardgames/cardgame.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var cardplayer_1 = require("./cardplayer"); +var CardGame = /** @class */ (function () { + function CardGame(aProfile) { + this._player = new cardplayer_1.CardPlayer(aProfile); + } + CardGame.prototype.startGame = function () { + }; + CardGame.prototype.endGame = function () { + }; + return CardGame; +}()); +exports.CardGame = CardGame; diff --git a/js/cardgames/cardplayer.js b/js/cardgames/cardplayer.js new file mode 100644 index 00000000..cb2bf9c5 --- /dev/null +++ b/js/cardgames/cardplayer.js @@ -0,0 +1,33 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var player_1 = require("../player"); +var CardPlayer = /** @class */ (function (_super) { + __extends(CardPlayer, _super); + function CardPlayer(theProfile) { + var _this = _super.call(this, theProfile) || this; + _this._hand = new Array(); + return _this; + } + Object.defineProperty(CardPlayer.prototype, "hand", { + get: function () { + return this._hand; + }, + set: function (newHand) { + this._hand = newHand; + }, + enumerable: true, + configurable: true + }); + return CardPlayer; +}(player_1.Player)); +exports.CardPlayer = CardPlayer; diff --git a/js/cardgames/gofish/gofishengine.js b/js/cardgames/gofish/gofishengine.js new file mode 100644 index 00000000..39c25648 --- /dev/null +++ b/js/cardgames/gofish/gofishengine.js @@ -0,0 +1,27 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var gameengine_1 = require("../../gameengine"); +var GoFishEngine = /** @class */ (function (_super) { + __extends(GoFishEngine, _super); + function GoFishEngine(game, player) { + var _this = _super.call(this, game, player) || this; + _this._game = game; + _this._player = player; + return _this; + } + GoFishEngine.prototype.run = function () { + }; + GoFishEngine.prototype.endGame = function () { + }; + return GoFishEngine; +}(gameengine_1.GameEngine)); diff --git a/js/cardgames/gofish/gofishgame.js b/js/cardgames/gofish/gofishgame.js new file mode 100644 index 00000000..59bac2db --- /dev/null +++ b/js/cardgames/gofish/gofishgame.js @@ -0,0 +1,21 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var cardgame_1 = require("../cardgame"); +var GoFishGame = /** @class */ (function (_super) { + __extends(GoFishGame, _super); + function GoFishGame() { + return _super !== null && _super.apply(this, arguments) || this; + } + return GoFishGame; +}(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..7e5fff80 --- /dev/null +++ b/js/cardgames/gofish/gofishplayer.js @@ -0,0 +1,21 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var cardplayer_1 = require("../cardplayer"); +var GoFishPlayer = /** @class */ (function (_super) { + __extends(GoFishPlayer, _super); + function GoFishPlayer() { + return _super !== null && _super.apply(this, arguments) || this; + } + return GoFishPlayer; +}(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..707048c2 --- /dev/null +++ b/js/cardgames/utilities/card.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Card = /** @class */ (function () { + function Card(theSuit, theRank) { + this._suit = theSuit; + this._rank = theRank; + } + Object.defineProperty(Card.prototype, "suit", { + get: function () { + return this._suit; + }, + set: function (newSuit) { + this._suit = newSuit; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Card.prototype, "rank", { + get: function () { + return this._rank; + }, + set: function (newRank) { + this._rank = newRank; + }, + enumerable: true, + configurable: true + }); + Card.prototype.toPrint = function () { + return this._rank + " of " + this._suit; + }; + return Card; +}()); +exports.Card = Card; diff --git a/js/cardgames/utilities/deck.js b/js/cardgames/utilities/deck.js new file mode 100644 index 00000000..2a01f4f7 --- /dev/null +++ b/js/cardgames/utilities/deck.js @@ -0,0 +1,49 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var card_1 = require("./card"); +var Deck = /** @class */ (function () { + function Deck() { + this._cardDeck = new Array(); + this.buildDeck(); + this.shuffle(); + } + Object.defineProperty(Deck.prototype, "deck", { + get: function () { + return this._cardDeck; + }, + set: function (newDeck) { + this._cardDeck = newDeck; + }, + enumerable: true, + configurable: true + }); + Deck.prototype.deal = function () { + var card = this._cardDeck[this._cardDeck.length - 1]; + this._cardDeck.splice(this._cardDeck.length - 1, 1); + // console.log(card); + return card; + }; + Deck.prototype.buildDeck = function () { + var cards = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + var suits = ["diamonds", "hearts", "spades", "clubs"]; + for (var i = 0; i < suits.length; i++) { + for (var j = 0; j < cards.length; j++) { + var card = new card_1.Card(suits[i], cards[j]); + this._cardDeck.push(card); + } + } + }; + Deck.prototype.shuffle = function () { + for (var i = 0; i < 1000; i++) { + var location1 = Math.floor((Math.random() * this._cardDeck.length)); + var location2 = Math.floor((Math.random() * this._cardDeck.length)); + var temp = this._cardDeck[location1]; + this._cardDeck[location1] = this._cardDeck[location2]; + this._cardDeck[location2] = temp; + } + }; + return Deck; +}()); +exports.Deck = Deck; +var 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..7ef123d3 --- /dev/null +++ b/js/escrow.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Escrow = /** @class */ (function () { + function Escrow() { + this._balance = 0; + } + Object.defineProperty(Escrow.prototype, "balance", { + get: function () { + return this._balance; + }, + set: function (newBalance) { + this._balance = newBalance; + }, + enumerable: true, + configurable: true + }); + return Escrow; +}()); +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..c7483315 --- /dev/null +++ b/js/gameengine.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var GameEngine = /** @class */ (function () { + function GameEngine(aGame, aPlayer) { + this._game = aGame; + this._player = aPlayer; + } + return GameEngine; +}()); +exports.GameEngine = GameEngine; diff --git a/js/house.js b/js/house.js new file mode 100644 index 00000000..4baea7e4 --- /dev/null +++ b/js/house.js @@ -0,0 +1,53 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var profile_1 = require("./profile"); +var House = /** @class */ (function () { + function House() { + this._profiles = new Array(); + this._profiles.push(this.houseProfile); + } + House.prototype.createProfile = function (name, balance) { + var 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]; + // } + // } + // } + House.prototype.removeProfile = function (id) { + var index = 0; + for (var i = 0; i < this._profiles.length; i++) { + if (this._profiles[i].id == id) { + index = i; + } + } + this._profiles.splice(index, 1); + }; + House.prototype.startCasino = function () { + }; + House.prototype.gameSeelction = function () { + }; + Object.defineProperty(House.prototype, "profiles", { + get: function () { + return this._profiles; + }, + set: function (newProfiles) { + this._profiles = newProfiles; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(House.prototype, "houseProfile", { + get: function () { + return this.houseProfile; + }, + enumerable: true, + configurable: true + }); + House._houseProfile = new profile_1.Profile("HOUSE", 0, 1); + return House; +}()); +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..3290b075 --- /dev/null +++ b/js/player.js @@ -0,0 +1,41 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Player = /** @class */ (function () { + function Player(theProfile) { + this._profile = theProfile; + this._name = this._profile.username; + this._id = this._profile.id; + } + Object.defineProperty(Player.prototype, "profile", { + get: function () { + return this._profile; + }, + set: function (newProfile) { + this._profile = newProfile; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Player.prototype, "name", { + get: function () { + return this._name; + }, + set: function (newName) { + this._name = newName; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Player.prototype, "id", { + get: function () { + return this._id; + }, + set: function (newId) { + this._id = newId; + }, + enumerable: true, + configurable: true + }); + return Player; +}()); +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..fbde5c5c --- /dev/null +++ b/js/profile.js @@ -0,0 +1,41 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Profile = /** @class */ (function () { + function Profile(theUsername, theBalance, theId) { + this._username = theUsername; + this._balance = theBalance; + this._id = theId; + } + Object.defineProperty(Profile.prototype, "id", { + get: function () { + return this._id; + }, + set: function (newId) { + this._id = newId; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Profile.prototype, "username", { + get: function () { + return this._username; + }, + set: function (newUsername) { + this._username = newUsername; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Profile.prototype, "balance", { + get: function () { + return this._balance; + }, + set: function (newBalance) { + this._balance = newBalance; + }, + enumerable: true, + configurable: true + }); + return Profile; +}()); +exports.Profile = Profile; diff --git a/js/ui.js b/js/ui.js new file mode 100644 index 00000000..d33649a6 --- /dev/null +++ b/js/ui.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var UI = /** @class */ (function () { + function UI() { + } + UI.prototype.display = function (someString) { + document.getElementById("display").innerHTML = someString; + }; + return UI; +}()); +exports.UI = UI; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..e425117e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,81 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "es5", /* 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 From e05a0d5a5eaba6e65fdd1cc396bdcd7249a0fd81 Mon Sep 17 00:00:00 2001 From: Vincent Gasbarro Date: Mon, 26 Mar 2018 14:27:00 -0400 Subject: [PATCH 2/2] vg --- app/app.ts | 10 -- js/app.js | 63 +++++------ js/cardgames/blackjack/blackjackengine.js | 47 +++------ js/cardgames/blackjack/blackjackgame.js | 123 +++++++++------------- js/cardgames/blackjack/blackjackplayer.js | 105 +++++++----------- js/cardgames/cardgame.js | 17 ++- js/cardgames/cardplayer.js | 41 +++----- js/cardgames/gofish/gofishengine.js | 35 ++---- js/cardgames/gofish/gofishgame.js | 21 +--- js/cardgames/gofish/gofishplayer.js | 21 +--- js/cardgames/utilities/card.js | 43 +++----- js/cardgames/utilities/deck.js | 53 +++++----- js/escrow.js | 23 ++-- js/gameengine.js | 7 +- js/house.js | 57 +++++----- js/player.js | 55 ++++------ js/profile.js | 55 ++++------ js/ui.js | 11 +- tsconfig.json | 2 +- 19 files changed, 299 insertions(+), 490 deletions(-) diff --git a/app/app.ts b/app/app.ts index 76a35f81..b6ea2d9e 100644 --- a/app/app.ts +++ b/app/app.ts @@ -1,14 +1,4 @@ // python -m SimpleHTTPServer 8000 -// import {Deck} from "./cardgames/utilities/deck" - -// function legend() { -// let first = "Larry"; -// let last = "Legend"; -// let full = first + " " + last; -// document.getElementById("display")!.innerHTML = full; -// } - -// legend(); import { House } from "./house"; import { UI } from "./ui"; diff --git a/js/app.js b/js/app.js index 5af041df..53daf566 100644 --- a/js/app.js +++ b/js/app.js @@ -1,42 +1,25 @@ "use strict"; // python -m SimpleHTTPServer 8000 -// import {Deck} from "./cardgames/utilities/deck" Object.defineProperty(exports, "__esModule", { value: true }); -function legend() { - var first = "Larry"; - var last = "Legend"; - var full = first + " " + last; - document.getElementById("display").innerHTML = full; -} -legend(); -var ui_1 = require("./ui"); -var App = /** @class */ (function () { - function App(theHouse) { +const ui_1 = require("./ui"); +class App { + constructor(theHouse) { this._theHouse = theHouse; this._ui = new ui_1.UI(); } - Object.defineProperty(App.prototype, "theHouse", { - get: function () { - return this._theHouse; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(App.prototype, "theUI", { - get: function () { - return this._ui; - }, - enumerable: true, - configurable: true - }); - return App; -}()); + 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!"); -var first = "Larry"; -var last = "Legend"; -var full = first + " " + last; +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; @@ -46,3 +29,23 @@ document.getElementById("display").innerHTML = full; // // 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 index 2a1629c1..2c18fe72 100644 --- a/js/cardgames/blackjack/blackjackengine.js +++ b/js/cardgames/blackjack/blackjackengine.js @@ -1,26 +1,14 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var gameengine_1 = require("../../gameengine"); -var BlackJackEngine = /** @class */ (function (_super) { - __extends(BlackJackEngine, _super); - function BlackJackEngine(game, player) { - var _this = _super.call(this, game, player) || this; - _this._game = game; - _this._player = player; - _this._keepPlaying = true; - return _this; +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; } - BlackJackEngine.prototype.run = function () { + run() { // display a welcome message while (this.keepPlaying === true) { this._game.playOneRound(); @@ -28,17 +16,12 @@ var BlackJackEngine = /** @class */ (function (_super) { //set keepPlaying status } this.endGame(); - }; - BlackJackEngine.prototype.endGame = function () { + } + endGame() { // game over // back to menu - }; - Object.defineProperty(BlackJackEngine.prototype, "keepPlaying", { - get: function () { - return this._keepPlaying; - }, - enumerable: true, - configurable: true - }); - return BlackJackEngine; -}(gameengine_1.GameEngine)); + } + get keepPlaying() { + return this._keepPlaying; + } +} diff --git a/js/cardgames/blackjack/blackjackgame.js b/js/cardgames/blackjack/blackjackgame.js index 29f288ce..3a9e3e28 100644 --- a/js/cardgames/blackjack/blackjackgame.js +++ b/js/cardgames/blackjack/blackjackgame.js @@ -1,30 +1,18 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var cardgame_1 = require("../cardgame"); -var blackjackplayer_1 = require("./blackjackplayer"); -var house_1 = require("../../house"); -var BlackJackGame = /** @class */ (function (_super) { - __extends(BlackJackGame, _super); - function BlackJackGame(aProfile) { - var _this = _super.call(this, aProfile) || this; - _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); - return _this; +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); } - BlackJackGame.prototype.playOneRound = function () { + playOneRound() { this.placeBets(); this.deal(); this.playerTurn(this._player); @@ -34,17 +22,17 @@ var BlackJackGame = /** @class */ (function (_super) { if (this._player.isBusted === false && this._dealer.isBusted === false) { this.decideWinner(); } - }; - BlackJackGame.prototype.deal = function () { + } + deal() { for (var i = 0; i < this._players.length; i++) { - var card1 = this.cardDeck.deal(); + let card1 = this.cardDeck.deal(); this._players[i]._hand.push(card1); - var card2 = this.cardDeck.deal(); + let card2 = this.cardDeck.deal(); this._players[i]._hand.push(card2); } // need to display players 2 cards and 1/2 of dealers - }; - BlackJackGame.prototype.playerTurn = function (currentPlayer) { + } + playerTurn(currentPlayer) { // dispaly the players score currentPlayer.scoreHand(); while (currentPlayer.hasStood === false && currentPlayer.isBusted === false) { @@ -58,8 +46,8 @@ var BlackJackGame = /** @class */ (function (_super) { // display that the player busted and lost their bet this._player.lose(); } - }; - BlackJackGame.prototype.dealerTurn = function (theDealer) { + } + dealerTurn(theDealer) { this.revealDealerCard(); // display the dealer's score theDealer.scoreHand(); @@ -77,25 +65,25 @@ var BlackJackGame = /** @class */ (function (_super) { theDealer.hasStood = true; } } - }; - BlackJackGame.prototype.hit = function (aBlackJackPlayer) { - var hitCard = this.cardDeck.deal(); + } + hit(aBlackJackPlayer) { + let hitCard = this.cardDeck.deal(); aBlackJackPlayer._hand.push(hitCard); // need to display card - }; - BlackJackGame.prototype.placeBets = function () { + } + placeBets() { // ask the player how much to bet - var playersBet = 0; + let playersBet = 0; this._player.bet(playersBet); - }; - BlackJackGame.prototype.calculateScore = function (aBlackJackPlayer) { + } + calculateScore(aBlackJackPlayer) { aBlackJackPlayer.hand; - }; - BlackJackGame.prototype.revealDealerCard = function () { + } + revealDealerCard() { // display 2nd card from dealer's hand this._dealer._hand[1]; - }; - BlackJackGame.prototype.decideWinner = function () { + } + decideWinner() { if (this._player.scoreHand() === this._dealer.scoreHand()) { // display that it is a push this._player.push(); @@ -108,34 +96,21 @@ var BlackJackGame = /** @class */ (function (_super) { // display that the dealer wins this._player.lose(); } - }; - Object.defineProperty(BlackJackGame.prototype, "player", { - get: function () { - return this._player; - }, - set: function (newPlayer) { - this._player = newPlayer; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(BlackJackGame.prototype, "dealer", { - get: function () { - return this._dealer; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(BlackJackGame.prototype, "cardDeck", { - get: function () { - return this.cardDeck; - }, - set: function (newDeck) { - this.cardDeck = newDeck; - }, - enumerable: true, - configurable: true - }); - return BlackJackGame; -}(cardgame_1.CardGame)); + } + 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 index ac431f6c..ea1148b1 100644 --- a/js/cardgames/blackjack/blackjackplayer.js +++ b/js/cardgames/blackjack/blackjackplayer.js @@ -1,26 +1,14 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var cardplayer_1 = require("../cardplayer"); -var escrow_1 = require("../../escrow"); -var BlackJackPlayer = /** @class */ (function (_super) { - __extends(BlackJackPlayer, _super); - function BlackJackPlayer(someProfile) { - var _this = _super.call(this, someProfile) || this; - _this._escrow = new escrow_1.Escrow(); - return _this; +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(); } - BlackJackPlayer.prototype.bet = function (betAmount) { - var accountBalance = this.profile.balance; + bet(betAmount) { + let accountBalance = this.profile.balance; if (betAmount > accountBalance) { // print insufficient funds return false; @@ -30,20 +18,20 @@ var BlackJackPlayer = /** @class */ (function (_super) { this.escrow.balance = betAmount; return true; } - }; - BlackJackPlayer.prototype.win = function () { + } + win() { this.profile.balance = this.profile.balance + (this._escrow.balance * 2); this.escrow.balance = 0; - }; - BlackJackPlayer.prototype.lose = function () { + } + lose() { this.escrow.balance = 0; - }; - BlackJackPlayer.prototype.push = function () { + } + push() { this.profile.balance = this.profile.balance + this._escrow.balance; this._escrow.balance = 0; - }; - BlackJackPlayer.prototype.scoreHand = function () { - var handScore = 0; + } + scoreHand() { + let handScore = 0; for (var i = 0; i < this.hand.length; i++) { handScore += this.scoreCard(this.hand[i]); } @@ -51,9 +39,9 @@ var BlackJackPlayer = /** @class */ (function (_super) { this.isBusted = true; } return handScore; - }; - BlackJackPlayer.prototype.scoreCard = function (anyCard) { - var cardScore = 0; + } + scoreCard(anyCard) { + let cardScore = 0; switch (anyCard.rank) { case "A": cardScore = 11; @@ -96,37 +84,24 @@ var BlackJackPlayer = /** @class */ (function (_super) { break; } return cardScore; - }; - Object.defineProperty(BlackJackPlayer.prototype, "hasStood", { - get: function () { - return this.hasStood; - }, - set: function (stoodStatus) { - this.hasStood = stoodStatus; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(BlackJackPlayer.prototype, "isBusted", { - get: function () { - return this.isBusted; - }, - set: function (bustedStatus) { - this.isBusted = bustedStatus; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(BlackJackPlayer.prototype, "escrow", { - get: function () { - return this._escrow; - }, - set: function (newEscrow) { - this._escrow = newEscrow; - }, - enumerable: true, - configurable: true - }); - return BlackJackPlayer; -}(cardplayer_1.CardPlayer)); + } + 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 index edf4e5cc..9fa8b7ca 100644 --- a/js/cardgames/cardgame.js +++ b/js/cardgames/cardgame.js @@ -1,14 +1,13 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var cardplayer_1 = require("./cardplayer"); -var CardGame = /** @class */ (function () { - function CardGame(aProfile) { +const cardplayer_1 = require("./cardplayer"); +class CardGame { + constructor(aProfile) { this._player = new cardplayer_1.CardPlayer(aProfile); } - CardGame.prototype.startGame = function () { - }; - CardGame.prototype.endGame = function () { - }; - return CardGame; -}()); + startGame() { + } + endGame() { + } +} exports.CardGame = CardGame; diff --git a/js/cardgames/cardplayer.js b/js/cardgames/cardplayer.js index cb2bf9c5..7a07868f 100644 --- a/js/cardgames/cardplayer.js +++ b/js/cardgames/cardplayer.js @@ -1,33 +1,16 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var player_1 = require("../player"); -var CardPlayer = /** @class */ (function (_super) { - __extends(CardPlayer, _super); - function CardPlayer(theProfile) { - var _this = _super.call(this, theProfile) || this; - _this._hand = new Array(); - return _this; +const player_1 = require("../player"); +class CardPlayer extends player_1.Player { + constructor(theProfile) { + super(theProfile); + this._hand = new Array(); } - Object.defineProperty(CardPlayer.prototype, "hand", { - get: function () { - return this._hand; - }, - set: function (newHand) { - this._hand = newHand; - }, - enumerable: true, - configurable: true - }); - return CardPlayer; -}(player_1.Player)); + 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 index 39c25648..b58f0511 100644 --- a/js/cardgames/gofish/gofishengine.js +++ b/js/cardgames/gofish/gofishengine.js @@ -1,27 +1,14 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var gameengine_1 = require("../../gameengine"); -var GoFishEngine = /** @class */ (function (_super) { - __extends(GoFishEngine, _super); - function GoFishEngine(game, player) { - var _this = _super.call(this, game, player) || this; - _this._game = game; - _this._player = player; - return _this; +const gameengine_1 = require("../../gameengine"); +class GoFishEngine extends gameengine_1.GameEngine { + constructor(game, player) { + super(game, player); + this._game = game; + this._player = player; } - GoFishEngine.prototype.run = function () { - }; - GoFishEngine.prototype.endGame = function () { - }; - return GoFishEngine; -}(gameengine_1.GameEngine)); + run() { + } + endGame() { + } +} diff --git a/js/cardgames/gofish/gofishgame.js b/js/cardgames/gofish/gofishgame.js index 59bac2db..bee8eaad 100644 --- a/js/cardgames/gofish/gofishgame.js +++ b/js/cardgames/gofish/gofishgame.js @@ -1,21 +1,6 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var cardgame_1 = require("../cardgame"); -var GoFishGame = /** @class */ (function (_super) { - __extends(GoFishGame, _super); - function GoFishGame() { - return _super !== null && _super.apply(this, arguments) || this; - } - return GoFishGame; -}(cardgame_1.CardGame)); +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 index 7e5fff80..37874e25 100644 --- a/js/cardgames/gofish/gofishplayer.js +++ b/js/cardgames/gofish/gofishplayer.js @@ -1,21 +1,6 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var cardplayer_1 = require("../cardplayer"); -var GoFishPlayer = /** @class */ (function (_super) { - __extends(GoFishPlayer, _super); - function GoFishPlayer() { - return _super !== null && _super.apply(this, arguments) || this; - } - return GoFishPlayer; -}(cardplayer_1.CardPlayer)); +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 index 707048c2..3b0fb055 100644 --- a/js/cardgames/utilities/card.js +++ b/js/cardgames/utilities/card.js @@ -1,33 +1,24 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var Card = /** @class */ (function () { - function Card(theSuit, theRank) { +class Card { + constructor(theSuit, theRank) { this._suit = theSuit; this._rank = theRank; } - Object.defineProperty(Card.prototype, "suit", { - get: function () { - return this._suit; - }, - set: function (newSuit) { - this._suit = newSuit; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Card.prototype, "rank", { - get: function () { - return this._rank; - }, - set: function (newRank) { - this._rank = newRank; - }, - enumerable: true, - configurable: true - }); - Card.prototype.toPrint = function () { + 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; - }; - return Card; -}()); + } +} exports.Card = Card; diff --git a/js/cardgames/utilities/deck.js b/js/cardgames/utilities/deck.js index 2a01f4f7..36370e0f 100644 --- a/js/cardgames/utilities/deck.js +++ b/js/cardgames/utilities/deck.js @@ -1,49 +1,44 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var card_1 = require("./card"); -var Deck = /** @class */ (function () { - function Deck() { +const card_1 = require("./card"); +class Deck { + constructor() { this._cardDeck = new Array(); this.buildDeck(); this.shuffle(); } - Object.defineProperty(Deck.prototype, "deck", { - get: function () { - return this._cardDeck; - }, - set: function (newDeck) { - this._cardDeck = newDeck; - }, - enumerable: true, - configurable: true - }); - Deck.prototype.deal = function () { - var card = this._cardDeck[this._cardDeck.length - 1]; + 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; - }; - Deck.prototype.buildDeck = function () { - var cards = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; - var suits = ["diamonds", "hearts", "spades", "clubs"]; + } + 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++) { - var card = new card_1.Card(suits[i], cards[j]); + let card = new card_1.Card(suits[i], cards[j]); this._cardDeck.push(card); } } - }; - Deck.prototype.shuffle = function () { + } + shuffle() { for (var i = 0; i < 1000; i++) { - var location1 = Math.floor((Math.random() * this._cardDeck.length)); - var location2 = Math.floor((Math.random() * this._cardDeck.length)); - var temp = this._cardDeck[location1]; + 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; } - }; - return Deck; -}()); + } +} exports.Deck = Deck; -var myDeck = new Deck(); +let myDeck = new Deck(); console.log(myDeck.deal()); diff --git a/js/escrow.js b/js/escrow.js index 7ef123d3..6248ba2f 100644 --- a/js/escrow.js +++ b/js/escrow.js @@ -1,19 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var Escrow = /** @class */ (function () { - function Escrow() { +class Escrow { + constructor() { this._balance = 0; } - Object.defineProperty(Escrow.prototype, "balance", { - get: function () { - return this._balance; - }, - set: function (newBalance) { - this._balance = newBalance; - }, - enumerable: true, - configurable: true - }); - return Escrow; -}()); + get balance() { + return this._balance; + } + set balance(newBalance) { + this._balance = newBalance; + } +} exports.Escrow = Escrow; diff --git a/js/gameengine.js b/js/gameengine.js index c7483315..cd88fb5b 100644 --- a/js/gameengine.js +++ b/js/gameengine.js @@ -1,10 +1,9 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var GameEngine = /** @class */ (function () { - function GameEngine(aGame, aPlayer) { +class GameEngine { + constructor(aGame, aPlayer) { this._game = aGame; this._player = aPlayer; } - return GameEngine; -}()); +} exports.GameEngine = GameEngine; diff --git a/js/house.js b/js/house.js index 4baea7e4..7b3e12c3 100644 --- a/js/house.js +++ b/js/house.js @@ -1,15 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var profile_1 = require("./profile"); -var House = /** @class */ (function () { - function House() { +const profile_1 = require("./profile"); +class House { + constructor() { this._profiles = new Array(); this._profiles.push(this.houseProfile); } - House.prototype.createProfile = function (name, balance) { - var newProfile = new profile_1.Profile(name, balance, this._profiles.length); + 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) { @@ -17,37 +17,28 @@ var House = /** @class */ (function () { // } // } // } - House.prototype.removeProfile = function (id) { - var index = 0; + 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); - }; - House.prototype.startCasino = function () { - }; - House.prototype.gameSeelction = function () { - }; - Object.defineProperty(House.prototype, "profiles", { - get: function () { - return this._profiles; - }, - set: function (newProfiles) { - this._profiles = newProfiles; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(House.prototype, "houseProfile", { - get: function () { - return this.houseProfile; - }, - enumerable: true, - configurable: true - }); - House._houseProfile = new profile_1.Profile("HOUSE", 0, 1); - return House; -}()); + } + 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/player.js b/js/player.js index 3290b075..e10d36be 100644 --- a/js/player.js +++ b/js/player.js @@ -1,41 +1,28 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var Player = /** @class */ (function () { - function Player(theProfile) { +class Player { + constructor(theProfile) { this._profile = theProfile; this._name = this._profile.username; this._id = this._profile.id; } - Object.defineProperty(Player.prototype, "profile", { - get: function () { - return this._profile; - }, - set: function (newProfile) { - this._profile = newProfile; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Player.prototype, "name", { - get: function () { - return this._name; - }, - set: function (newName) { - this._name = newName; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Player.prototype, "id", { - get: function () { - return this._id; - }, - set: function (newId) { - this._id = newId; - }, - enumerable: true, - configurable: true - }); - return Player; -}()); + 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/profile.js b/js/profile.js index fbde5c5c..5f875aa9 100644 --- a/js/profile.js +++ b/js/profile.js @@ -1,41 +1,28 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var Profile = /** @class */ (function () { - function Profile(theUsername, theBalance, theId) { +class Profile { + constructor(theUsername, theBalance, theId) { this._username = theUsername; this._balance = theBalance; this._id = theId; } - Object.defineProperty(Profile.prototype, "id", { - get: function () { - return this._id; - }, - set: function (newId) { - this._id = newId; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Profile.prototype, "username", { - get: function () { - return this._username; - }, - set: function (newUsername) { - this._username = newUsername; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Profile.prototype, "balance", { - get: function () { - return this._balance; - }, - set: function (newBalance) { - this._balance = newBalance; - }, - enumerable: true, - configurable: true - }); - return Profile; -}()); + 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 index d33649a6..4a0bcef8 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1,11 +1,10 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var UI = /** @class */ (function () { - function UI() { +class UI { + constructor() { } - UI.prototype.display = function (someString) { + display(someString) { document.getElementById("display").innerHTML = someString; - }; - return UI; -}()); + } +} exports.UI = UI; diff --git a/tsconfig.json b/tsconfig.json index e425117e..243bdb28 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { /* Basic Options */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "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. */