diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7a73a41b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/index.html b/index.html index d2c3c254..dbb169cf 100644 --- a/index.html +++ b/index.html @@ -20,12 +20,14 @@

TypeScript Casino

-
- - -
+
+ + +
- + + + diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..69e3f1ce --- /dev/null +++ b/js/app.js @@ -0,0 +1,102 @@ +var UserInterface = (function () { + function UserInterface() { + var _this = this; + this.userInput = document.getElementById('user_input'); + this.window = document.getElementById('display'); + this.button = document.getElementById('submit'); + this.button.addEventListener("click", function (e) { _this._lastInput = _this.userInput.value; }); + this.button.addEventListener("click", function (e) { return console.log(_this._lastInput); }); + this.button.addEventListener("click", function (e) { _this.userInput.value = ''; }); + } + UserInterface.prototype.display = function (input) { + this.window.innerText += input + '\n'; + }; + UserInterface.prototype.clearScreen = function () { + this.window.innerText = ''; + }; + UserInterface.prototype.lastInput = function () { + return this._lastInput; + }; + UserInterface.prototype.start = function () { + var _this = this; + this.display("Do you want to play Blackjack? (y/n)"); + this.button.addEventListener("click", function (e) { return _this.chooseGame(); }); + }; + UserInterface.prototype.chooseGame = function () { + var _this = this; + if (this.lastInput() === "y") { + this.clearScreen(); + this.display("Ok, let's play Blackjack."); + } + else if (this.lastInput() === "n") { + this.clearScreen(); + this.display("All right, good-bye. Live your best life."); + } + else { + this.button.addEventListener("click", function (e) { return _this.chooseGame(); }); + } + }; + return UserInterface; +}()); +var MathOps = (function () { + function MathOps() { + } + MathOps.sum = function (number1, number2) { + return (number1 + number2); + }; + return MathOps; +}()); +var RankNumber; +(function (RankNumber) { + RankNumber[RankNumber["DEUCE"] = 2] = "DEUCE"; + RankNumber[RankNumber["THREE"] = 3] = "THREE"; + RankNumber[RankNumber["FOUR"] = 4] = "FOUR"; + RankNumber[RankNumber["FIVE"] = 5] = "FIVE"; + RankNumber[RankNumber["SIX"] = 6] = "SIX"; + RankNumber[RankNumber["SEVEN"] = 7] = "SEVEN"; + RankNumber[RankNumber["EIGHT"] = 8] = "EIGHT"; + RankNumber[RankNumber["NINE"] = 9] = "NINE"; + RankNumber[RankNumber["TEN"] = 10] = "TEN"; + RankNumber[RankNumber["JACK"] = 11] = "JACK"; + RankNumber[RankNumber["QUEEN"] = 12] = "QUEEN"; + RankNumber[RankNumber["KING"] = 13] = "KING"; + RankNumber[RankNumber["ACE"] = 1] = "ACE"; +})(RankNumber || (RankNumber = {})); +var RankString; +(function (RankString) { + RankString["DEUCE"] = "2"; + RankString["THREE"] = "3"; + RankString["FOUR"] = "4"; + RankString["FIVE"] = "5"; + RankString["SIX"] = "6"; + RankString["SEVEN"] = "7"; + RankString["EIGHT"] = "8"; + RankString["NINE"] = "9"; + RankString["TEN"] = "10"; + RankString["JACK"] = "J"; + RankString["QUEEN"] = "Q"; + RankString["KING"] = "K"; + RankString["ACE"] = "A"; +})(RankString || (RankString = {})); +var SuitString; +(function (SuitString) { + SuitString["CLUBS"] = "clubs"; + SuitString["DIAMONDS"] = "diamonds"; + SuitString["HEARTS"] = "hearts"; + SuitString["SPADES"] = "spades"; +})(SuitString || (SuitString = {})); +var SuitSymbol; +(function (SuitSymbol) { + SuitSymbol["CLUBS"] = "\u2663"; + SuitSymbol["DIAMONDS"] = "\u2666"; + SuitSymbol["HEARTS"] = "\u2665"; + SuitSymbol["SPADES"] = "\u2660"; +})(SuitSymbol || (SuitSymbol = {})); +var UI = new UserInterface(); +UI.start(); +UI.display(SuitString.CLUBS); +UI.display(SuitSymbol.CLUBS); +UI.display(SuitSymbol.DIAMONDS); +UI.display(SuitSymbol.HEARTS); +UI.display(SuitSymbol.SPADES); +//# 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..a0fcdcac --- /dev/null +++ b/js/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sourceRoot":"","sources":["../ts/app.ts","../ts/previous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AA;IACX,wBAAU,CAAA;IACV,wBAAU,CAAA;IACV,wBAAU,CAAA;IACV,yBAAW,CAAA;IACX,wBAAU,CAAA;IACV,uBAAS,CAAA;AACb,CAAC,EAdI,UAAU,KAAV,UAAU,QAcd;AAED,IAAK,UAKJ;AALD,WAAK,UAAU;IACX,6BAAe,CAAA;IACf,mCAAqB,CAAA;IACrB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;AACrB,CAAC,EALI,UAAU,KAAV,UAAU,QAKd;AAED,IAAK,UAKJ;AALD,WAAK,UAAU;IACX,8BAAgB,CAAA;IAChB,iCAAmB,CAAA;IACnB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;AACrB,CAAC,EALI,UAAU,KAAV,UAAU,QAKd;AAED,IAAI,EAAE,GAAkB,IAAI,aAAa,EAAE,CAAC;AAC5C,EAAE,CAAC,KAAK,EAAE,CAAC;AACX,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC7B,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC7B,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAChC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC9B,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/ts/app.js b/ts/app.js new file mode 100644 index 00000000..26039680 --- /dev/null +++ b/ts/app.js @@ -0,0 +1,164 @@ +var UserInterface = /** @class */ (function () { + function UserInterface() { + var _this = this; + this.userInput = document.getElementById('user_input'); + this.window = document.getElementById('display'); + this.button = document.getElementById('submit'); + this.button.addEventListener("click", function (e) { _this._lastInput = _this.userInput.value; }); + this.button.addEventListener("click", function (e) { return console.log(_this._lastInput); }); + this.button.addEventListener("click", function (e) { _this.userInput.value = ''; }); + // this.chooseGame = this.chooseGame.bind(this); + } + UserInterface.prototype.display = function (input) { this.window.innerText += input + '\n'; }; + UserInterface.prototype.clearScreen = function () { this.window.innerText = ''; }; + UserInterface.prototype.lastInput = function () { return this._lastInput; }; + UserInterface.prototype.start = function () { + var _this = this; + this.display("Do you want to play Blackjack? (y/n)"); + this.button.addEventListener("click", function (e) { return _this.chooseGame(); }); + }; + UserInterface.prototype.chooseGame = function () { + var _this = this; + // this.button.removeEventListener("click", (e:Event) => this.chooseGame()); + if (this.lastInput() === "y") { + this.clearScreen(); + this.display("Ok, let's play Blackjack."); + // this.button.removeEventListener("click", (e:Event) => this.chooseGame()); + } + else if (this.lastInput() === "n") { + this.clearScreen(); + this.display("All right, good-bye. Live your best life."); + // this.button.removeEventListener("click", (e:Event) => this.chooseGame()); + } + else { + this.button.addEventListener("click", function (e) { return _this.chooseGame(); }); + // this.display("Please try again"); + } + }; + return UserInterface; +}()); +var MathOps = /** @class */ (function () { + function MathOps() { + } + MathOps.sum = function (number1, number2) { return (number1 + number2); }; + return MathOps; +}()); +var RankNumber = /** @class */ (function () { + function RankNumber() { + } + RankNumber.getInstance = function () { + if (this._INSTANCE === null) { + this._INSTANCE = new RankNumber(); + } + return this._INSTANCE; + }; + RankNumber.getRankNumbers = function () { return this.rankNumbers; }; + RankNumber.DEUCE = function () { return this.rankNumbers[0]; }; + RankNumber.THREE = function () { return this.rankNumbers[1]; }; + RankNumber.FOUR = function () { return this.rankNumbers[2]; }; + RankNumber.FIVE = function () { return this.rankNumbers[3]; }; + RankNumber.SIX = function () { return this.rankNumbers[4]; }; + RankNumber.SEVEN = function () { return this.rankNumbers[5]; }; + RankNumber.EIGHT = function () { return this.rankNumbers[6]; }; + RankNumber.NINE = function () { return this.rankNumbers[7]; }; + RankNumber.TEN = function () { return this.rankNumbers[8]; }; + RankNumber.JACK = function () { return this.rankNumbers[9]; }; + RankNumber.QUEEN = function () { return this.rankNumbers[10]; }; + RankNumber.KING = function () { return this.rankNumbers[11]; }; + RankNumber.ACE = function () { return this.rankNumbers[12]; }; + RankNumber.rankNumbers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]; + return RankNumber; +}()); +var RankString = /** @class */ (function () { + function RankString() { + } + RankString.getInstance = function () { + if (this._INSTANCE === null) { + this._INSTANCE = new RankString(); + } + return this._INSTANCE; + }; + RankString.getRankStrings = function () { return this.rankStrings; }; + RankString.DEUCE = function () { return this.rankStrings[0]; }; + RankString.THREE = function () { return this.rankStrings[1]; }; + RankString.FOUR = function () { return this.rankStrings[2]; }; + RankString.FIVE = function () { return this.rankStrings[3]; }; + RankString.SIX = function () { return this.rankStrings[4]; }; + RankString.SEVEN = function () { return this.rankStrings[5]; }; + RankString.EIGHT = function () { return this.rankStrings[6]; }; + RankString.NINE = function () { return this.rankStrings[7]; }; + RankString.TEN = function () { return this.rankStrings[8]; }; + RankString.JACK = function () { return this.rankStrings[9]; }; + RankString.QUEEN = function () { return this.rankStrings[10]; }; + RankString.KING = function () { return this.rankStrings[11]; }; + RankString.ACE = function () { return this.rankStrings[12]; }; + RankString.rankStrings = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]; + return RankString; +}()); +var SuitString = /** @class */ (function () { + function SuitString() { + } + SuitString.getInstance = function () { + if (this._INSTANCE === null) { + this._INSTANCE = new SuitString(); + } + return this._INSTANCE; + }; + SuitString.getSuitStrings = function () { return this.suitStrings; }; + SuitString.CLUBS = function () { return this.suitStrings[0]; }; + SuitString.DIAMONDS = function () { return this.suitStrings[1]; }; + SuitString.HEARTS = function () { return this.suitStrings[2]; }; + SuitString.SPADES = function () { return this.suitStrings[3]; }; + SuitString.suitStrings = ["clubs", "diamonds", "hearts", "spades"]; + return SuitString; +}()); +var SuitSymbol = /** @class */ (function () { + function SuitSymbol() { + } + SuitSymbol.getInstance = function () { + if (this._INSTANCE === null) { + this._INSTANCE = new SuitSymbol(); + } + return this._INSTANCE; + }; + SuitSymbol.getSuitSymbols = function () { return this.suitSymbols; }; + SuitSymbol.CLUBS = function () { return this.suitSymbols[0]; }; + SuitSymbol.DIAMONDS = function () { return this.suitSymbols[1]; }; + SuitSymbol.HEARTS = function () { return this.suitSymbols[2]; }; + SuitSymbol.SPADES = function () { return this.suitSymbols[3]; }; + SuitSymbol.suitSymbols = ["\u2663", "\u2666", "\u2665", "\u2660"]; + return SuitSymbol; +}()); +var Card = /** @class */ (function () { + function Card(rankNumber, rankString, suitSymbol, suitString) { + this.rankNumber = rankNumber; + this.rankString = rankString; + this.suitSymbol = suitSymbol; + this.suitString = suitString; + } + Card.prototype.getRankNumber = function () { return this.rankNumber; }; + Card.prototype.getRankString = function () { return this.rankString; }; + Card.prototype.getSuitSymbol = function () { return this.suitSymbol; }; + Card.prototype.getSuitString = function () { return this.suitString; }; + Card.prototype.toString = function () { return this.rankString + this.suitSymbol; }; + return Card; +}()); +var Deck = /** @class */ (function () { + function Deck() { + this.deck = []; + for (var i = 0; i < 4; i++) { + for (var j = 0; j < 13; j++) { + this.deck.push(new Card(RankNumber.getRankNumbers()[j], RankString.getRankStrings()[j], SuitSymbol.getSuitSymbols()[i], SuitString.getSuitStrings()[i])); + } + } + } + Deck.prototype.getDeck = function () { return this.deck; }; + return Deck; +}()); +var UI = new UserInterface(); +var card = new Card(RankNumber.KING(), RankString.KING(), SuitSymbol.SPADES(), SuitString.SPADES()); +var deck = new Deck(); +UI.start(); +UI.display(RankNumber.DEUCE()); +UI.display(card.toString()); +UI.display(deck.getDeck()[12]); diff --git a/ts/app.ts b/ts/app.ts new file mode 100644 index 00000000..e48cde93 --- /dev/null +++ b/ts/app.ts @@ -0,0 +1,187 @@ +class UserInterface { + public userInput: HTMLInputElement = document.getElementById('user_input'); + public window: HTMLDivElement = document.getElementById('display'); + public button: HTMLDivElement = document.getElementById('submit'); + public _lastInput: any; + + constructor() { + this.button.addEventListener("click", (e: Event) => { this._lastInput = this.userInput.value }); + this.button.addEventListener("click", (e:Event) => console.log(this._lastInput)); + this.button.addEventListener("click", (e: Event) => { this.userInput.value = '' }); + // this.chooseGame = this.chooseGame.bind(this); + } + + display(input: any): void { this.window.innerText += input + '\n'; } + clearScreen(): void { this.window.innerText = ''; } + lastInput(): any { return this._lastInput; } + + start() { + this.display("Do you want to play Blackjack? (y/n)"); + this.button.addEventListener("click", (e:Event) => this.chooseGame()); + } + + chooseGame(): void { + // this.button.removeEventListener("click", (e:Event) => this.chooseGame()); + if (this.lastInput() === "y") { + this.clearScreen(); + this.display("Ok, let's play Blackjack."); + // this.button.removeEventListener("click", (e:Event) => this.chooseGame()); + } + else if (this.lastInput() === "n") { + this.clearScreen(); + this.display("All right, good-bye. Live your best life."); + // this.button.removeEventListener("click", (e:Event) => this.chooseGame()); + } + else { + this.button.addEventListener("click", (e:Event) => this.chooseGame()); + // this.display("Please try again"); + } + } +} + +class MathOps { + constructor() {} + public static sum(number1: number, number2: number): number { return (number1 + number2); } +} + +class RankNumber { + private static _INSTANCE: RankNumber; + private static rankNumbers: number[] = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]; + + private constructor() {} + + public static getInstance(): RankNumber { + if (this._INSTANCE === null) { this._INSTANCE = new RankNumber(); } + return this._INSTANCE; + } + + public static getRankNumbers(): number[] { return this.rankNumbers; } + + public static DEUCE(): number { return this.rankNumbers[0]; } + public static THREE(): number { return this.rankNumbers[1]; } + public static FOUR(): number { return this.rankNumbers[2]; } + public static FIVE(): number { return this.rankNumbers[3]; } + public static SIX(): number { return this.rankNumbers[4]; } + public static SEVEN(): number { return this.rankNumbers[5]; } + public static EIGHT(): number { return this.rankNumbers[6]; } + public static NINE(): number { return this.rankNumbers[7]; } + public static TEN(): number { return this.rankNumbers[8]; } + public static JACK(): number { return this.rankNumbers[9]; } + public static QUEEN(): number { return this.rankNumbers[10]; } + public static KING(): number { return this.rankNumbers[11]; } + public static ACE(): number { return this.rankNumbers[12]; } +} + +class RankString { + private static _INSTANCE: RankString; + private static rankStrings: string[] = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]; + + private constructor() {} + + public static getInstance(): RankString { + if (this._INSTANCE === null) { this._INSTANCE = new RankString(); } + return this._INSTANCE; + } + + public static getRankStrings(): string[] { return this.rankStrings; } + + public static DEUCE(): string { return this.rankStrings[0]; } + public static THREE(): string { return this.rankStrings[1]; } + public static FOUR(): string { return this.rankStrings[2]; } + public static FIVE(): string { return this.rankStrings[3]; } + public static SIX(): string { return this.rankStrings[4]; } + public static SEVEN(): string { return this.rankStrings[5]; } + public static EIGHT(): string { return this.rankStrings[6]; } + public static NINE(): string { return this.rankStrings[7]; } + public static TEN(): string { return this.rankStrings[8]; } + public static JACK(): string { return this.rankStrings[9]; } + public static QUEEN(): string { return this.rankStrings[10]; } + public static KING(): string { return this.rankStrings[11]; } + public static ACE(): string { return this.rankStrings[12]; } +} + +class SuitString { + private static _INSTANCE: SuitString; + private static suitStrings: string[] = ["clubs", "diamonds", "hearts", "spades"]; + + private constructor() {} + + public static getInstance() { + if (this._INSTANCE === null) { this._INSTANCE = new SuitString(); } + return this._INSTANCE; + } + + public static getSuitStrings(): string[] { return this.suitStrings; } + + public static CLUBS(): string { return this.suitStrings[0]; } + public static DIAMONDS(): string { return this.suitStrings[1]; } + public static HEARTS(): string { return this.suitStrings[2]; } + public static SPADES(): string { return this.suitStrings[3]; } +} + +class SuitSymbol { + private static _INSTANCE: SuitSymbol; + private static suitSymbols: string[] = ["\u2663", "\u2666", "\u2665", "\u2660"]; + + private constructor() {} + + public static getInstance() { + if (this._INSTANCE === null) { this._INSTANCE = new SuitSymbol(); } + return this._INSTANCE; + } + + public static getSuitSymbols(): string[] { return this.suitSymbols; } + + public static CLUBS(): string { return this.suitSymbols[0]; } + public static DIAMONDS(): string { return this.suitSymbols[1]; } + public static HEARTS(): string { return this.suitSymbols[2]; } + public static SPADES(): string { return this.suitSymbols[3]; } +} + +class Card { + private rankNumber: number; + private rankString: string; + private suitSymbol: string; + private suitString: string; + + constructor(rankNumber: number, rankString: string, suitSymbol: string, suitString: string) { + this.rankNumber = rankNumber; + this.rankString = rankString; + this.suitSymbol = suitSymbol; + this.suitString = suitString; + } + + getRankNumber(): number { return this.rankNumber; } + getRankString(): string { return this.rankString; } + getSuitSymbol(): string { return this.suitSymbol; } + getSuitString(): string { return this.suitString; } + toString(): string { return this.rankString + this.suitSymbol; } +} + +class Deck { + private deck: Card[]; + + constructor() { + this.deck = []; + for (let i = 0; i < 4; i++) { + for (let j = 0; j < 13; j++) { + this.deck.push(new Card(RankNumber.getRankNumbers()[j], + RankString.getRankStrings()[j], + SuitSymbol.getSuitSymbols()[i], + SuitString.getSuitStrings()[i])); + } + } + } + + getDeck(): Card[] { return this.deck; } +} + +let UI: UserInterface = new UserInterface(); +let card: Card = new Card(RankNumber.KING(), RankString.KING(), SuitSymbol.SPADES(), SuitString.SPADES()); +let deck: Deck = new Deck(); + +UI.start(); +UI.display(RankNumber.DEUCE()); +UI.display(card.toString()); +UI.display(deck.getDeck()[12]); + diff --git a/ts/enums b/ts/enums new file mode 100644 index 00000000..748b3e77 --- /dev/null +++ b/ts/enums @@ -0,0 +1,45 @@ +enum RankNumber { + DEUCE = 2, + THREE = 3, + FOUR = 4, + FIVE = 5, + SIX = 6, + SEVEN = 7, + EIGHT = 8, + NINE = 9, + TEN = 10, + JACK = 11, + QUEEN = 12, + KING = 13, + ACE = 1 +} + +enum RankString { + DEUCE = "2", + THREE = "3", + FOUR = "4", + FIVE = "5", + SIX = "6", + SEVEN = "7", + EIGHT = "8", + NINE = "9", + TEN = "10", + JACK = "J", + QUEEN = "Q", + KING = "K", + ACE = "A" +} + +enum SuitString { + CLUBS = "clubs", + DIAMONDS = "diamonds", + HEARTS = "hearts", + SPADES = "spades" +} + +enum SuitSymbol { + CLUBS = "\u2663", + DIAMONDS = "\u2666", + HEARTS = "\u2665", + SPADES = "\u2660" +} \ No newline at end of file diff --git a/ts/previousApp.js b/ts/previousApp.js new file mode 100644 index 00000000..4c35ca7f --- /dev/null +++ b/ts/previousApp.js @@ -0,0 +1,74 @@ +//IGNORE THIS FILE +// namespace commoname; +// // import { sumTwoNumbers } from "./sumTwoNumbers"; +// // class Student { +// // fullName: string; +// // constructor(public firstName: string, public middleInitial: string, public lastName: string) { +// // this.fullName = firstName + " " + middleInitial + " " + lastName; +// // } +// // } +// // interface Person { +// // firstName: string; +// // lastName: string; +// // } +// // function greeter(person: Person) { +// // return "Hello, " + person.firstName + " " + person.lastName; +// // } +// // let user: Student = new Student("Luis", "J.", "Romero"); +// class UI { +// static userInput: HTMLInputElement = document.getElementById('user_input'); +// static window: HTMLDivElement = document.getElementById('display'); +// static button: HTMLDivElement = 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) => console.log(UI._lastInput)); +// 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 = ''; +// } +// public static get Instance(): UI { +// return this._instance || (this._instance = new UI()); +// } +// public static get lastInput(): any { +// return this._lastInput; +// } +// } +// // let userInput0 = prompt("Please enter something: ", "type0"); +// // let userInput1 = prompt("Please enter something: ", "type1"); +// // console.log(userInput0); +// // console.log(userInput1); +// class Choose { +// 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", (e:Event) => this.chooseGame); +// chooseGame(): void { +// UI.button.removeEventListener("click", (e:Event) => this.chooseGame); +// if (UI.lastInput === "Black Jack") { +// UI.display("Black Jack worked"); +// } +// else if (UI.lastInput === "Go Fish") { +// UI.display("Go Fish worked"); +// } +// else { +// UI.button.addEventListener("click", (e:Event) => this.chooseGame); +// } +// } +// } +// UI; +// UI.display("text from display method"); +// let chooseGame: Choose = new Choose(); +// // chooseGame.start(); +// chooseGame.chooseGame(); +// // let num: number = sumTwoNumbers(1, 2); +// // console.log(num); diff --git a/ts/previousApp.ts b/ts/previousApp.ts new file mode 100644 index 00000000..d44c6e87 --- /dev/null +++ b/ts/previousApp.ts @@ -0,0 +1,93 @@ +//IGNORE THIS FILE + +// namespace commoname; + +// // import { sumTwoNumbers } from "./sumTwoNumbers"; + +// // class Student { +// // fullName: string; +// // constructor(public firstName: string, public middleInitial: string, public lastName: string) { +// // this.fullName = firstName + " " + middleInitial + " " + lastName; +// // } +// // } + +// // interface Person { +// // firstName: string; +// // lastName: string; +// // } + +// // function greeter(person: Person) { +// // return "Hello, " + person.firstName + " " + person.lastName; +// // } + +// // let user: Student = new Student("Luis", "J.", "Romero"); + +// class UI { +// static userInput: HTMLInputElement = document.getElementById('user_input'); +// static window: HTMLDivElement = document.getElementById('display'); +// static button: HTMLDivElement = 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) => console.log(UI._lastInput)); +// 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 = ''; +// } + +// public static get Instance(): UI { +// return this._instance || (this._instance = new UI()); +// } + +// public static get lastInput(): any { +// return this._lastInput; +// } + +// } + +// // let userInput0 = prompt("Please enter something: ", "type0"); +// // let userInput1 = prompt("Please enter something: ", "type1"); +// // console.log(userInput0); +// // console.log(userInput1); + +// class Choose { +// 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", (e:Event) => this.chooseGame); + +// chooseGame(): void { +// UI.button.removeEventListener("click", (e:Event) => this.chooseGame); +// if (UI.lastInput === "Black Jack") { +// UI.display("Black Jack worked"); +// } +// else if (UI.lastInput === "Go Fish") { +// UI.display("Go Fish worked"); +// } +// else { +// UI.button.addEventListener("click", (e:Event) => this.chooseGame); +// } +// } +// } + +// UI; +// UI.display("text from display method"); +// let chooseGame: Choose = new Choose(); +// // chooseGame.start(); +// chooseGame.chooseGame(); + +// // let num: number = sumTwoNumbers(1, 2); +// // console.log(num); \ No newline at end of file diff --git a/ts/singleton.ts b/ts/singleton.ts new file mode 100644 index 00000000..f5603c26 --- /dev/null +++ b/ts/singleton.ts @@ -0,0 +1,53 @@ +class UI_Singleton { + static userInput = document.getElementById("user_input"); + static window = document.getElementById('display'); + static button = document.getElementById('submit'); + static _lastInput: any; + private static _instance: UI_Singleton; + + private constructor() { + UI_Singleton.button.addEventListener("click", (e: Event) => { UI_Singleton._lastInput = UI_Singleton.userInput.value }); + UI_Singleton.button.addEventListener("click", (e: Event) => { UI_Singleton.userInput.value = '' }); + } + + static display(input: string): void { + this.window.innerText += input + '\n'; + } + + static clearScreen(): void { + this.window.innerText = ''; + } + + public static get Instance(): UI_Singleton { + return this._instance || (this._instance = new UI_Singleton()); + } + + public static get lastInput(): any { + return this._lastInput; + } + +} + +class Singleton { + static anyVariable: any = "anyValue"; + private static _INSTANCE: Singleton; + + private constructor() { + } + + static someMethod(input: string): void { + } + + static someMethod2(): any { + return null; + } + + public static getInstance(): Singleton { + return this._INSTANCE; + } + + public static getField(): any { + return this.anyVariable; + } + +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..75a50f02 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "system", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "outFile": "./js/app.js", + "sourceMap": true, + "target": "es5", + "watch": true + }, + "include": [ + "./**/*" + ], + "exclude": [ + "node_modules", + "**/*.spec.ts" + ] +} \ No newline at end of file