From a4621bd9e98f5b0f63d06f552ddc053dd6d19402 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Fri, 23 Mar 2018 16:23:39 -0400 Subject: [PATCH 01/16] saving --- js/app.js | 11 ++++++++++ js/app.ts | 8 ++++++++ tsconfig.json | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 js/app.js create mode 100644 js/app.ts create mode 100644 tsconfig.json diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..866e528d --- /dev/null +++ b/js/app.js @@ -0,0 +1,11 @@ +"use strict"; +var Startup = /** @class */ (function () { + function Startup() { + } + Startup.main = function () { + var webElement = document.getElementById("display"); + webElement.innerText += "Hello World"; + }; + return Startup; +}()); +Startup.main(); diff --git a/js/app.ts b/js/app.ts new file mode 100644 index 00000000..acc13fbc --- /dev/null +++ b/js/app.ts @@ -0,0 +1,8 @@ +class Startup { + public static main(): void { + var webElement = document.getElementById("display"); + webElement.innerText += "Hello World"; + } +} + +Startup.main(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..cb57cd13 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,57 @@ +{ + "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": "./", /* 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'). */ + + /* 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. */ + } +} \ No newline at end of file From 0165a3e71dcadbad282300a7963faa744acaab9d Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sat, 24 Mar 2018 17:19:56 -0400 Subject: [PATCH 02/16] made the damn submit button work --- index.html | 2 +- js/app.js | 6 ++++-- js/app.ts | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index d2c3c254..a378524e 100644 --- a/index.html +++ b/index.html @@ -22,7 +22,7 @@

TypeScript Casino

