From 38b0426c8e1ace287544cd7ac2c40c025131ba69 Mon Sep 17 00:00:00 2001 From: Froilan Miranda Date: Mon, 4 Dec 2017 15:04:02 -0500 Subject: [PATCH 1/2] updated demo files --- index.html | 2 +- js/app.js | 28 ++++++++++++++++++++++++++++ js/app.js.map | 1 + ts/AliceBob.ts | 29 +++++++++++++++++++++++++++++ ts/Bootstrapper.ts | 4 ++++ ts/tsconfig.json | 7 +++++++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 js/app.js create mode 100644 js/app.js.map create mode 100644 ts/AliceBob.ts create mode 100644 ts/Bootstrapper.ts create mode 100644 ts/tsconfig.json diff --git a/index.html b/index.html index d2c3c254..d4efd531 100644 --- a/index.html +++ b/index.html @@ -22,7 +22,7 @@

TypeScript Casino

- +
diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..bffd7bca --- /dev/null +++ b/js/app.js @@ -0,0 +1,28 @@ +var AliceBob = (function () { + function AliceBob() { + this.displayEle = document.getElementById("display"); + this.userInputEle = document.getElementById("user_input"); + } + AliceBob.prototype.init = function () { + this.askForName(); + }; + AliceBob.prototype.submitName = function () { + this.displayEle.innerHTML += "
"; + if (this.userInputEle.value.toLowerCase() == "bob" || this.userInputEle.value.toLowerCase() == "alice") { + this.displayEle.innerHTML += "Greetings, " + this.userInputEle.value + "!"; + } + else { + this.displayEle.innerHTML += this.userInputEle.value + "? " + "Stranger Danger!!!"; + } + this.displayEle.innerHTML += "

"; + this.askForName(); + }; + AliceBob.prototype.askForName = function () { + this.displayEle.innerHTML += "What is your name?"; + }; + return AliceBob; +}()); +/// +var aliceBob = new AliceBob(); +aliceBob.init(); +//# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/js/app.js.map b/js/app.js.map new file mode 100644 index 00000000..391e66da --- /dev/null +++ b/js/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sourceRoot":"","sources":["../ts/AliceBob.ts","../ts/Bootstrapper.ts"],"names":[],"mappings":"AAAA;IAKC;QACC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IAC1D,CAAC;IAED,uBAAI,GAAJ;QACC,IAAI,CAAC,UAAU,EAAE,CAAC;IACnB,CAAC;IAED,6BAAU,GAAV;QACC,IAAI,CAAC,UAAU,CAAC,SAAS,IAAI,OAAO,CAAC;QACrC,EAAE,CAAA,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,CAAA,CAAC;YACtG,IAAI,CAAC,UAAU,CAAC,SAAS,IAAI,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,GAAG,GAAG,CAAE;QAC7E,CAAC;QAAA,IAAI,CAAA,CAAC;YACL,IAAI,CAAC,UAAU,CAAC,SAAS,IAAK,IAAI,CAAC,YAAY,CAAC,KAAK,GAAG,IAAI,GAAG,oBAAoB,CAAC;QACrF,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,SAAS,IAAI,YAAY,CAAC;QAC1C,IAAI,CAAC,UAAU,EAAE,CAAC;IACnB,CAAC;IAED,6BAAU,GAAV;QACC,IAAI,CAAC,UAAU,CAAC,SAAS,IAAI,oBAAoB,CAAA;IAClD,CAAC;IACF,eAAC;AAAD,CAAC,AA5BD,IA4BC;AC5BD,oCAAoC;AAEpC,IAAI,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;AAC9B,QAAQ,CAAC,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/ts/AliceBob.ts b/ts/AliceBob.ts new file mode 100644 index 00000000..7f4892ac --- /dev/null +++ b/ts/AliceBob.ts @@ -0,0 +1,29 @@ +class AliceBob{ + + displayEle:any; + userInputEle:any; + + constructor(){ + this.displayEle = document.getElementById("display"); + this.userInputEle = document.getElementById("user_input") + } + + init(){ + this.askForName(); + } + + submitName() { + this.displayEle.innerHTML += "
"; + if(this.userInputEle.value.toLowerCase() == "bob" || this.userInputEle.value.toLowerCase() == "alice"){ + this.displayEle.innerHTML += "Greetings, " + this.userInputEle.value + "!" ; + }else{ + this.displayEle.innerHTML += this.userInputEle.value + "? " + "Stranger Danger!!!"; + } + this.displayEle.innerHTML += "

"; + this.askForName(); + } + + askForName(){ + this.displayEle.innerHTML += "What is your name?" + } +} diff --git a/ts/Bootstrapper.ts b/ts/Bootstrapper.ts new file mode 100644 index 00000000..f959ce23 --- /dev/null +++ b/ts/Bootstrapper.ts @@ -0,0 +1,4 @@ +/// + +let aliceBob = new AliceBob(); +aliceBob.init(); diff --git a/ts/tsconfig.json b/ts/tsconfig.json new file mode 100644 index 00000000..1cac3f54 --- /dev/null +++ b/ts/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "sourceMap": true, + "target": "es5", + "outFile": "../js/app.js" + } +} From 1083d41cd939d8e042e1118ab95bd11098aed8d0 Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 11 Dec 2017 16:20:44 -0500 Subject: [PATCH 2/2] first commit --- .idea/Casino-TypeScript.iml | 12 ++ .idea/modules.xml | 8 + .idea/typescript-compiler.xml | 7 + .idea/vcs.xml | 6 + .idea/workspace.xml | 221 +++++++++++++++++++++ ts/AliceBob.js | 30 +++ ts/AliceBob.ts | 28 ++- ts/Bootstrapper.js | 3 + ts/casino/Casino.ts | 0 ts/casino/Profile.ts | 63 ++++++ ts/casino/cardgames/cardutils/Card.ts | 17 ++ ts/casino/cardgames/cardutils/Deck.ts | 31 +++ ts/casino/cardgames/cardutils/Rank.ts | 31 +++ ts/casino/cardgames/cardutils/Suit.ts | 22 ++ ts/casino/utils/ArrayUtils.ts | 15 ++ ts/casino/utils/webutils/Console.ts | 0 ts/casino/utils/webutils/DisplayElement.js | 25 +++ ts/casino/utils/webutils/DisplayElement.ts | 30 +++ ts/casino/utils/webutils/InputElement.js | 9 + ts/casino/utils/webutils/InputElement.ts | 11 + ts/casino/utils/webutils/PageObject.js | 6 + ts/casino/utils/webutils/PageObject.ts | 4 + ts/casino/utils/webutils/WebElement.ts | 1 + 23 files changed, 569 insertions(+), 11 deletions(-) create mode 100644 .idea/Casino-TypeScript.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/typescript-compiler.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 ts/AliceBob.js create mode 100644 ts/Bootstrapper.js create mode 100644 ts/casino/Casino.ts create mode 100644 ts/casino/Profile.ts create mode 100644 ts/casino/cardgames/cardutils/Card.ts create mode 100644 ts/casino/cardgames/cardutils/Deck.ts create mode 100644 ts/casino/cardgames/cardutils/Rank.ts create mode 100644 ts/casino/cardgames/cardutils/Suit.ts create mode 100644 ts/casino/utils/ArrayUtils.ts create mode 100644 ts/casino/utils/webutils/Console.ts create mode 100644 ts/casino/utils/webutils/DisplayElement.js create mode 100644 ts/casino/utils/webutils/DisplayElement.ts create mode 100644 ts/casino/utils/webutils/InputElement.js create mode 100644 ts/casino/utils/webutils/InputElement.ts create mode 100644 ts/casino/utils/webutils/PageObject.js create mode 100644 ts/casino/utils/webutils/PageObject.ts create mode 100644 ts/casino/utils/webutils/WebElement.ts diff --git a/.idea/Casino-TypeScript.iml b/.idea/Casino-TypeScript.iml new file mode 100644 index 00000000..24643cc3 --- /dev/null +++ b/.idea/Casino-TypeScript.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..e1fa0ee3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/typescript-compiler.xml b/.idea/typescript-compiler.xml new file mode 100644 index 00000000..17ff836a --- /dev/null +++ b/.idea/typescript-compiler.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..c4fa1dd0 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1512671917560 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ts/AliceBob.js b/ts/AliceBob.js new file mode 100644 index 00000000..8e77cce6 --- /dev/null +++ b/ts/AliceBob.js @@ -0,0 +1,30 @@ +/// +/// +/// +var AliceBob = /** @class */ (function () { + function AliceBob() { + this.displayEle = WebElement.DISPLAY; + this.userInputEle = WebElement.INPUT; + } + AliceBob.prototype.init = function () { + this.askForName(); + }; + AliceBob.prototype.submitName = function () { + var display = this.displayEle; + var userInput = this.userInputEle; + var userInputValue = userInput.getValue().toLowerCase(); + display.appendNewLine(); + if (userInputValue == "bob" || userInputValue == "alice") { + display.append("Greetings, " + userInputValue + "!"); + } + else { + display.append(userInputValue + "? Stranger Danger!!!"); + } + display.appendNewLine().appendNewLine(); + this.askForName(); + }; + AliceBob.prototype.askForName = function () { + this.displayEle.append("What is your name?"); + }; + return AliceBob; +}()); diff --git a/ts/AliceBob.ts b/ts/AliceBob.ts index 7f4892ac..d3c8083b 100644 --- a/ts/AliceBob.ts +++ b/ts/AliceBob.ts @@ -1,11 +1,14 @@ +/// +/// +/// class AliceBob{ - displayEle:any; - userInputEle:any; + displayEle:DisplayElement; + userInputEle:InputElement; constructor(){ - this.displayEle = document.getElementById("display"); - this.userInputEle = document.getElementById("user_input") + this.displayEle = PageObject.DISPLAY; + this.userInputEle = PageObject.INPUT; } init(){ @@ -13,17 +16,20 @@ class AliceBob{ } submitName() { - this.displayEle.innerHTML += "
"; - if(this.userInputEle.value.toLowerCase() == "bob" || this.userInputEle.value.toLowerCase() == "alice"){ - this.displayEle.innerHTML += "Greetings, " + this.userInputEle.value + "!" ; - }else{ - this.displayEle.innerHTML += this.userInputEle.value + "? " + "Stranger Danger!!!"; + let display = this.displayEle; + let userInput= this.userInputEle; + let userInputValue = userInput.getValue().toLowerCase(); + + display.appendNewLine(""); + if(userInputValue == "bob" || userInputValue == "alice"){ + display.append("Greetings, " + userInputValue + "!"); + } else { + display.append(userInputValue + "? Stranger Danger!!!"); } - this.displayEle.innerHTML += "

"; this.askForName(); } askForName(){ - this.displayEle.innerHTML += "What is your name?" + this.displayEle.append("What is your name?"); } } diff --git a/ts/Bootstrapper.js b/ts/Bootstrapper.js new file mode 100644 index 00000000..ff57ba79 --- /dev/null +++ b/ts/Bootstrapper.js @@ -0,0 +1,3 @@ +/// +var aliceBob = new AliceBob(); +aliceBob.init(); diff --git a/ts/casino/Casino.ts b/ts/casino/Casino.ts new file mode 100644 index 00000000..e69de29b diff --git a/ts/casino/Profile.ts b/ts/casino/Profile.ts new file mode 100644 index 00000000..35cd8bb0 --- /dev/null +++ b/ts/casino/Profile.ts @@ -0,0 +1,63 @@ +class Profile { + private profileId: number; + private name: string + private balance: number; + + public Profile(name: string, balance: number) { + this.name = name; + this.balance = balance; + this.profileId = Casino.profiles.size(); +} + +public printInformation(): void { + Console.printDashes(); + + Console.println("Printing profile details"); + Console.println("\tName:\t\t %s", getName()); + Console.println("\tBalance:\t %s", getBalance()); + Console.println("\tId:\t\t\t %s", getProfileId()); +} + +public increaseBalance(amount: number): void{ + let oldBalance = this.getBalance(); + let newBalance = oldBalance + amount; + let deltaStr = newBalance > oldBalance ? "increased" : "decreased"; + + this.setBalance(newBalance); + PageObject.DISPLAY.append("[ %s ]'s balance has %s from [ %s ] to [ %s ]", name, deltaStr, oldBalance, newBalance); +} + +public decreaseBalance(double amount): void{ + increaseBalance(amount * -1); +} + +public Double createBetAmount() { + Console.printDashes(); + double playerBalance = getBalance(); + double playerBet = Console.getLongInput("How much money would you like to bet this game, [ %s ] ?", getName()); + if (playerBet <= playerBalance) { + return playerBet; + } else { + Console.println("You cannot bet more money than what is credited to your player-profile."); + Console.println("Try inputting a valid less than [ %s ]", playerBalance); + printInformation(); + return createBetAmount(); + } +} + +public double getBalance() { + return this.balance; +} + +public String getName() { + return this.name; +} + +public Long getProfileId() { + return this.profileId; +} + +private void setBalance(double balance) { + this.balance = balance; +} +} diff --git a/ts/casino/cardgames/cardutils/Card.ts b/ts/casino/cardgames/cardutils/Card.ts new file mode 100644 index 00000000..9bb5b446 --- /dev/null +++ b/ts/casino/cardgames/cardutils/Card.ts @@ -0,0 +1,17 @@ +class Card { + private suit: Suit; + private rank: Rank; + + constructor(suit: Suit, rank: Rank) { + this.suit = suit; + this.rank = rank; + } + + public getSuit(): Suit { + return this.suit; + } + + public getRank(): Rank { + return this.rank; + } +} \ No newline at end of file diff --git a/ts/casino/cardgames/cardutils/Deck.ts b/ts/casino/cardgames/cardutils/Deck.ts new file mode 100644 index 00000000..94a46998 --- /dev/null +++ b/ts/casino/cardgames/cardutils/Deck.ts @@ -0,0 +1,31 @@ +class Deck { + private cards: Card[] = []; + + constructor() { + for(let rank of Rank.getValues()) { + for(let suit of Suit.getValues()) { + this.push(new Card(suit, rank)); + } + } + } + + public isEmpty(): boolean { + return this.cards.length == 0; + } + + public push(card: Card) { + this.cards.push(card); + } + + public pop(): Card { + return this.cards.pop(); + } + + public peek(): Card { + return this.cards[0]; + } + + public shuffle() { + ArrayUtils.shuffle(this.cards); + } +} \ No newline at end of file diff --git a/ts/casino/cardgames/cardutils/Rank.ts b/ts/casino/cardgames/cardutils/Rank.ts new file mode 100644 index 00000000..ee153242 --- /dev/null +++ b/ts/casino/cardgames/cardutils/Rank.ts @@ -0,0 +1,31 @@ +class Rank { + private static values: Rank[] = []; + public static LOW_ACE: Rank = new Rank(1); + public static TWO: Rank = new Rank(2); + public static THREE: Rank = new Rank(3); + public static FOUR: Rank = new Rank(4); + public static FIVE: Rank = new Rank(5); + public static SIX: Rank = new Rank(6); + public static SEVEN: Rank = new Rank(7); + public static EIGHT: Rank = new Rank(8); + public static NINE: Rank = new Rank(9); + public static TEN: Rank = new Rank(10); + public static JACK: Rank = new Rank(10); + public static QUEEN: Rank = new Rank(10); + public static KING: Rank = new Rank(10); + + private value: number; + + constructor(value: number) { + this.value = value; + Rank.values.push(this); + } + + public getValue(): number { + return this.value; + } + + public static getValues(): Rank[] { + return Rank.values; + } +} \ No newline at end of file diff --git a/ts/casino/cardgames/cardutils/Suit.ts b/ts/casino/cardgames/cardutils/Suit.ts new file mode 100644 index 00000000..75808cac --- /dev/null +++ b/ts/casino/cardgames/cardutils/Suit.ts @@ -0,0 +1,22 @@ +class Suit { + private static values: Suit[] = []; + public static HEARTS: Suit = new Suit("♥"); + public static DIAMONDS: Suit = new Suit("♦"); + public static CLUBS: Suit = new Suit("♣"); + public static SPADES: Suit = new Suit("♠"); + + private value: string; + + constructor(value: string) { + this.value = value; + Suit.values.push(this); + } + + public getValue(): string { + return this.value; + } + + public static getValues(): Suit[] { + return Suit.values; + } +} \ No newline at end of file diff --git a/ts/casino/utils/ArrayUtils.ts b/ts/casino/utils/ArrayUtils.ts new file mode 100644 index 00000000..ef3854e6 --- /dev/null +++ b/ts/casino/utils/ArrayUtils.ts @@ -0,0 +1,15 @@ +class ArrayUtils { + /** + * Shuffles array in place. + * @param {Array} a items An array containing the items. + */ + public static shuffle(a) { + var j, x, i; + for (i = a.length - 1; i > 0; i--) { + j = Math.floor(Math.random() * (i + 1)); + x = a[i]; + a[i] = a[j]; + a[j] = x; + } + } +} \ No newline at end of file diff --git a/ts/casino/utils/webutils/Console.ts b/ts/casino/utils/webutils/Console.ts new file mode 100644 index 00000000..e69de29b diff --git a/ts/casino/utils/webutils/DisplayElement.js b/ts/casino/utils/webutils/DisplayElement.js new file mode 100644 index 00000000..ffa5f3e6 --- /dev/null +++ b/ts/casino/utils/webutils/DisplayElement.js @@ -0,0 +1,25 @@ +var DisplayElement = /** @class */ (function () { + function DisplayElement() { + this.displayEle = document.getElementById("display"); + } + DisplayElement.prototype.append = function (val) { + this.setInnerHtml(this.getInnerHtml() + val); + return this; + }; + DisplayElement.prototype.appendNewLine = function (val) { + return this.append("
" + val); + }; + DisplayElement.prototype.appendNewLine = function () { + return this.appendNewLine(""); + }; + DisplayElement.prototype.clear = function () { + this.setInnerHtml(""); + }; + DisplayElement.prototype.getInnerHtml = function () { + return this.displayEle.innerHTML; + }; + DisplayElement.prototype.setInnerHtml = function (val) { + this.displayEle.innerHTML = val; + }; + return DisplayElement; +}()); diff --git a/ts/casino/utils/webutils/DisplayElement.ts b/ts/casino/utils/webutils/DisplayElement.ts new file mode 100644 index 00000000..a6e3707c --- /dev/null +++ b/ts/casino/utils/webutils/DisplayElement.ts @@ -0,0 +1,30 @@ +class DisplayElement implements WebElement { + displayEle:any; + + constructor(){ + this.displayEle = document.getElementById("display"); + } + + public append(val :string): DisplayElement { + this.setInnerHtml(this.getInnerHtml() + val) + return this; + } + + + public appendNewLine(val: string): DisplayElement { + return this.append("
" + val); + } + + public clear() { + this.setInnerHtml(""); + } + + public getInnerHtml(): any { + return this.displayEle.innerHTML; + } + + private setInnerHtml(val: string) { + this.displayEle.innerHTML = val; + } + +} diff --git a/ts/casino/utils/webutils/InputElement.js b/ts/casino/utils/webutils/InputElement.js new file mode 100644 index 00000000..59f0da12 --- /dev/null +++ b/ts/casino/utils/webutils/InputElement.js @@ -0,0 +1,9 @@ +var InputElement = /** @class */ (function () { + function InputElement() { + this.inputEle = document.getElementById("user_input"); + } + InputElement.prototype.getValue = function () { + return this.inputEle.value; + }; + return InputElement; +}()); diff --git a/ts/casino/utils/webutils/InputElement.ts b/ts/casino/utils/webutils/InputElement.ts new file mode 100644 index 00000000..f4c9cb52 --- /dev/null +++ b/ts/casino/utils/webutils/InputElement.ts @@ -0,0 +1,11 @@ +class InputElement implements WebElement { + inputEle:any; + + constructor(){ + this.inputEle = document.getElementById("user_input"); + } + + public getValue(): string { + return this.inputEle.value + } +} \ No newline at end of file diff --git a/ts/casino/utils/webutils/PageObject.js b/ts/casino/utils/webutils/PageObject.js new file mode 100644 index 00000000..f10fbd7a --- /dev/null +++ b/ts/casino/utils/webutils/PageObject.js @@ -0,0 +1,6 @@ +var WebElement; +(function (WebElement) { + WebElement[WebElement["DISPLAY"] = new DisplayElement()] = "DISPLAY"; + WebElement[WebElement["INPUT"] = new InputElement()] = "INPUT"; +})(WebElement || (WebElement = {})); +; diff --git a/ts/casino/utils/webutils/PageObject.ts b/ts/casino/utils/webutils/PageObject.ts new file mode 100644 index 00000000..d45b3ec0 --- /dev/null +++ b/ts/casino/utils/webutils/PageObject.ts @@ -0,0 +1,4 @@ +class PageObject { + public static DISPLAY: DisplayElement = new DisplayElement(); + public static INPUT: InputElement = new InputElement(); +}; \ No newline at end of file diff --git a/ts/casino/utils/webutils/WebElement.ts b/ts/casino/utils/webutils/WebElement.ts new file mode 100644 index 00000000..530a9762 --- /dev/null +++ b/ts/casino/utils/webutils/WebElement.ts @@ -0,0 +1 @@ +interface WebElement {} \ No newline at end of file