- +
diff --git a/js/app.js b/js/app.js index 866e528d..ef7aa934 100644 --- a/js/app.js +++ b/js/app.js @@ -3,8 +3,10 @@ var Startup = /** @class */ (function () { function Startup() { } Startup.main = function () { - var webElement = document.getElementById("display"); - webElement.innerText += "Hello World"; + var input = document.getElementById("user_input"); + var window = document.getElementById('display'); + var button = document.getElementById('submit'); + button.addEventListener("click", function (e) { window.innerText += input.value + '\n'; }); }; return Startup; }()); diff --git a/js/app.ts b/js/app.ts index acc13fbc..dd005c9d 100644 --- a/js/app.ts +++ b/js/app.ts @@ -1,7 +1,17 @@ class Startup { + public static main(): void { - var webElement = document.getElementById("display"); - webElement.innerText += "Hello World"; + var input = document.getElementById("user_input"); + var window = document.getElementById('display'); + var button = document.getElementById('submit'); + + + button.addEventListener("click",(e:Event)=>{window.innerText += input.value + '\n'}); + + + + + } } From 696c124cb814e535a8589178739fcd03100e0902 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sat, 24 Mar 2018 17:23:15 -0400 Subject: [PATCH 03/16] submit field now clears after click event --- js/app.js | 1 + js/app.ts | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/js/app.js b/js/app.js index ef7aa934..231ad80c 100644 --- a/js/app.js +++ b/js/app.js @@ -7,6 +7,7 @@ var Startup = /** @class */ (function () { var window = document.getElementById('display'); var button = document.getElementById('submit'); button.addEventListener("click", function (e) { window.innerText += input.value + '\n'; }); + button.addEventListener("click", function (e) { input.value = ''; }); }; return Startup; }()); diff --git a/js/app.ts b/js/app.ts index dd005c9d..4d45a06d 100644 --- a/js/app.ts +++ b/js/app.ts @@ -5,13 +5,9 @@ class Startup { var window = document.getElementById('display'); var button = document.getElementById('submit'); - button.addEventListener("click",(e:Event)=>{window.innerText += input.value + '\n'}); - - - - - + button.addEventListener("click",(e:Event)=>{input.value = ''}); + } } From 5b48eaf154537821f6cdf2f42e4fe3c7af3dc65e Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sat, 24 Mar 2018 21:02:15 -0400 Subject: [PATCH 04/16] finally got that damn button working --- js/app.js | 84 ++++++++++++++++++++++++++++++++++++++++++--- js/app.ts | 101 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 172 insertions(+), 13 deletions(-) diff --git a/js/app.js b/js/app.js index 231ad80c..ba7ed17d 100644 --- a/js/app.js +++ b/js/app.js @@ -3,12 +3,86 @@ var Startup = /** @class */ (function () { function Startup() { } Startup.main = function () { - var input = document.getElementById("user_input"); - var window = document.getElementById('display'); - var button = document.getElementById('submit'); - button.addEventListener("click", function (e) { window.innerText += input.value + '\n'; }); - button.addEventListener("click", function (e) { input.value = ''; }); + var casino = new Casino(); + casino.start(); }; return Startup; }()); +var Casino = /** @class */ (function () { + function Casino() { + this.chooser = this.chooseGame.bind(this); + } + Casino.prototype.start = function () { + UI.display("What game do you want to play?"); + UI.display("Black Jack or Go Fish?"); + UI.button.addEventListener("click", this.chooser); + }; + Casino.prototype.chooseGame = function () { + UI.button.removeEventListener("click", this.chooser); + if (UI.lastInput === "Black Jack") { + BlackJack.start(); + } + else if (UI.lastInput === "Go Fish") { + GoFish.start(); + } + else { + UI.button.addEventListener("click", this.chooser); + } + }; + return Casino; +}()); +var UI = /** @class */ (function () { + function UI() { + UI.button.addEventListener("click", function (e) { UI._lastInput = UI.userInput.value; }); + UI.button.addEventListener("click", function (e) { UI.userInput.value = ''; }); + } + UI.display = function (input) { + this.window.innerText += input + '\n'; + }; + UI.clearScreen = function () { + this.window.innerText = ''; + }; + UI.getInput = function () { + UI.button.addEventListener("click", function (e) { UI._lastInput = UI.userInput.value; }); + UI.button.addEventListener("click", function (e) { UI.userInput.value = ''; }); + }; + Object.defineProperty(UI, "Instance", { + get: function () { + return this._instance || (this._instance = new UI()); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(UI, "lastInput", { + get: function () { + return this._lastInput; + }, + enumerable: true, + configurable: true + }); + UI.userInput = document.getElementById("user_input"); + UI.window = document.getElementById('display'); + UI.button = document.getElementById('submit'); + return UI; +}()); +var BlackJack = /** @class */ (function () { + function BlackJack() { + } + BlackJack.start = function () { + UI.clearScreen(); + UI.display("Black Jack"); + }; + return BlackJack; +}()); +var GoFish = /** @class */ (function () { + function GoFish() { + } + GoFish.start = function () { + UI.clearScreen(); + UI.display("Go Fish"); + }; + return GoFish; +}()); +//var lastInput : any; +var UIInstance = UI.Instance; Startup.main(); diff --git a/js/app.ts b/js/app.ts index 4d45a06d..aa837f79 100644 --- a/js/app.ts +++ b/js/app.ts @@ -1,14 +1,99 @@ class Startup { - + public static main(): void { - var input = document.getElementById("user_input"); - var window = document.getElementById('display'); - var button = document.getElementById('submit'); - - button.addEventListener("click",(e:Event)=>{window.innerText += input.value + '\n'}); - button.addEventListener("click",(e:Event)=>{input.value = ''}); - + var casino = new Casino(); + casino.start(); + } +} + + +class Casino { + + constructor(){} + + start() { + UI.display("What game do you want to play?"); + UI.display("Black Jack or Go Fish?"); + UI.button.addEventListener("click", this.chooser); + } + + chooseGame(): void { + UI.button.removeEventListener("click", this.chooser); + if (UI.lastInput === "Black Jack") { + + BlackJack.start(); + + } + else if (UI.lastInput === "Go Fish") { + GoFish.start(); + + } + else { + UI.button.addEventListener("click", this.chooser); + } + } + + chooser = this.chooseGame.bind(this); + + + +} + + + + +class UI { + static userInput = document.getElementById("user_input"); + static window = document.getElementById('display'); + static button = document.getElementById('submit'); + static _lastInput: any; + private static _instance: UI; + + private constructor() { + UI.button.addEventListener("click", (e: Event) => { UI._lastInput = UI.userInput.value }); + UI.button.addEventListener("click", (e: Event) => { UI.userInput.value = '' }); + + } + + static display(input: string): void { + this.window.innerText += input + '\n'; + } + + static clearScreen(): void { + this.window.innerText = ''; + } + + static getInput(): void { + UI.button.addEventListener("click", (e: Event) => { UI._lastInput = UI.userInput.value }); + UI.button.addEventListener("click", (e: Event) => { UI.userInput.value = '' }); + + } + + public static get Instance(): UI { + return this._instance || (this._instance = new UI()); + } + + public static get lastInput(): any { + return this._lastInput; + + } + +} + +class BlackJack { + static start(): void { + UI.clearScreen(); + UI.display("Black Jack"); + } +} + +class GoFish { + static start(): void { + UI.clearScreen(); + UI.display("Go Fish"); } } +//var lastInput : any; +const UIInstance = UI.Instance; Startup.main(); \ No newline at end of file From d69c7e74bc32d86cb8eba40f10de645df724c4f1 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sun, 25 Mar 2018 16:41:19 -0400 Subject: [PATCH 05/16] woo baby truckin along --- js/app.js | 332 +++++++++++++++++++++++++++++++++++---- js/app.ts | 428 +++++++++++++++++++++++++++++++++++++++++++++----- tsconfig.json | 2 +- 3 files changed, 688 insertions(+), 74 deletions(-) diff --git a/js/app.js b/js/app.js index ba7ed17d..9b795bde 100644 --- a/js/app.js +++ b/js/app.js @@ -1,32 +1,325 @@ "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 __()); + }; +})(); var Startup = /** @class */ (function () { function Startup() { } Startup.main = function () { - var casino = new Casino(); - casino.start(); + // var casino = new Casino(); + // casino.start(); + // var club = new Card(Rank.ACE, Suit.CLUBS); + // var diamond = new Card(Rank.FIVE, Suit.DIAMONDS); + // var spade = new Card(Rank.QUEEN, Suit.SPADES); + // var heart = new Card(Rank.JACK, Suit.HEARTS); + // UI.display(club); + // UI.display(heart); + // UI.display(spade); + // UI.display(diamond); + var deck = new Deck(); + deck.shuffle(); + for (var i = 0; i <= 51; i++) { + UI.display(deck.deal()); + } }; return Startup; }()); +var Profile = /** @class */ (function () { + function Profile(name, balance) { + this._id = Profile._lastId; + Profile._lastId++; + this._name = name; + this._balance = balance; + } + Object.defineProperty(Profile.prototype, "id", { + get: function () { + return this._id; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Profile.prototype, "name", { + get: function () { + return this._name; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Profile.prototype, "balance", { + get: function () { + return this._balance; + }, + set: function (newBalance) { + this._balance = newBalance; + }, + enumerable: true, + configurable: true + }); + Profile.prototype.addToBalance = function (amount) { + this._balance += amount; + }; + Profile._lastId = 1; + return Profile; +}()); +var Player = /** @class */ (function () { + function Player(playerProfile) { + this._playerProfile = playerProfile; + } + Player.prototype.getProfile = function () { + return this._playerProfile; + }; + Player.prototype.getName = function () { + return this._playerProfile.name; + }; + Player.prototype.getId = function () { + return this._playerProfile.id; + }; + return Player; +}()); +var CardPlayer = /** @class */ (function (_super) { + __extends(CardPlayer, _super); + function CardPlayer(profile) { + var _this = _super.call(this, profile) || this; + _this._hand = new Hand(); + return _this; + } + CardPlayer.prototype.takeCard = function (card) { + this._hand.cards.push(card); + }; + CardPlayer.prototype.discardAll = function () { + while (this._hand.cards.length > 0) { + this._hand.cards.pop(); + } + }; + Object.defineProperty(CardPlayer.prototype, "hand", { + get: function () { + return this._hand; + }, + enumerable: true, + configurable: true + }); + return CardPlayer; +}(Player)); +var BlackJackPlayer = /** @class */ (function (_super) { + __extends(BlackJackPlayer, _super); + function BlackJackPlayer(profile) { + var _this = _super.call(this, profile) || this; + _this.escrow = new Escrow(); + return _this; + } + BlackJackPlayer.prototype.bet = function (amount) { + this.escrow.addToEscrowBalance(amount); + this.getProfile().balance -= amount; + }; + BlackJackPlayer.prototype.win = function (amount, multiplier) { + var winnings = this.escrow.escrowBalance + (this.escrow.escrowBalance * multiplier); + this.getProfile().addToBalance(winnings); + this.escrow.escrowBalance = 0; + }; + BlackJackPlayer.prototype.lose = function () { + this.escrow.escrowBalance = 0; + }; + return BlackJackPlayer; +}(CardPlayer)); +var Escrow = /** @class */ (function () { + function Escrow() { + this._escrowBalance = 0; + } + Object.defineProperty(Escrow.prototype, "escrowBalance", { + get: function () { + return this._escrowBalance; + }, + set: function (amount) { + this._escrowBalance = amount; + }, + enumerable: true, + configurable: true + }); + Escrow.prototype.addToEscrowBalance = function (amount) { + this._escrowBalance += amount; + }; + return Escrow; +}()); +var Suit; +(function (Suit) { + Suit[Suit["HEARTS"] = 0] = "HEARTS"; + Suit[Suit["CLUBS"] = 1] = "CLUBS"; + Suit[Suit["DIAMONDS"] = 2] = "DIAMONDS"; + Suit[Suit["SPADES"] = 3] = "SPADES"; +})(Suit || (Suit = {})); +var Rank; +(function (Rank) { + Rank[Rank["TWO"] = 0] = "TWO"; + Rank[Rank["THREE"] = 1] = "THREE"; + Rank[Rank["FOUR"] = 2] = "FOUR"; + Rank[Rank["FIVE"] = 3] = "FIVE"; + Rank[Rank["SIX"] = 4] = "SIX"; + Rank[Rank["SEVEN"] = 5] = "SEVEN"; + Rank[Rank["EIGHT"] = 6] = "EIGHT"; + Rank[Rank["NINE"] = 7] = "NINE"; + Rank[Rank["TEN"] = 8] = "TEN"; + Rank[Rank["JACK"] = 9] = "JACK"; + Rank[Rank["QUEEN"] = 10] = "QUEEN"; + Rank[Rank["KING"] = 11] = "KING"; + Rank[Rank["ACE"] = 12] = "ACE"; +})(Rank || (Rank = {})); +var Card = /** @class */ (function () { + function Card(rank, suit) { + this._suit = suit; + this._rank = rank; + } + Object.defineProperty(Card.prototype, "suit", { + get: function () { + return this._suit; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Card.prototype, "rank", { + get: function () { + return this._rank; + }, + enumerable: true, + configurable: true + }); + Card.prototype.toString = function () { + if (this._suit === Suit.CLUBS) { + return Rank[this._rank] + " \u2663"; + } + else if (this._suit === Suit.DIAMONDS) { + return Rank[this._rank] + " \u2666"; + } + else if (this._suit === Suit.SPADES) { + return Rank[this._rank] + " \u2660"; + } + else if (this._suit === Suit.HEARTS) { + return Rank[this._rank] + " \u2665"; + } + else { + throw new Error("Something has gone horribly wrong"); + } + }; + return Card; +}()); +var Deck = /** @class */ (function () { + function Deck() { + this._cards = new Array(); + this.populate(); + } + Deck.prototype.deal = function () { + return this._cards.pop(); + }; + Deck.prototype.shuffle = function () { + this._cards.sort(function (a, b) { return 0.5 - Math.random(); }); + }; + Deck.prototype.populate = function () { + for (var suit = Suit.HEARTS; suit <= Suit.SPADES; suit++) { + for (var rank = Rank.TWO; rank <= Rank.ACE; rank++) { + this._cards.push(new Card(rank, suit)); + } + } + }; + return Deck; +}()); +var Hand = /** @class */ (function () { + function Hand() { + this._cards = new Array(); + } + Object.defineProperty(Hand.prototype, "cards", { + get: function () { + return this._cards; + }, + enumerable: true, + configurable: true + }); + return Hand; +}()); +var GameEngine = /** @class */ (function () { + function GameEngine(game) { + this._game = game; + } + GameEngine.prototype.getGame = function () { + return this._game; + }; + return GameEngine; +}()); +var CardGame = /** @class */ (function (_super) { + __extends(CardGame, _super); + function CardGame(game) { + var _this = _super.call(this, game) || this; + _this._players = new Array; + _this._deck = new Deck(); + return _this; + } + Object.defineProperty(CardGame.prototype, "deck", { + get: function () { + return this._deck; + }, + enumerable: true, + configurable: true + }); + CardGame.prototype.getPlayers = function () { + return this._players; + }; + CardGame.prototype.getPlayer = function (playerId) { + this._players.forEach(function (element) { + if (element.getId() === playerId) { + return element; + } + }); + throw new Error("Player not found"); + }; + CardGame.prototype.addPlayer = function (player) { + this._players.push(player); + }; + CardGame.prototype.removePlayer = function (player) { + this._players.splice(this._players.indexOf(player), 1); + }; + CardGame.prototype.contains = function (player) { + this._players.forEach(function (element) { + if (element === player) { + return true; + } + }); + return false; + }; + return CardGame; +}(GameEngine)); +var BlackJackGame = /** @class */ (function (_super) { + __extends(BlackJackGame, _super); + function BlackJackGame() { + return _super !== null && _super.apply(this, arguments) || this; + } + BlackJackGame.prototype.run = function () { + }; + BlackJackGame.prototype.evaluateTurn = function (player) { + }; + return BlackJackGame; +}(CardGame)); var Casino = /** @class */ (function () { function Casino() { - this.chooser = this.chooseGame.bind(this); + this.chooseGame = this.chooseGame.bind(this); } Casino.prototype.start = function () { UI.display("What game do you want to play?"); UI.display("Black Jack or Go Fish?"); - UI.button.addEventListener("click", this.chooser); + UI.button.addEventListener("click", this.chooseGame); }; Casino.prototype.chooseGame = function () { - UI.button.removeEventListener("click", this.chooser); + 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.chooser); + UI.button.addEventListener("click", this.chooseGame); } }; return Casino; @@ -42,10 +335,6 @@ var UI = /** @class */ (function () { UI.clearScreen = function () { this.window.innerText = ''; }; - UI.getInput = function () { - UI.button.addEventListener("click", function (e) { UI._lastInput = UI.userInput.value; }); - UI.button.addEventListener("click", function (e) { UI.userInput.value = ''; }); - }; Object.defineProperty(UI, "Instance", { get: function () { return this._instance || (this._instance = new UI()); @@ -65,24 +354,5 @@ var UI = /** @class */ (function () { UI.button = document.getElementById('submit'); return UI; }()); -var BlackJack = /** @class */ (function () { - function BlackJack() { - } - BlackJack.start = function () { - UI.clearScreen(); - UI.display("Black Jack"); - }; - return BlackJack; -}()); -var GoFish = /** @class */ (function () { - function GoFish() { - } - GoFish.start = function () { - UI.clearScreen(); - UI.display("Go Fish"); - }; - return GoFish; -}()); -//var lastInput : any; var UIInstance = UI.Instance; Startup.main(); diff --git a/js/app.ts b/js/app.ts index aa837f79..bee4efd1 100644 --- a/js/app.ts +++ b/js/app.ts @@ -1,46 +1,413 @@ class Startup { public static main(): void { - var casino = new Casino(); - casino.start(); + // var casino = new Casino(); + // casino.start(); + + // var club = new Card(Rank.ACE, Suit.CLUBS); + // var diamond = new Card(Rank.FIVE, Suit.DIAMONDS); + // var spade = new Card(Rank.QUEEN, Suit.SPADES); + // var heart = new Card(Rank.JACK, Suit.HEARTS); + + + // UI.display(club); + // UI.display(heart); + // UI.display(spade); + // UI.display(diamond); + var deck = new Deck(); + deck.shuffle(); + for (var i = 0; i <= 51; i++) { + UI.display(deck.deal()); + } + } } -class Casino { +class Profile { + private static _lastId: number = 1; + private _id: number; + private _name: string; + private _balance: number; - constructor(){} + constructor(name: string, balance: number) { + this._id = Profile._lastId; + Profile._lastId++; + this._name = name; + this._balance = balance; + } - start() { - UI.display("What game do you want to play?"); - UI.display("Black Jack or Go Fish?"); - UI.button.addEventListener("click", this.chooser); + public get id(): number { + return this._id; } - chooseGame(): void { - UI.button.removeEventListener("click", this.chooser); - if (UI.lastInput === "Black Jack") { - - BlackJack.start(); - + public get name(): string { + return this._name; + } + + public get balance(): number { + return this._balance; + } + + public set balance(newBalance: number) { + this._balance = newBalance; + } + + public addToBalance(amount:number):void{ + this._balance += amount; + } + +} + +interface PlayerInterface { + + getProfile(): Profile; + getName(): string; + getId(): number; + +} + +abstract class Player implements PlayerInterface { + + private _playerProfile: Profile; + + constructor(playerProfile: Profile) { + this._playerProfile = playerProfile; + } + + public getProfile(): Profile { + return this._playerProfile; + } + + public getName(): string { + return this._playerProfile.name; + } + + public getId(): number { + return this._playerProfile.id; + } + +} + +abstract class CardPlayer extends Player { + + private _hand: Hand; + + constructor(profile: Profile) { + super(profile); + this._hand = new Hand(); + } + + public takeCard(card: Card): void { + this._hand.cards.push(card); + } + + public discardAll(): void { + while (this._hand.cards.length > 0) { + this._hand.cards.pop(); } - else if (UI.lastInput === "Go Fish") { - GoFish.start(); + } + + public get hand():Hand{ + return this._hand; + } + +} + +class BlackJackPlayer extends CardPlayer implements Gamble { + escrow:Escrow; + + constructor(profile:Profile){ + super(profile); + this.escrow = new Escrow(); + } + + bet(amount: number): void { + this.escrow.addToEscrowBalance(amount); + this.getProfile().balance -= amount; + } + win(amount: number, multiplier: number): void { + let winnings:number = this.escrow.escrowBalance + (this.escrow.escrowBalance * multiplier); + this.getProfile().addToBalance(winnings); + this.escrow.escrowBalance=0; + } + lose(): void { + this.escrow.escrowBalance=0; + } +} + +class Escrow{ + + private _escrowBalance:number; + + constructor(){ + this._escrowBalance = 0; + } + + public get escrowBalance():number{ + return this._escrowBalance; + } + + public set escrowBalance(amount:number){ + this._escrowBalance=amount; + } + + public addToEscrowBalance(amount:number){ + this._escrowBalance+=amount; + } + + + +} + +enum Suit { + HEARTS, + CLUBS, + DIAMONDS, + SPADES + +} + +enum Rank { + TWO, + THREE, + FOUR, + FIVE, + SIX, + SEVEN, + EIGHT, + NINE, + TEN, + JACK, + QUEEN, + KING, + ACE +} + +class Card { + + private _suit: Suit; + private _rank: Rank; + + constructor(rank: Rank, suit: Suit) { + this._suit = suit; + this._rank = rank; + } + + public get suit(): Suit { + return this._suit; + } + + public get rank(): Rank { + return this._rank; + } + + public toString(): string { + if (this._suit === Suit.CLUBS) { + return Rank[this._rank] + ' \u{2663}'; + } + else if (this._suit === Suit.DIAMONDS) { + return Rank[this._rank] + ' \u{2666}'; + } + else if (this._suit === Suit.SPADES) { + return Rank[this._rank] + ' \u{2660}'; + } + else if (this._suit === Suit.HEARTS) { + return Rank[this._rank] + ' \u{2665}'; } else { - UI.button.addEventListener("click", this.chooser); + throw new Error("Something has gone horribly wrong"); } + + } + + +} + +class Deck { + + private _cards: Card[]; + + constructor() { + this._cards = new Array(); + this.populate(); } - chooser = this.chooseGame.bind(this); + public deal(): Card { + return this._cards.pop(); + } + public shuffle(): void { + this._cards.sort(function (a, b) { return 0.5 - Math.random() }); + } + private populate(): void { + for (let suit = Suit.HEARTS; suit <= Suit.SPADES; suit++) { + for (let rank = Rank.TWO; rank <= Rank.ACE; rank++) { + this._cards.push(new Card(rank, suit)) + } + } + } } +class Hand { + private _cards: Card[]; + constructor() { + this._cards = new Array(); + } + + public get cards(): Card[] { + return this._cards; + } + +} + +interface GameInterface { + + getPlayers(): PlayerInterface[]; + getPlayer(playerId: number): PlayerInterface; + addPlayer(player: PlayerInterface): void; + removePlayer(player: PlayerInterface): void; + contains(player: PlayerInterface): boolean; + +} + +interface GameEngineInterface { + + run(): void; + getGame(): GameInterface; + evaluateTurn(player: PlayerInterface): void; + +} + +abstract class GameEngine implements GameEngineInterface, PlayerInterface>{ + + private _game: GameInterface; + + constructor(game: GameInterface) { + this._game = game; + + } + abstract run(): void; + abstract evaluateTurn(player: PlayerInterface): void; + + public getGame(): GameInterface { + return this._game; + } + +} + +interface Gamble { + + escrow:Escrow; + + bet(amount: number): void; + win(amount: number, multiplier: number): void; + lose(): void; + +} + + +abstract class CardGame extends GameEngine implements GameInterface { + + private _players: CardPlayer[]; + private _deck: Deck; + + constructor(game: CardGame) { + super(game); + this._players = new Array; + this._deck = new Deck(); + + } + + + public get deck(): Deck { + return this._deck; + } + + + getPlayers(): CardPlayer[] { + return this._players; + + } + + getPlayer(playerId: number): CardPlayer { + this._players.forEach(element => { + if (element.getId() === playerId) { + return element; + } + }); + throw new Error("Player not found"); + } + + addPlayer(player: CardPlayer): void { + this._players.push(player); + } + + removePlayer(player: CardPlayer): void { + this._players.splice(this._players.indexOf(player), 1); + } + + contains(player: CardPlayer): boolean { + this._players.forEach(element => { + if (element === player) { + return true; + } + }); + return false; + } +} + +class BlackJackGame extends CardGame { + run(): void { + + } + + evaluateTurn(player: BlackJackPlayer): void { + + } + + + +} + + + +class Casino { + + + 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") { + + + + } + else if (UI.lastInput === "Go Fish") { + + + } + else { + UI.button.addEventListener("click", this.chooseGame); + } + } + + +} class UI { static userInput = document.getElementById("user_input"); @@ -52,10 +419,9 @@ class UI { private constructor() { UI.button.addEventListener("click", (e: Event) => { UI._lastInput = UI.userInput.value }); UI.button.addEventListener("click", (e: Event) => { UI.userInput.value = '' }); - } - static display(input: string): void { + static display(input: any): void { this.window.innerText += input + '\n'; } @@ -63,37 +429,15 @@ class UI { this.window.innerText = ''; } - static getInput(): void { - UI.button.addEventListener("click", (e: Event) => { UI._lastInput = UI.userInput.value }); - UI.button.addEventListener("click", (e: Event) => { UI.userInput.value = '' }); - - } - public static get Instance(): UI { return this._instance || (this._instance = new UI()); } public static get lastInput(): any { return this._lastInput; - } } -class BlackJack { - static start(): void { - UI.clearScreen(); - UI.display("Black Jack"); - } -} - -class GoFish { - static start(): void { - UI.clearScreen(); - UI.display("Go Fish"); - } -} - -//var lastInput : any; const UIInstance = UI.Instance; Startup.main(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index cb57cd13..5617cd44 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,7 @@ /* 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. */ + "strictNullChecks": false, /* 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. */ From 74437307b8cb52c2773cf17eb45cc849c1f623a0 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sun, 25 Mar 2018 16:51:46 -0400 Subject: [PATCH 06/16] saving --- js/app.js | 30 ++++++++++++++++++++++++++++++ js/app.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/js/app.js b/js/app.js index 9b795bde..b57341de 100644 --- a/js/app.js +++ b/js/app.js @@ -126,6 +126,36 @@ var BlackJackPlayer = /** @class */ (function (_super) { BlackJackPlayer.prototype.lose = function () { this.escrow.escrowBalance = 0; }; + Object.defineProperty(BlackJackPlayer.prototype, "busted", { + get: function () { + return this.busted; + }, + set: function (state) { + this._busted = state; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BlackJackPlayer.prototype, "stand", { + get: function () { + return this._stand; + }, + set: function (state) { + this._stand = state; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BlackJackPlayer.prototype, "score", { + get: function () { + return this._score; + }, + set: function (amount) { + this._score = amount; + }, + enumerable: true, + configurable: true + }); return BlackJackPlayer; }(CardPlayer)); var Escrow = /** @class */ (function () { diff --git a/js/app.ts b/js/app.ts index bee4efd1..6b58ae02 100644 --- a/js/app.ts +++ b/js/app.ts @@ -117,6 +117,9 @@ abstract class CardPlayer extends Player { class BlackJackPlayer extends CardPlayer implements Gamble { escrow:Escrow; + private _busted:boolean; + private _stand:boolean; + private _score:number; constructor(profile:Profile){ super(profile); @@ -135,6 +138,30 @@ class BlackJackPlayer extends CardPlayer implements Gamble { lose(): void { this.escrow.escrowBalance=0; } + + public get busted():boolean{ + return this.busted; + } + + public set busted(state:boolean){ + this._busted=state; + } + + public get stand():boolean{ + return this._stand; + } + + public set stand(state:boolean){ + this._stand=state; + } + + public get score():number{ + return this._score; + } + + public set score(amount:number){ + this._score=amount; + } } class Escrow{ From 57800197c4b525b3f22bd80734f92d84fb68263a Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sun, 25 Mar 2018 17:48:09 -0400 Subject: [PATCH 07/16] calculating blackjack scores baby --- js/app.js | 111 +++++++++++++++++++++++++++++++++++++++++++++++------- js/app.ts | 99 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 178 insertions(+), 32 deletions(-) diff --git a/js/app.js b/js/app.js index b57341de..310d4d43 100644 --- a/js/app.js +++ b/js/app.js @@ -23,11 +23,25 @@ var Startup = /** @class */ (function () { // UI.display(heart); // UI.display(spade); // UI.display(diamond); - var deck = new Deck(); - deck.shuffle(); - for (var i = 0; i <= 51; i++) { - UI.display(deck.deal()); - } + // var deck = new Deck(); + // deck.shuffle(); + // for (var i = 0; i <= 51; i++) { + // UI.display(deck.deal()); + // } + var profile = new Profile('Eric', 10000); + var player = new BlackJackPlayer(profile); + var ace = new Card(Rank.ACE, Suit.SPADES); + var king = new Card(Rank.KING, Suit.SPADES); + var seven = new Card(Rank.SEVEN, Suit.SPADES); + var two = new Card(Rank.TWO, Suit.SPADES); + var five = new Card(Rank.FIVE, Suit.SPADES); + player.takeCard(ace); + player.takeCard(five); + player.takeCard(seven); + player.takeCard(ace); + player.calculateScore(); + UI.display(player.hand.cards); + UI.display(player.score); }; return Startup; }()); @@ -156,6 +170,81 @@ var BlackJackPlayer = /** @class */ (function (_super) { enumerable: true, configurable: true }); + BlackJackPlayer.prototype.isBusted = function () { + if (this._score > 21) { + return true; + } + else { + return false; + } + }; + BlackJackPlayer.prototype.calculateScore = function () { + var hasAce = false; + var tempScore = 0; + this.hand.cards.forEach(function (element) { + if (element.rank === Rank.TWO) + tempScore += 2; + else if (element.rank === Rank.THREE) + tempScore += 3; + else if (element.rank === Rank.FOUR) + tempScore += 4; + else if (element.rank === Rank.FIVE) + tempScore += 5; + else if (element.rank === Rank.SIX) + tempScore += 6; + else if (element.rank === Rank.SEVEN) + tempScore += 7; + else if (element.rank === Rank.EIGHT) + tempScore += 8; + else if (element.rank === Rank.NINE) + tempScore += 9; + else if (element.rank === Rank.TEN) + tempScore += 10; + else if (element.rank === Rank.JACK) + tempScore += 10; + else if (element.rank === Rank.QUEEN) + tempScore += 10; + else if (element.rank === Rank.KING) + tempScore += 10; + else if (element.rank === Rank.ACE) { + tempScore += 11; + hasAce = true; + } + }); + if (tempScore > 21 && hasAce) { + tempScore = 0; + this.hand.cards.forEach(function (element) { + if (element.rank === Rank.TWO) + tempScore += 2; + else if (element.rank === Rank.THREE) + tempScore += 3; + else if (element.rank === Rank.FOUR) + tempScore += 4; + else if (element.rank === Rank.FIVE) + tempScore += 5; + else if (element.rank === Rank.SIX) + tempScore += 6; + else if (element.rank === Rank.SEVEN) + tempScore += 7; + else if (element.rank === Rank.EIGHT) + tempScore += 8; + else if (element.rank === Rank.NINE) + tempScore += 9; + else if (element.rank === Rank.TEN) + tempScore += 10; + else if (element.rank === Rank.JACK) + tempScore += 10; + else if (element.rank === Rank.QUEEN) + tempScore += 10; + else if (element.rank === Rank.KING) + tempScore += 10; + else if (element.rank === Rank.ACE) { + tempScore += 1; + } + }); + } + this._score = tempScore; + }; return BlackJackPlayer; }(CardPlayer)); var Escrow = /** @class */ (function () { @@ -272,19 +361,15 @@ var Hand = /** @class */ (function () { return Hand; }()); var GameEngine = /** @class */ (function () { - function GameEngine(game) { - this._game = game; + function GameEngine() { } - GameEngine.prototype.getGame = function () { - return this._game; - }; return GameEngine; }()); var CardGame = /** @class */ (function (_super) { __extends(CardGame, _super); - function CardGame(game) { - var _this = _super.call(this, game) || this; - _this._players = new Array; + function CardGame() { + var _this = _super.call(this) || this; + _this._players = new Array(); _this._deck = new Deck(); return _this; } diff --git a/js/app.ts b/js/app.ts index 6b58ae02..881f2f78 100644 --- a/js/app.ts +++ b/js/app.ts @@ -14,11 +14,27 @@ class Startup { // UI.display(heart); // UI.display(spade); // UI.display(diamond); - var deck = new Deck(); - deck.shuffle(); - for (var i = 0; i <= 51; i++) { - UI.display(deck.deal()); - } + // var deck = new Deck(); + // deck.shuffle(); + // for (var i = 0; i <= 51; i++) { + // UI.display(deck.deal()); + // } + + var profile = new Profile('Eric',10000); + var player = new BlackJackPlayer(profile); + var ace = new Card(Rank.ACE, Suit.SPADES); + var king = new Card(Rank.KING, Suit.SPADES); + var seven = new Card(Rank.SEVEN, Suit.SPADES); + var two = new Card(Rank.TWO, Suit.SPADES); + var five = new Card(Rank.FIVE, Suit.SPADES); + + player.takeCard(ace); + player.takeCard(five); + player.takeCard(seven); + player.takeCard(ace); + player.calculateScore(); + UI.display(player.hand.cards); + UI.display(player.score); } } @@ -162,6 +178,60 @@ class BlackJackPlayer extends CardPlayer implements Gamble { public set score(amount:number){ this._score=amount; } + + public isBusted():boolean{ + if(this._score>21){ + return true; + } + else{ + return false; + } + } + + public calculateScore():void{ + let hasAce : boolean = false; + let tempScore : number = 0; + this.hand.cards.forEach(element => { + if(element.rank === Rank.TWO) tempScore += 2; + else if (element.rank === Rank.THREE) tempScore +=3; + else if (element.rank === Rank.FOUR) tempScore +=4; + else if (element.rank === Rank.FIVE) tempScore +=5; + else if (element.rank === Rank.SIX) tempScore +=6; + else if (element.rank === Rank.SEVEN) tempScore +=7; + else if (element.rank === Rank.EIGHT) tempScore +=8; + else if (element.rank === Rank.NINE) tempScore +=9; + else if (element.rank === Rank.TEN) tempScore +=10; + else if (element.rank === Rank.JACK) tempScore +=10; + else if (element.rank === Rank.QUEEN) tempScore +=10; + else if (element.rank === Rank.KING) tempScore +=10; + else if (element.rank === Rank.ACE) { + tempScore +=11; + hasAce = true; + } + }); + if(tempScore >21 && hasAce){ + tempScore = 0; + this.hand.cards.forEach(element => { + if(element.rank === Rank.TWO) tempScore += 2; + else if (element.rank === Rank.THREE) tempScore +=3; + else if (element.rank === Rank.FOUR) tempScore +=4; + else if (element.rank === Rank.FIVE) tempScore +=5; + else if (element.rank === Rank.SIX) tempScore +=6; + else if (element.rank === Rank.SEVEN) tempScore +=7; + else if (element.rank === Rank.EIGHT) tempScore +=8; + else if (element.rank === Rank.NINE) tempScore +=9; + else if (element.rank === Rank.TEN) tempScore +=10; + else if (element.rank === Rank.JACK) tempScore +=10; + else if (element.rank === Rank.QUEEN) tempScore +=10; + else if (element.rank === Rank.KING) tempScore +=10; + else if (element.rank === Rank.ACE) { + tempScore +=1; + } + }); + } + this._score=tempScore; + } + } class Escrow{ @@ -305,25 +375,17 @@ interface GameInterface { interface GameEngineInterface { run(): void; - getGame(): GameInterface; evaluateTurn(player: PlayerInterface): void; } abstract class GameEngine implements GameEngineInterface, PlayerInterface>{ - private _game: GameInterface; - - constructor(game: GameInterface) { - this._game = game; - - } + abstract run(): void; abstract evaluateTurn(player: PlayerInterface): void; - public getGame(): GameInterface { - return this._game; - } + } @@ -343,11 +405,10 @@ abstract class CardGame extends GameEngine implements GameInterface private _players: CardPlayer[]; private _deck: Deck; - constructor(game: CardGame) { - super(game); - this._players = new Array; + constructor() { + super(); + this._players = new Array(); this._deck = new Deck(); - } From 28b65b2a5d5f86f6c7fa2fd42f13f176fbb89591 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sun, 25 Mar 2018 18:51:47 -0400 Subject: [PATCH 08/16] slow and steady progress baby --- js/app.js | 73 +++++++++++++++++++++++++++++++++++++++----------- js/app.ts | 80 +++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 124 insertions(+), 29 deletions(-) diff --git a/js/app.js b/js/app.js index 310d4d43..2bfa8531 100644 --- a/js/app.js +++ b/js/app.js @@ -29,19 +29,21 @@ var Startup = /** @class */ (function () { // UI.display(deck.deal()); // } var profile = new Profile('Eric', 10000); - var player = new BlackJackPlayer(profile); - var ace = new Card(Rank.ACE, Suit.SPADES); - var king = new Card(Rank.KING, Suit.SPADES); - var seven = new Card(Rank.SEVEN, Suit.SPADES); - var two = new Card(Rank.TWO, Suit.SPADES); - var five = new Card(Rank.FIVE, Suit.SPADES); - player.takeCard(ace); - player.takeCard(five); - player.takeCard(seven); - player.takeCard(ace); - player.calculateScore(); - UI.display(player.hand.cards); - UI.display(player.score); + // var player = new BlackJackPlayer(profile); + // var ace = new Card(Rank.ACE, Suit.SPADES); + // var king = new Card(Rank.KING, Suit.SPADES); + // var seven = new Card(Rank.SEVEN, Suit.SPADES); + // var two = new Card(Rank.TWO, Suit.SPADES); + // var five = new Card(Rank.FIVE, Suit.SPADES); + // player.takeCard(ace); + // player.takeCard(five); + // player.takeCard(seven); + // player.takeCard(ace); + // player.calculateScore(); + // UI.display(player.hand.cards); + // UI.display(player.score); + var test = new BlackJackGame(profile); + test.run(); }; return Startup; }()); @@ -409,13 +411,54 @@ var CardGame = /** @class */ (function (_super) { }(GameEngine)); var BlackJackGame = /** @class */ (function (_super) { __extends(BlackJackGame, _super); - function BlackJackGame() { - return _super !== null && _super.apply(this, arguments) || this; + function BlackJackGame(playerProfile) { + var _this = _super.call(this) || this; + var dealer = new BlackJackPlayer(new Profile('Dealer', 0)); + _this.currentPlayer = new BlackJackPlayer(playerProfile); + _this.addPlayer(dealer); + _this.addPlayer(_this.currentPlayer); + _this.startRound = _this.startRound.bind(_this); + _this.placeBet = _this.placeBet.bind(_this); + _this.run = _this.run.bind(_this); + return _this; } BlackJackGame.prototype.run = function () { + this.startRound(); }; BlackJackGame.prototype.evaluateTurn = function (player) { }; + BlackJackGame.prototype.startRound = function (errorMessage) { + this.header(); + UI.display("How much would you like to bet?"); + UI.display("This minimum bet is $10"); + if (typeof errorMessage !== "undefined") + UI.display(errorMessage); + UI.button.addEventListener("click", this.placeBet); + }; + BlackJackGame.prototype.placeBet = function () { + UI.button.removeEventListener("click", this.placeBet); + UI.clearScreen(); + if (UI.lastInput <= this.currentPlayer.getProfile().balance && UI.lastInput > 10) { + this.currentPlayer.bet(UI.lastInput); + this.initialDeal(); + } + else if (UI.lastInput < 10) { + this.startRound("That amount is below the minimum bet"); + } + else if (UI.lastInput > this.currentPlayer.getProfile().balance) { + this.startRound("You cannot bet more money than you have"); + } + else { + this.startRound("You must input a number to place a bet"); + } + }; + BlackJackGame.prototype.initialDeal = function () { + UI.clearScreen(); + UI.display("YaY!"); + }; + BlackJackGame.prototype.header = function () { + UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance); + }; return BlackJackGame; }(CardGame)); var Casino = /** @class */ (function () { diff --git a/js/app.ts b/js/app.ts index 881f2f78..e7656529 100644 --- a/js/app.ts +++ b/js/app.ts @@ -21,20 +21,23 @@ class Startup { // } var profile = new Profile('Eric',10000); - var player = new BlackJackPlayer(profile); - var ace = new Card(Rank.ACE, Suit.SPADES); - var king = new Card(Rank.KING, Suit.SPADES); - var seven = new Card(Rank.SEVEN, Suit.SPADES); - var two = new Card(Rank.TWO, Suit.SPADES); - var five = new Card(Rank.FIVE, Suit.SPADES); - - player.takeCard(ace); - player.takeCard(five); - player.takeCard(seven); - player.takeCard(ace); - player.calculateScore(); - UI.display(player.hand.cards); - UI.display(player.score); + // var player = new BlackJackPlayer(profile); + // var ace = new Card(Rank.ACE, Suit.SPADES); + // var king = new Card(Rank.KING, Suit.SPADES); + // var seven = new Card(Rank.SEVEN, Suit.SPADES); + // var two = new Card(Rank.TWO, Suit.SPADES); + // var five = new Card(Rank.FIVE, Suit.SPADES); + + // player.takeCard(ace); + // player.takeCard(five); + // player.takeCard(seven); + // player.takeCard(ace); + // player.calculateScore(); + // UI.display(player.hand.cards); + // UI.display(player.score); + + var test = new BlackJackGame(profile); + test.run(); } } @@ -451,7 +454,21 @@ abstract class CardGame extends GameEngine implements GameInterface class BlackJackGame extends CardGame { + currentPlayer : BlackJackPlayer; + + constructor(playerProfile:Profile){ + super(); + let dealer = new BlackJackPlayer(new Profile('Dealer',0)); + this.currentPlayer = new BlackJackPlayer(playerProfile); + this.addPlayer(dealer); + this.addPlayer(this.currentPlayer); + this.startRound = this.startRound.bind(this); + this.placeBet = this.placeBet.bind(this); + this.run = this.run.bind(this); + } + run(): void { + this.startRound(); } @@ -459,6 +476,41 @@ class BlackJackGame extends CardGame { } + private startRound(errorMessage?:string):void{ + this.header(); + UI.display("How much would you like to bet?"); + UI.display("This minimum bet is $10"); + if(typeof errorMessage !== "undefined") UI.display(errorMessage); + UI.button.addEventListener("click", this.placeBet); + } + + private placeBet():void{ + UI.button.removeEventListener("click", this.placeBet); + UI.clearScreen(); + if(UI.lastInput <= this.currentPlayer.getProfile().balance && UI.lastInput >10){ + this.currentPlayer.bet(UI.lastInput); + this.initialDeal(); + } + else if (UI.lastInput <10){ + this.startRound("That amount is below the minimum bet"); + } + else if (UI.lastInput > this.currentPlayer.getProfile().balance){ + this.startRound("You cannot bet more money than you have"); + } + else{ + this.startRound("You must input a number to place a bet"); + } + } + + private initialDeal():void{ + UI.clearScreen(); + UI.display("YaY!"); + } + + private header():void{ + UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance); + } + } From 0a7bf025295fae21c554e931fe1db8e3592f4cf9 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sun, 25 Mar 2018 19:07:24 -0400 Subject: [PATCH 09/16] saving --- js/app.js | 10 ++++++---- js/app.ts | 14 ++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/js/app.js b/js/app.js index 2bfa8531..90209081 100644 --- a/js/app.js +++ b/js/app.js @@ -264,7 +264,9 @@ var Escrow = /** @class */ (function () { configurable: true }); Escrow.prototype.addToEscrowBalance = function (amount) { - this._escrowBalance += amount; + this._escrowBalance; + amount; + this.escrowBalance = this.escrowBalance + amount; }; return Escrow; }()); @@ -439,7 +441,7 @@ var BlackJackGame = /** @class */ (function (_super) { UI.button.removeEventListener("click", this.placeBet); UI.clearScreen(); if (UI.lastInput <= this.currentPlayer.getProfile().balance && UI.lastInput > 10) { - this.currentPlayer.bet(UI.lastInput); + this.currentPlayer.bet(parseInt(UI.lastInput)); this.initialDeal(); } else if (UI.lastInput < 10) { @@ -454,10 +456,10 @@ var BlackJackGame = /** @class */ (function (_super) { }; BlackJackGame.prototype.initialDeal = function () { UI.clearScreen(); - UI.display("YaY!"); + this.header(); }; BlackJackGame.prototype.header = function () { - UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance); + UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $" + this.currentPlayer.escrow.escrowBalance); }; return BlackJackGame; }(CardGame)); diff --git a/js/app.ts b/js/app.ts index e7656529..a74e7965 100644 --- a/js/app.ts +++ b/js/app.ts @@ -254,7 +254,9 @@ class Escrow{ } public addToEscrowBalance(amount:number){ - this._escrowBalance+=amount; + this._escrowBalance; + amount; + this.escrowBalance = this.escrowBalance + amount; } @@ -488,7 +490,7 @@ class BlackJackGame extends CardGame { UI.button.removeEventListener("click", this.placeBet); UI.clearScreen(); if(UI.lastInput <= this.currentPlayer.getProfile().balance && UI.lastInput >10){ - this.currentPlayer.bet(UI.lastInput); + this.currentPlayer.bet(parseInt(UI.lastInput)); this.initialDeal(); } else if (UI.lastInput <10){ @@ -504,15 +506,15 @@ class BlackJackGame extends CardGame { private initialDeal():void{ UI.clearScreen(); - UI.display("YaY!"); + this.header(); + + } private header():void{ - UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance); + UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $"+ this.currentPlayer.escrow.escrowBalance); } - - } From 46da5fb89952cfd90fa43df889fa1a9c65f034b6 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Sun, 25 Mar 2018 19:36:06 -0400 Subject: [PATCH 10/16] initial deal working --- js/app.js | 31 +++++++++++++++++++++++++++++-- js/app.ts | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/js/app.js b/js/app.js index 90209081..d75f738a 100644 --- a/js/app.js +++ b/js/app.js @@ -375,6 +375,7 @@ var CardGame = /** @class */ (function (_super) { var _this = _super.call(this) || this; _this._players = new Array(); _this._deck = new Deck(); + _this._deck.shuffle(); return _this; } Object.defineProperty(CardGame.prototype, "deck", { @@ -415,9 +416,9 @@ var BlackJackGame = /** @class */ (function (_super) { __extends(BlackJackGame, _super); function BlackJackGame(playerProfile) { var _this = _super.call(this) || this; - var dealer = new BlackJackPlayer(new Profile('Dealer', 0)); + _this.dealer = new BlackJackPlayer(new Profile('Dealer', 0)); _this.currentPlayer = new BlackJackPlayer(playerProfile); - _this.addPlayer(dealer); + _this.addPlayer(_this.dealer); _this.addPlayer(_this.currentPlayer); _this.startRound = _this.startRound.bind(_this); _this.placeBet = _this.placeBet.bind(_this); @@ -456,10 +457,36 @@ var BlackJackGame = /** @class */ (function (_super) { }; BlackJackGame.prototype.initialDeal = function () { UI.clearScreen(); + this.currentPlayer.takeCard(this.deck.deal()); + this.dealer.takeCard(this.deck.deal()); + this.currentPlayer.takeCard(this.deck.deal()); + this.dealer.takeCard(this.deck.deal()); this.header(); + this.showCards(); }; BlackJackGame.prototype.header = function () { UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $" + this.currentPlayer.escrow.escrowBalance); + UI.display(""); + }; + BlackJackGame.prototype.score = function () { + this.currentPlayer.calculateScore(); + UI.display("Current Score: " + this.currentPlayer.score); + }; + BlackJackGame.prototype.showCards = function () { + UI.display("Your Cards"); + var yourCards = this.currentPlayer.hand.cards[0].toString() + ' '; + for (var i = 1; i < this.currentPlayer.hand.cards.length; i++) { + yourCards += "| " + this.currentPlayer.hand.cards[i]; + } + UI.display(yourCards); + this.score(); + UI.display(''); + UI.display("Dealer Cards"); + var dealerCards = "UNKNOWN "; + for (var i = 1; i < this.dealer.hand.cards.length; i++) { + dealerCards += "| " + this.dealer.hand.cards[i]; + } + UI.display(dealerCards); }; return BlackJackGame; }(CardGame)); diff --git a/js/app.ts b/js/app.ts index a74e7965..d6d6085e 100644 --- a/js/app.ts +++ b/js/app.ts @@ -414,6 +414,7 @@ abstract class CardGame extends GameEngine implements GameInterface super(); this._players = new Array(); this._deck = new Deck(); + this._deck.shuffle(); } @@ -457,12 +458,13 @@ abstract class CardGame extends GameEngine implements GameInterface class BlackJackGame extends CardGame { currentPlayer : BlackJackPlayer; + dealer : BlackJackPlayer; constructor(playerProfile:Profile){ super(); - let dealer = new BlackJackPlayer(new Profile('Dealer',0)); + this.dealer = new BlackJackPlayer(new Profile('Dealer',0)); this.currentPlayer = new BlackJackPlayer(playerProfile); - this.addPlayer(dealer); + this.addPlayer(this.dealer); this.addPlayer(this.currentPlayer); this.startRound = this.startRound.bind(this); this.placeBet = this.placeBet.bind(this); @@ -506,15 +508,47 @@ class BlackJackGame extends CardGame { private initialDeal():void{ UI.clearScreen(); + this.currentPlayer.takeCard(this.deck.deal()); + this.dealer.takeCard(this.deck.deal()); + this.currentPlayer.takeCard(this.deck.deal()); + this.dealer.takeCard(this.deck.deal()); + this.header(); + this.showCards(); + } private header():void{ UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $"+ this.currentPlayer.escrow.escrowBalance); + UI.display(""); + } + + private score():void{ + this.currentPlayer.calculateScore(); + UI.display("Current Score: " + this.currentPlayer.score) + } + + private showCards():void{ + UI.display("Your Cards"); + let yourCards : string = this.currentPlayer.hand.cards[0].toString() + ' '; + for(let i = 1; i Date: Sun, 25 Mar 2018 21:03:51 -0400 Subject: [PATCH 11/16] closing in on an mvp --- js/app.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++++-- js/app.ts | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 247 insertions(+), 11 deletions(-) diff --git a/js/app.js b/js/app.js index d75f738a..a76c6c49 100644 --- a/js/app.js +++ b/js/app.js @@ -134,7 +134,7 @@ var BlackJackPlayer = /** @class */ (function (_super) { this.escrow.addToEscrowBalance(amount); this.getProfile().balance -= amount; }; - BlackJackPlayer.prototype.win = function (amount, multiplier) { + BlackJackPlayer.prototype.win = function (multiplier) { var winnings = this.escrow.escrowBalance + (this.escrow.escrowBalance * multiplier); this.getProfile().addToBalance(winnings); this.escrow.escrowBalance = 0; @@ -423,17 +423,58 @@ var BlackJackGame = /** @class */ (function (_super) { _this.startRound = _this.startRound.bind(_this); _this.placeBet = _this.placeBet.bind(_this); _this.run = _this.run.bind(_this); + _this.initialDeal = _this.initialDeal.bind(_this); + _this.restart = _this.restart.bind(_this); + _this.naturalCheck = _this.naturalCheck.bind(_this); + _this.nextMove = _this.nextMove.bind(_this); + _this.hitOrStand = _this.hitOrStand.bind(_this); return _this; } BlackJackGame.prototype.run = function () { this.startRound(); }; - BlackJackGame.prototype.evaluateTurn = function (player) { + BlackJackGame.prototype.evaluateTurn = function () { + UI.clearScreen(); + this.tallyScores(); + this.dealerTurn(); + this.header(); + this.showCards(); + if (!this.isWinner()) { + this.nextMove(false); + } + }; + BlackJackGame.prototype.isWinner = function () { + if (this.currentPlayer.isBusted() && this.dealer.isBusted()) { + UI.display("You and the Dealer are both Bust"); + UI.display("You break even"); + this.currentPlayer.win(0); + this.restart(); + return true; + } + else if (this.currentPlayer.isBusted()) { + UI.display("You went Bust"); + UI.display("You lose your bet"); + this.currentPlayer.lose(); + this.restart(); + return true; + } + else if (this.dealer.isBusted()) { + UI.display("The Dealer went Bust!"); + UI.display("Your bet pays even money!"); + this.currentPlayer.win(1); + this.restart(); + return true; + } + else if (this.currentPlayer.stand && this.dealer.stand) { + } }; BlackJackGame.prototype.startRound = function (errorMessage) { + this.currentPlayer.discardAll(); + this.dealer.discardAll(); + UI.clearScreen(); this.header(); UI.display("How much would you like to bet?"); - UI.display("This minimum bet is $10"); + UI.display("The minimum bet is $10"); if (typeof errorMessage !== "undefined") UI.display(errorMessage); UI.button.addEventListener("click", this.placeBet); @@ -461,15 +502,55 @@ var BlackJackGame = /** @class */ (function (_super) { this.dealer.takeCard(this.deck.deal()); this.currentPlayer.takeCard(this.deck.deal()); this.dealer.takeCard(this.deck.deal()); + this.tallyScores(); this.header(); this.showCards(); + var natural = this.naturalCheck(); + if (!natural) { + this.nextMove(false); + } + }; + BlackJackGame.prototype.dealerTurn = function () { + if (this.dealer.score < 17) { + this.dealer.takeCard(this.deck.deal()); + } + else { + this.dealer.stand = true; + } + }; + BlackJackGame.prototype.nextMove = function (secondTime) { + if (secondTime === true) { + UI.clearScreen(); + this.header(); + this.showCards(); + UI.display("Invalid input detected"); + UI.display("Would you like to [hit] or [stand]?"); + UI.button.addEventListener("click", this.hitOrStand); + } + else { + UI.display("Would you like to [hit] or [stand]?"); + UI.button.addEventListener("click", this.hitOrStand); + } + }; + BlackJackGame.prototype.hitOrStand = function () { + UI.button.removeEventListener("click", this.hitOrStand); + if (UI.lastInput === 'hit') { + this.currentPlayer.takeCard(this.deck.deal()); + this.evaluateTurn(); + } + else if (UI.lastInput === 'stand') { + this.currentPlayer.stand = true; + this.evaluateTurn(); + } + else { + this.nextMove(true); + } }; BlackJackGame.prototype.header = function () { UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $" + this.currentPlayer.escrow.escrowBalance); UI.display(""); }; BlackJackGame.prototype.score = function () { - this.currentPlayer.calculateScore(); UI.display("Current Score: " + this.currentPlayer.score); }; BlackJackGame.prototype.showCards = function () { @@ -487,6 +568,41 @@ var BlackJackGame = /** @class */ (function (_super) { dealerCards += "| " + this.dealer.hand.cards[i]; } UI.display(dealerCards); + UI.display(''); + }; + BlackJackGame.prototype.tallyScores = function () { + this.dealer.calculateScore(); + this.currentPlayer.calculateScore(); + }; + BlackJackGame.prototype.naturalCheck = function () { + if (this.currentPlayer.score === 21 && this.dealer.score === 21) { + UI.display("Improbably, both you and the Dealer got natural Black Jack"); + UI.display("You break even"); + this.currentPlayer.win(0); + this.restart(); + return true; + } + else if (this.currentPlayer.score === 21) { + UI.display("You got a natural Black Jack!"); + UI.display("Your bet pays 3:2!"); + this.currentPlayer.win(1.5); + this.restart(); + return true; + } + else if (this.dealer.score === 21) { + UI.display("The Dealer got a natural Black Jack"); + UI.display("You lose your bet"); + this.currentPlayer.lose(); + this.restart(); + return true; + } + else { + return false; + } + }; + BlackJackGame.prototype.restart = function () { + UI.display("Press [submit] to play again"); + UI.button.addEventListener("click", this.run, { once: true }); }; return BlackJackGame; }(CardGame)); diff --git a/js/app.ts b/js/app.ts index d6d6085e..3e2a1ca6 100644 --- a/js/app.ts +++ b/js/app.ts @@ -149,7 +149,7 @@ class BlackJackPlayer extends CardPlayer implements Gamble { this.escrow.addToEscrowBalance(amount); this.getProfile().balance -= amount; } - win(amount: number, multiplier: number): void { + win(multiplier: number): void { let winnings:number = this.escrow.escrowBalance + (this.escrow.escrowBalance * multiplier); this.getProfile().addToBalance(winnings); this.escrow.escrowBalance=0; @@ -388,7 +388,7 @@ abstract class GameEngine implements GameEngineInterface Date: Sun, 25 Mar 2018 21:41:49 -0400 Subject: [PATCH 12/16] blackjack functional. fleshing out main menu --- js/app.js | 82 +++++++++++++++++++++++++++++++++++++++++++++---------- js/app.ts | 76 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 133 insertions(+), 25 deletions(-) diff --git a/js/app.js b/js/app.js index a76c6c49..9ad4bb12 100644 --- a/js/app.js +++ b/js/app.js @@ -437,36 +437,75 @@ var BlackJackGame = /** @class */ (function (_super) { UI.clearScreen(); this.tallyScores(); this.dealerTurn(); + this.tallyScores(); this.header(); - this.showCards(); + this.showCards(false); if (!this.isWinner()) { this.nextMove(false); } + if (this.currentPlayer.stand) { + this.evaluateTurn(); + } }; BlackJackGame.prototype.isWinner = function () { if (this.currentPlayer.isBusted() && this.dealer.isBusted()) { + this.currentPlayer.win(0); + this.endScreen(); UI.display("You and the Dealer are both Bust"); UI.display("You break even"); - this.currentPlayer.win(0); this.restart(); return true; } else if (this.currentPlayer.isBusted()) { + this.currentPlayer.lose(); + this.endScreen(); UI.display("You went Bust"); UI.display("You lose your bet"); - this.currentPlayer.lose(); this.restart(); return true; } else if (this.dealer.isBusted()) { + this.currentPlayer.win(1); + this.endScreen(); UI.display("The Dealer went Bust!"); UI.display("Your bet pays even money!"); - this.currentPlayer.win(1); this.restart(); return true; } else if (this.currentPlayer.stand && this.dealer.stand) { + if (this.currentPlayer.score === this.dealer.score) { + this.currentPlayer.win(0); + this.endScreen(); + UI.display("The Dealer has the same score as you. You push"); + UI.display("You break even"); + this.restart(); + return true; + } + else if (this.currentPlayer.score > this.dealer.score) { + this.currentPlayer.win(1); + this.endScreen(); + UI.display("You have a higher score. You win!"); + UI.display("Yor bet pays even money!"); + this.restart(); + return true; + } + else if (this.currentPlayer.score < this.dealer.score) { + this.currentPlayer.lose(); + this.endScreen(); + UI.display("The Dealer has a higher score. You lose"); + UI.display("You lose your bet"); + this.restart(); + return true; + } } + else { + return false; + } + }; + BlackJackGame.prototype.endScreen = function () { + UI.clearScreen(); + this.header(); + this.showCards(true); }; BlackJackGame.prototype.startRound = function (errorMessage) { this.currentPlayer.discardAll(); @@ -504,7 +543,7 @@ var BlackJackGame = /** @class */ (function (_super) { this.dealer.takeCard(this.deck.deal()); this.tallyScores(); this.header(); - this.showCards(); + this.showCards(false); var natural = this.naturalCheck(); if (!natural) { this.nextMove(false); @@ -522,7 +561,7 @@ var BlackJackGame = /** @class */ (function (_super) { if (secondTime === true) { UI.clearScreen(); this.header(); - this.showCards(); + this.showCards(false); UI.display("Invalid input detected"); UI.display("Would you like to [hit] or [stand]?"); UI.button.addEventListener("click", this.hitOrStand); @@ -553,7 +592,7 @@ var BlackJackGame = /** @class */ (function (_super) { BlackJackGame.prototype.score = function () { UI.display("Current Score: " + this.currentPlayer.score); }; - BlackJackGame.prototype.showCards = function () { + BlackJackGame.prototype.showCards = function (showHole) { UI.display("Your Cards"); var yourCards = this.currentPlayer.hand.cards[0].toString() + ' '; for (var i = 1; i < this.currentPlayer.hand.cards.length; i++) { @@ -563,11 +602,21 @@ var BlackJackGame = /** @class */ (function (_super) { this.score(); UI.display(''); UI.display("Dealer Cards"); - var dealerCards = "UNKNOWN "; - for (var i = 1; i < this.dealer.hand.cards.length; i++) { - dealerCards += "| " + this.dealer.hand.cards[i]; + if (showHole === false) { + var dealerCards = "UNKNOWN "; + for (var i = 1; i < this.dealer.hand.cards.length; i++) { + dealerCards += "| " + this.dealer.hand.cards[i]; + } + UI.display(dealerCards); + } + else if (showHole === true) { + var dealerCards = this.dealer.hand.cards[0].toString() + ' '; + for (var i = 1; i < this.dealer.hand.cards.length; i++) { + dealerCards += "| " + this.dealer.hand.cards[i]; + } + UI.display(dealerCards); + UI.display("Dealer Score: " + this.dealer.score); } - UI.display(dealerCards); UI.display(''); }; BlackJackGame.prototype.tallyScores = function () { @@ -576,23 +625,26 @@ var BlackJackGame = /** @class */ (function (_super) { }; BlackJackGame.prototype.naturalCheck = function () { if (this.currentPlayer.score === 21 && this.dealer.score === 21) { + this.currentPlayer.win(0); + this.endScreen(); UI.display("Improbably, both you and the Dealer got natural Black Jack"); UI.display("You break even"); - this.currentPlayer.win(0); this.restart(); return true; } else if (this.currentPlayer.score === 21) { + this.currentPlayer.win(1.5); + this.endScreen(); UI.display("You got a natural Black Jack!"); UI.display("Your bet pays 3:2!"); - this.currentPlayer.win(1.5); this.restart(); return true; } else if (this.dealer.score === 21) { + this.currentPlayer.lose(); + this.endScreen(); UI.display("The Dealer got a natural Black Jack"); UI.display("You lose your bet"); - this.currentPlayer.lose(); this.restart(); return true; } @@ -602,6 +654,8 @@ var BlackJackGame = /** @class */ (function (_super) { }; BlackJackGame.prototype.restart = function () { UI.display("Press [submit] to play again"); + this.currentPlayer.stand = false; + this.dealer.stand = false; UI.button.addEventListener("click", this.run, { once: true }); }; return BlackJackGame; diff --git a/js/app.ts b/js/app.ts index 3e2a1ca6..7bbb27c4 100644 --- a/js/app.ts +++ b/js/app.ts @@ -485,39 +485,78 @@ class BlackJackGame extends CardGame { UI.clearScreen(); this.tallyScores(); this.dealerTurn(); + this.tallyScores(); this.header(); - this.showCards(); + this.showCards(false); if(!this.isWinner()){ this.nextMove(false); } + if(this.currentPlayer.stand){ + this.evaluateTurn(); + } } private isWinner():boolean{ if(this.currentPlayer.isBusted() && this.dealer.isBusted()){ + this.currentPlayer.win(0); + this.endScreen(); UI.display("You and the Dealer are both Bust"); UI.display("You break even"); - this.currentPlayer.win(0); this.restart(); return true; } else if (this.currentPlayer.isBusted()){ + this.currentPlayer.lose(); + this.endScreen(); UI.display("You went Bust"); UI.display("You lose your bet"); - this.currentPlayer.lose(); this.restart(); return true; } else if (this.dealer.isBusted()){ + this.currentPlayer.win(1); + this.endScreen(); UI.display("The Dealer went Bust!"); UI.display("Your bet pays even money!"); - this.currentPlayer.win(1); this.restart(); return true; } else if (this.currentPlayer.stand && this.dealer.stand){ - + if(this.currentPlayer.score === this.dealer.score){ + this.currentPlayer.win(0); + this.endScreen(); + UI.display("The Dealer has the same score as you. You push"); + UI.display("You break even"); + this.restart(); + return true; + } + else if (this.currentPlayer.score > this.dealer.score){ + this.currentPlayer.win(1); + this.endScreen(); + UI.display("You have a higher score. You win!"); + UI.display("Yor bet pays even money!"); + this.restart(); + return true; + } + else if (this.currentPlayer.score < this.dealer.score){ + this.currentPlayer.lose(); + this.endScreen(); + UI.display("The Dealer has a higher score. You lose"); + UI.display("You lose your bet"); + this.restart(); + return true; + } } + else{ + return false; + } + } + + private endScreen():void{ + UI.clearScreen(); + this.header(); + this.showCards(true); } private startRound(errorMessage?:string):void{ @@ -557,7 +596,7 @@ class BlackJackGame extends CardGame { this.dealer.takeCard(this.deck.deal()); this.tallyScores(); this.header(); - this.showCards(); + this.showCards(false); let natural:boolean = this.naturalCheck(); if(!natural){ this.nextMove(false); @@ -580,7 +619,7 @@ class BlackJackGame extends CardGame { if (secondTime === true){ UI.clearScreen(); this.header(); - this.showCards(); + this.showCards(false); UI.display("Invalid input detected"); UI.display("Would you like to [hit] or [stand]?"); UI.button.addEventListener("click",this.hitOrStand); @@ -615,7 +654,7 @@ class BlackJackGame extends CardGame { UI.display("Current Score: " + this.currentPlayer.score) } - private showCards():void{ + private showCards(showHole: boolean):void{ UI.display("Your Cards"); let yourCards : string = this.currentPlayer.hand.cards[0].toString() + ' '; for(let i = 1; i Date: Sun, 25 Mar 2018 22:32:21 -0400 Subject: [PATCH 13/16] mvp achieved --- js/app.js | 77 +++++++++-- js/app.ts | 399 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 302 insertions(+), 174 deletions(-) diff --git a/js/app.js b/js/app.js index 9ad4bb12..2e0b04df 100644 --- a/js/app.js +++ b/js/app.js @@ -28,7 +28,7 @@ var Startup = /** @class */ (function () { // for (var i = 0; i <= 51; i++) { // UI.display(deck.deal()); // } - var profile = new Profile('Eric', 10000); + // var profile = new Profile('Eric', 10000); // var player = new BlackJackPlayer(profile); // var ace = new Card(Rank.ACE, Suit.SPADES); // var king = new Card(Rank.KING, Suit.SPADES); @@ -42,8 +42,10 @@ var Startup = /** @class */ (function () { // player.calculateScore(); // UI.display(player.hand.cards); // UI.display(player.score); - var test = new BlackJackGame(profile); - test.run(); + // var test = new BlackJackGame(profile); + // test.run(); + var casino = new Casino(); + casino.start(); }; return Startup; }()); @@ -430,6 +432,13 @@ var BlackJackGame = /** @class */ (function (_super) { _this.hitOrStand = _this.hitOrStand.bind(_this); return _this; } + BlackJackGame.prototype.start = function () { + UI.clearScreen(); + this.header(); + UI.display("Welcome to Black Jack"); + UI.display("Press [submit] to begin"); + UI.button.addEventListener("click", this.run, { once: true }); + }; BlackJackGame.prototype.run = function () { this.startRound(); }; @@ -662,21 +671,73 @@ var BlackJackGame = /** @class */ (function (_super) { }(CardGame)); var Casino = /** @class */ (function () { function Casino() { + this.profiles = new Array(); this.chooseGame = this.chooseGame.bind(this); + this.stepTwo = this.stepTwo.bind(this); + this.mainMenu = this.mainMenu.bind(this); + this.register = this.register.bind(this); + this.start = this.start.bind(this); + this.stepOne = this.stepOne.bind(this); } Casino.prototype.start = function () { - UI.display("What game do you want to play?"); - UI.display("Black Jack or Go Fish?"); + UI.display("Welcome to Casino Royale With Cheese!"); + UI.display("Let's start by registering your profile"); + UI.display("What is your name?"); + UI.button.addEventListener("click", this.stepOne, { once: true }); + }; + Casino.prototype.stepOne = function () { + this.name = UI.lastInput; + this.stepTwo(); + }; + Casino.prototype.stepTwo = function (errorMessage) { + //UI.button.removeEventListener("click", this.stepOne); + UI.clearScreen(); + UI.display("Nice to meet you " + this.name); + UI.display("How much money would you like to change into chips?"); + UI.display("The minimum desposit is $1000"); + if (typeof errorMessage !== "undefined") + UI.display(errorMessage); + UI.button.addEventListener("click", this.register); + }; + Casino.prototype.register = function () { + UI.button.removeEventListener("click", this.register); + if (parseInt(UI.lastInput) > 1000) { + this.amount = parseInt(UI.lastInput); + this.currentPlayer = new Profile(this.name, this.amount); + this.profiles.push(this.currentPlayer); + this.mainMenu(); + } + else if (parseInt(UI.lastInput) < 1000) { + // UI.button.addEventListener("Click", this.register); + this.stepTwo("You must change at least $1000 into chips to play in our casino"); + } + else { + //UI.button.addEventListener("Click", this.register); + this.stepTwo("You must enter a number for your deposit"); + } + }; + Casino.prototype.mainMenu = function (errorMessage) { + UI.clearScreen(); + this.header(); + UI.display("What game would you like to play?"); + UI.display("[Black Jack]"); + UI.display(''); + if (typeof errorMessage !== "undefined") + UI.display(errorMessage); UI.button.addEventListener("click", this.chooseGame); }; + Casino.prototype.header = function () { + UI.display("Current Player: " + this.currentPlayer.name + "\t|\tCurrent Balance: $" + this.currentPlayer.balance); + UI.display(""); + }; Casino.prototype.chooseGame = function () { UI.button.removeEventListener("click", this.chooseGame); if (UI.lastInput === "Black Jack") { - } - else if (UI.lastInput === "Go Fish") { + var currentGame = new BlackJackGame(this.currentPlayer); + currentGame.start(); } else { - UI.button.addEventListener("click", this.chooseGame); + this.mainMenu("I'm sorry. We don't have that game yet."); } }; return Casino; diff --git a/js/app.ts b/js/app.ts index 7bbb27c4..192b3616 100644 --- a/js/app.ts +++ b/js/app.ts @@ -20,7 +20,7 @@ class Startup { // UI.display(deck.deal()); // } - var profile = new Profile('Eric',10000); + // var profile = new Profile('Eric', 10000); // var player = new BlackJackPlayer(profile); // var ace = new Card(Rank.ACE, Suit.SPADES); // var king = new Card(Rank.KING, Suit.SPADES); @@ -36,8 +36,11 @@ class Startup { // UI.display(player.hand.cards); // UI.display(player.score); - var test = new BlackJackGame(profile); - test.run(); + // var test = new BlackJackGame(profile); + // test.run(); + var casino = new Casino(); + casino.start(); + } } @@ -72,7 +75,7 @@ class Profile { this._balance = newBalance; } - public addToBalance(amount:number):void{ + public addToBalance(amount: number): void { this._balance += amount; } @@ -127,139 +130,139 @@ abstract class CardPlayer extends Player { } } - public get hand():Hand{ + public get hand(): Hand { return this._hand; } } class BlackJackPlayer extends CardPlayer implements Gamble { - - escrow:Escrow; - private _busted:boolean; - private _stand:boolean; - private _score:number; - - constructor(profile:Profile){ + + escrow: Escrow; + private _busted: boolean; + private _stand: boolean; + private _score: number; + + constructor(profile: Profile) { super(profile); this.escrow = new Escrow(); } - + bet(amount: number): void { this.escrow.addToEscrowBalance(amount); this.getProfile().balance -= amount; } win(multiplier: number): void { - let winnings:number = this.escrow.escrowBalance + (this.escrow.escrowBalance * multiplier); + let winnings: number = this.escrow.escrowBalance + (this.escrow.escrowBalance * multiplier); this.getProfile().addToBalance(winnings); - this.escrow.escrowBalance=0; + this.escrow.escrowBalance = 0; } lose(): void { - this.escrow.escrowBalance=0; + this.escrow.escrowBalance = 0; } - public get busted():boolean{ + public get busted(): boolean { return this.busted; } - public set busted(state:boolean){ - this._busted=state; + public set busted(state: boolean) { + this._busted = state; } - public get stand():boolean{ + public get stand(): boolean { return this._stand; } - public set stand(state:boolean){ - this._stand=state; + public set stand(state: boolean) { + this._stand = state; } - public get score():number{ + public get score(): number { return this._score; } - public set score(amount:number){ - this._score=amount; + public set score(amount: number) { + this._score = amount; } - public isBusted():boolean{ - if(this._score>21){ + public isBusted(): boolean { + if (this._score > 21) { return true; } - else{ + else { return false; } } - public calculateScore():void{ - let hasAce : boolean = false; - let tempScore : number = 0; + public calculateScore(): void { + let hasAce: boolean = false; + let tempScore: number = 0; this.hand.cards.forEach(element => { - if(element.rank === Rank.TWO) tempScore += 2; - else if (element.rank === Rank.THREE) tempScore +=3; - else if (element.rank === Rank.FOUR) tempScore +=4; - else if (element.rank === Rank.FIVE) tempScore +=5; - else if (element.rank === Rank.SIX) tempScore +=6; - else if (element.rank === Rank.SEVEN) tempScore +=7; - else if (element.rank === Rank.EIGHT) tempScore +=8; - else if (element.rank === Rank.NINE) tempScore +=9; - else if (element.rank === Rank.TEN) tempScore +=10; - else if (element.rank === Rank.JACK) tempScore +=10; - else if (element.rank === Rank.QUEEN) tempScore +=10; - else if (element.rank === Rank.KING) tempScore +=10; + if (element.rank === Rank.TWO) tempScore += 2; + else if (element.rank === Rank.THREE) tempScore += 3; + else if (element.rank === Rank.FOUR) tempScore += 4; + else if (element.rank === Rank.FIVE) tempScore += 5; + else if (element.rank === Rank.SIX) tempScore += 6; + else if (element.rank === Rank.SEVEN) tempScore += 7; + else if (element.rank === Rank.EIGHT) tempScore += 8; + else if (element.rank === Rank.NINE) tempScore += 9; + else if (element.rank === Rank.TEN) tempScore += 10; + else if (element.rank === Rank.JACK) tempScore += 10; + else if (element.rank === Rank.QUEEN) tempScore += 10; + else if (element.rank === Rank.KING) tempScore += 10; else if (element.rank === Rank.ACE) { - tempScore +=11; + tempScore += 11; hasAce = true; } }); - if(tempScore >21 && hasAce){ + if (tempScore > 21 && hasAce) { tempScore = 0; this.hand.cards.forEach(element => { - if(element.rank === Rank.TWO) tempScore += 2; - else if (element.rank === Rank.THREE) tempScore +=3; - else if (element.rank === Rank.FOUR) tempScore +=4; - else if (element.rank === Rank.FIVE) tempScore +=5; - else if (element.rank === Rank.SIX) tempScore +=6; - else if (element.rank === Rank.SEVEN) tempScore +=7; - else if (element.rank === Rank.EIGHT) tempScore +=8; - else if (element.rank === Rank.NINE) tempScore +=9; - else if (element.rank === Rank.TEN) tempScore +=10; - else if (element.rank === Rank.JACK) tempScore +=10; - else if (element.rank === Rank.QUEEN) tempScore +=10; - else if (element.rank === Rank.KING) tempScore +=10; + if (element.rank === Rank.TWO) tempScore += 2; + else if (element.rank === Rank.THREE) tempScore += 3; + else if (element.rank === Rank.FOUR) tempScore += 4; + else if (element.rank === Rank.FIVE) tempScore += 5; + else if (element.rank === Rank.SIX) tempScore += 6; + else if (element.rank === Rank.SEVEN) tempScore += 7; + else if (element.rank === Rank.EIGHT) tempScore += 8; + else if (element.rank === Rank.NINE) tempScore += 9; + else if (element.rank === Rank.TEN) tempScore += 10; + else if (element.rank === Rank.JACK) tempScore += 10; + else if (element.rank === Rank.QUEEN) tempScore += 10; + else if (element.rank === Rank.KING) tempScore += 10; else if (element.rank === Rank.ACE) { - tempScore +=1; + tempScore += 1; } }); } - this._score=tempScore; + this._score = tempScore; } } -class Escrow{ +class Escrow { - private _escrowBalance:number; - - constructor(){ + private _escrowBalance: number; + + constructor() { this._escrowBalance = 0; } - public get escrowBalance():number{ + public get escrowBalance(): number { return this._escrowBalance; } - public set escrowBalance(amount:number){ - this._escrowBalance=amount; + public set escrowBalance(amount: number) { + this._escrowBalance = amount; } - public addToEscrowBalance(amount:number){ - this._escrowBalance; + public addToEscrowBalance(amount: number) { + this._escrowBalance; amount; this.escrowBalance = this.escrowBalance + amount; } - + } @@ -386,7 +389,7 @@ interface GameEngineInterface { abstract class GameEngine implements GameEngineInterface, PlayerInterface>{ - + abstract run(): void; abstract evaluateTurn(): void; @@ -396,7 +399,7 @@ abstract class GameEngine implements GameEngineInterface class BlackJackGame extends CardGame { - currentPlayer : BlackJackPlayer; - dealer : BlackJackPlayer; + currentPlayer: BlackJackPlayer; + dealer: BlackJackPlayer; - constructor(playerProfile:Profile){ + constructor(playerProfile: Profile) { super(); - this.dealer = new BlackJackPlayer(new Profile('Dealer',0)); + this.dealer = new BlackJackPlayer(new Profile('Dealer', 0)); this.currentPlayer = new BlackJackPlayer(playerProfile); this.addPlayer(this.dealer); this.addPlayer(this.currentPlayer); @@ -475,6 +478,14 @@ class BlackJackGame extends CardGame { this.nextMove = this.nextMove.bind(this); this.hitOrStand = this.hitOrStand.bind(this); } + + start():void{ + UI.clearScreen(); + this.header(); + UI.display("Welcome to Black Jack"); + UI.display("Press [submit] to begin"); + UI.button.addEventListener("click", this.run, { once: true }); + } run(): void { this.startRound(); @@ -488,17 +499,17 @@ class BlackJackGame extends CardGame { this.tallyScores(); this.header(); this.showCards(false); - if(!this.isWinner()){ - this.nextMove(false); + if (!this.isWinner()) { + this.nextMove(false); } - if(this.currentPlayer.stand){ + if (this.currentPlayer.stand) { this.evaluateTurn(); } } - private isWinner():boolean{ - if(this.currentPlayer.isBusted() && this.dealer.isBusted()){ + private isWinner(): boolean { + if (this.currentPlayer.isBusted() && this.dealer.isBusted()) { this.currentPlayer.win(0); this.endScreen(); UI.display("You and the Dealer are both Bust"); @@ -506,7 +517,7 @@ class BlackJackGame extends CardGame { this.restart(); return true; } - else if (this.currentPlayer.isBusted()){ + else if (this.currentPlayer.isBusted()) { this.currentPlayer.lose(); this.endScreen(); UI.display("You went Bust"); @@ -514,7 +525,7 @@ class BlackJackGame extends CardGame { this.restart(); return true; } - else if (this.dealer.isBusted()){ + else if (this.dealer.isBusted()) { this.currentPlayer.win(1); this.endScreen(); UI.display("The Dealer went Bust!"); @@ -522,8 +533,8 @@ class BlackJackGame extends CardGame { this.restart(); return true; } - else if (this.currentPlayer.stand && this.dealer.stand){ - if(this.currentPlayer.score === this.dealer.score){ + else if (this.currentPlayer.stand && this.dealer.stand) { + if (this.currentPlayer.score === this.dealer.score) { this.currentPlayer.win(0); this.endScreen(); UI.display("The Dealer has the same score as you. You push"); @@ -531,7 +542,7 @@ class BlackJackGame extends CardGame { this.restart(); return true; } - else if (this.currentPlayer.score > this.dealer.score){ + else if (this.currentPlayer.score > this.dealer.score) { this.currentPlayer.win(1); this.endScreen(); UI.display("You have a higher score. You win!"); @@ -539,7 +550,7 @@ class BlackJackGame extends CardGame { this.restart(); return true; } - else if (this.currentPlayer.score < this.dealer.score){ + else if (this.currentPlayer.score < this.dealer.score) { this.currentPlayer.lose(); this.endScreen(); UI.display("The Dealer has a higher score. You lose"); @@ -548,47 +559,47 @@ class BlackJackGame extends CardGame { return true; } } - else{ + else { return false; } } - private endScreen():void{ + private endScreen(): void { UI.clearScreen(); this.header(); this.showCards(true); } - private startRound(errorMessage?:string):void{ + private startRound(errorMessage?: string): void { this.currentPlayer.discardAll(); this.dealer.discardAll(); UI.clearScreen(); this.header(); UI.display("How much would you like to bet?"); UI.display("The minimum bet is $10"); - if(typeof errorMessage !== "undefined") UI.display(errorMessage); + if (typeof errorMessage !== "undefined") UI.display(errorMessage); UI.button.addEventListener("click", this.placeBet); } - private placeBet():void{ + private placeBet(): void { UI.button.removeEventListener("click", this.placeBet); UI.clearScreen(); - if(UI.lastInput <= this.currentPlayer.getProfile().balance && UI.lastInput >10){ - this.currentPlayer.bet(parseInt(UI.lastInput)); - this.initialDeal(); + if (UI.lastInput <= this.currentPlayer.getProfile().balance && UI.lastInput > 10) { + this.currentPlayer.bet(parseInt(UI.lastInput)); + this.initialDeal(); } - else if (UI.lastInput <10){ + else if (UI.lastInput < 10) { this.startRound("That amount is below the minimum bet"); } - else if (UI.lastInput > this.currentPlayer.getProfile().balance){ + else if (UI.lastInput > this.currentPlayer.getProfile().balance) { this.startRound("You cannot bet more money than you have"); } - else{ + else { this.startRound("You must input a number to place a bet"); } } - private initialDeal():void{ + private initialDeal(): void { UI.clearScreen(); this.currentPlayer.takeCard(this.deck.deal()); this.dealer.takeCard(this.deck.deal()); @@ -597,98 +608,98 @@ class BlackJackGame extends CardGame { this.tallyScores(); this.header(); this.showCards(false); - let natural:boolean = this.naturalCheck(); - if(!natural){ + let natural: boolean = this.naturalCheck(); + if (!natural) { this.nextMove(false); } - - + + } - private dealerTurn():void{ - if(this.dealer.score<17){ + private dealerTurn(): void { + if (this.dealer.score < 17) { this.dealer.takeCard(this.deck.deal()); } - else{ - this.dealer.stand=true; + else { + this.dealer.stand = true; } } - private nextMove(secondTime:boolean){ - if (secondTime === true){ - UI.clearScreen(); - this.header(); - this.showCards(false); - UI.display("Invalid input detected"); - UI.display("Would you like to [hit] or [stand]?"); - UI.button.addEventListener("click",this.hitOrStand); - } - else{ - UI.display("Would you like to [hit] or [stand]?"); - UI.button.addEventListener("click",this.hitOrStand); - } + private nextMove(secondTime: boolean) { + if (secondTime === true) { + UI.clearScreen(); + this.header(); + this.showCards(false); + UI.display("Invalid input detected"); + UI.display("Would you like to [hit] or [stand]?"); + UI.button.addEventListener("click", this.hitOrStand); + } + else { + UI.display("Would you like to [hit] or [stand]?"); + UI.button.addEventListener("click", this.hitOrStand); + } } - private hitOrStand():void{ - UI.button.removeEventListener("click",this.hitOrStand); - if(UI.lastInput === 'hit'){ + private hitOrStand(): void { + UI.button.removeEventListener("click", this.hitOrStand); + if (UI.lastInput === 'hit') { this.currentPlayer.takeCard(this.deck.deal()); this.evaluateTurn(); } - else if (UI.lastInput === 'stand'){ - this.currentPlayer.stand=true; + else if (UI.lastInput === 'stand') { + this.currentPlayer.stand = true; this.evaluateTurn(); } - else{this.nextMove(true)} + else { this.nextMove(true) } } - private header():void{ - UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $"+ this.currentPlayer.escrow.escrowBalance); + private header(): void { + UI.display("Current Player: " + this.currentPlayer.getProfile().name + "\t|\tCurrent Balance: $" + this.currentPlayer.getProfile().balance + "\t|\t Amount Wagered: $" + this.currentPlayer.escrow.escrowBalance); UI.display(""); } - private score():void{ + private score(): void { UI.display("Current Score: " + this.currentPlayer.score) } - private showCards(showHole: boolean):void{ + private showCards(showHole: boolean): void { UI.display("Your Cards"); - let yourCards : string = this.currentPlayer.hand.cards[0].toString() + ' '; - for(let i = 1; i (); this.chooseGame = this.chooseGame.bind(this); + this.stepTwo = this.stepTwo.bind(this); + this.mainMenu = this.mainMenu.bind(this); + this.register = this.register.bind(this); + this.start = this.start.bind(this); + this.stepOne = this.stepOne.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); + UI.display("Welcome to Casino Royale With Cheese!"); + UI.display("Let's start by registering your profile"); + UI.display("What is your name?") + UI.button.addEventListener("click", this.stepOne,{once:true}); } - chooseGame(): void { - UI.button.removeEventListener("click", this.chooseGame); - if (UI.lastInput === "Black Jack") { - + stepOne(): void { + this.name = UI.lastInput; + this.stepTwo(); + } + stepTwo(errorMessage?: string): void { + //UI.button.removeEventListener("click", this.stepOne); + UI.clearScreen(); + UI.display("Nice to meet you " + this.name); + UI.display("How much money would you like to change into chips?") + UI.display("The minimum desposit is $1000"); + if (typeof errorMessage !== "undefined") UI.display(errorMessage); + UI.button.addEventListener("click", this.register); + } + register(): void { + UI.button.removeEventListener("click", this.register); + if (parseInt(UI.lastInput) > 1000) { + this.amount = parseInt(UI.lastInput); + this.currentPlayer = new Profile(this.name, this.amount); + this.profiles.push(this.currentPlayer); + this.mainMenu(); } - else if (UI.lastInput === "Go Fish") { - - + else if (parseInt(UI.lastInput) < 1000) { + // UI.button.addEventListener("Click", this.register); + this.stepTwo("You must change at least $1000 into chips to play in our casino"); } else { - UI.button.addEventListener("click", this.chooseGame); + //UI.button.addEventListener("Click", this.register); + this.stepTwo("You must enter a number for your deposit"); } + } + mainMenu(errorMessage?: string): void { + UI.clearScreen(); + this.header(); + UI.display("What game would you like to play?") + UI.display("[Black Jack]"); + UI.display(''); + if (typeof errorMessage !== "undefined") UI.display(errorMessage); + UI.button.addEventListener("click", this.chooseGame); + + } + + private header(): void { + UI.display("Current Player: " + this.currentPlayer.name + "\t|\tCurrent Balance: $" + this.currentPlayer.balance); + UI.display(""); + } + + + chooseGame(): void { + UI.button.removeEventListener("click", this.chooseGame); + if (UI.lastInput === "Black Jack") { + var currentGame = new BlackJackGame(this.currentPlayer); + currentGame.start(); + } + else { + this.mainMenu("I'm sorry. We don't have that game yet."); + } + } } + class UI { static userInput = document.getElementById("user_input"); static window = document.getElementById('display'); From 6d76b21680e1f5df2099aad16cbfbb2cd0574ccc Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Mon, 26 Mar 2018 08:51:24 -0400 Subject: [PATCH 14/16] saving --- js/app.ts | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/js/app.ts b/js/app.ts index 192b3616..1d82c219 100644 --- a/js/app.ts +++ b/js/app.ts @@ -1,47 +1,8 @@ class Startup { public static main(): void { - // var casino = new Casino(); - // casino.start(); - - // var club = new Card(Rank.ACE, Suit.CLUBS); - // var diamond = new Card(Rank.FIVE, Suit.DIAMONDS); - // var spade = new Card(Rank.QUEEN, Suit.SPADES); - // var heart = new Card(Rank.JACK, Suit.HEARTS); - - - // UI.display(club); - // UI.display(heart); - // UI.display(spade); - // UI.display(diamond); - // var deck = new Deck(); - // deck.shuffle(); - // for (var i = 0; i <= 51; i++) { - // UI.display(deck.deal()); - // } - - // var profile = new Profile('Eric', 10000); - // var player = new BlackJackPlayer(profile); - // var ace = new Card(Rank.ACE, Suit.SPADES); - // var king = new Card(Rank.KING, Suit.SPADES); - // var seven = new Card(Rank.SEVEN, Suit.SPADES); - // var two = new Card(Rank.TWO, Suit.SPADES); - // var five = new Card(Rank.FIVE, Suit.SPADES); - - // player.takeCard(ace); - // player.takeCard(five); - // player.takeCard(seven); - // player.takeCard(ace); - // player.calculateScore(); - // UI.display(player.hand.cards); - // UI.display(player.score); - - // var test = new BlackJackGame(profile); - // test.run(); var casino = new Casino(); casino.start(); - - } } From 3e077ec6b3acfc257ba6b85602d04d7ae360caf3 Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Mon, 26 Mar 2018 09:10:16 -0400 Subject: [PATCH 15/16] cleaned up a bit --- js/app.js | 44 +++++++++++++------------------------------- js/app.ts | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/js/app.js b/js/app.js index 2e0b04df..4edea0d5 100644 --- a/js/app.js +++ b/js/app.js @@ -13,37 +13,6 @@ var Startup = /** @class */ (function () { function Startup() { } Startup.main = function () { - // var casino = new Casino(); - // casino.start(); - // var club = new Card(Rank.ACE, Suit.CLUBS); - // var diamond = new Card(Rank.FIVE, Suit.DIAMONDS); - // var spade = new Card(Rank.QUEEN, Suit.SPADES); - // var heart = new Card(Rank.JACK, Suit.HEARTS); - // UI.display(club); - // UI.display(heart); - // UI.display(spade); - // UI.display(diamond); - // var deck = new Deck(); - // deck.shuffle(); - // for (var i = 0; i <= 51; i++) { - // UI.display(deck.deal()); - // } - // var profile = new Profile('Eric', 10000); - // var player = new BlackJackPlayer(profile); - // var ace = new Card(Rank.ACE, Suit.SPADES); - // var king = new Card(Rank.KING, Suit.SPADES); - // var seven = new Card(Rank.SEVEN, Suit.SPADES); - // var two = new Card(Rank.TWO, Suit.SPADES); - // var five = new Card(Rank.FIVE, Suit.SPADES); - // player.takeCard(ace); - // player.takeCard(five); - // player.takeCard(seven); - // player.takeCard(ace); - // player.calculateScore(); - // UI.display(player.hand.cards); - // UI.display(player.score); - // var test = new BlackJackGame(profile); - // test.run(); var casino = new Casino(); casino.start(); }; @@ -351,6 +320,9 @@ var Deck = /** @class */ (function () { } } }; + Deck.prototype.getSize = function () { + return this._cards.length; + }; return Deck; }()); var Hand = /** @class */ (function () { @@ -387,6 +359,10 @@ var CardGame = /** @class */ (function (_super) { enumerable: true, configurable: true }); + CardGame.prototype.replaceDeck = function () { + this._deck = new Deck(); + this._deck.shuffle(); + }; CardGame.prototype.getPlayers = function () { return this._players; }; @@ -665,8 +641,14 @@ var BlackJackGame = /** @class */ (function (_super) { UI.display("Press [submit] to play again"); this.currentPlayer.stand = false; this.dealer.stand = false; + this.newDeck(); UI.button.addEventListener("click", this.run, { once: true }); }; + BlackJackGame.prototype.newDeck = function () { + if (this.deck.getSize() <= 20) { + this.replaceDeck(); + } + }; return BlackJackGame; }(CardGame)); var Casino = /** @class */ (function () { diff --git a/js/app.ts b/js/app.ts index 1d82c219..e809e4e3 100644 --- a/js/app.ts +++ b/js/app.ts @@ -316,6 +316,10 @@ class Deck { } } + public getSize():number{ + return this._cards.length; + } + } class Hand { @@ -386,6 +390,11 @@ abstract class CardGame extends GameEngine implements GameInterface return this._deck; } + public replaceDeck(){ + this._deck = new Deck(); + this._deck.shuffle(); + } + getPlayers(): CardPlayer[] { return this._players; @@ -450,7 +459,6 @@ class BlackJackGame extends CardGame { run(): void { this.startRound(); - } evaluateTurn(): void { @@ -691,13 +699,18 @@ class BlackJackGame extends CardGame { UI.display("Press [submit] to play again"); this.currentPlayer.stand = false; this.dealer.stand = false; + this.newDeck(); UI.button.addEventListener("click", this.run, { once: true }) } - -} + private newDeck(){ + if(this.deck.getSize()<=20){ + this.replaceDeck(); + } + } +} class Casino { @@ -786,7 +799,6 @@ class Casino { } } - class UI { static userInput = document.getElementById("user_input"); static window = document.getElementById('display'); From a905fcc424e0c549af40a4ac8c370d114b47c6ab Mon Sep 17 00:00:00 2001 From: Eric Barnaba Date: Mon, 26 Mar 2018 09:31:34 -0400 Subject: [PATCH 16/16] just messing with the html for fun --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a378524e..701a74a5 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ -

TypeScript Casino

+

Casnio Royale With Cheese