diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..252a2274 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,62 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/app.js" + }, + { + "type": "node", + "request": "launch", + "name": "Gulp task", + "program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js", + "args": [ + "task" + ] + }, + { + "type": "node", + "request": "launch", + "name": "Electron Main", + "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron", + "program": "${workspaceFolder}/main.js", + "protocol": "legacy" + }, + { + "type": "node", + "request": "attach", + "name": "Attach to Remote", + "address": "TCP/IP address of process to be debugged", + "port": 9229, + "localRoot": "${workspaceFolder}", + "remoteRoot": "Absolute path to the remote directory containing the program" + }, + { + "type": "node", + "request": "attach", + "name": "Attach by Process ID", + "processId": "${command:PickProcess}" + }, + { + "type": "node", + "request": "attach", + "name": "Attach", + "port": 9229 + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/app.ts", + "preLaunchTask": "tsc: build - tsconfig.json", + "outFiles": [ + "${workspaceFolder}/js/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..250affa3 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,18 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/app.ts b/app.ts new file mode 100644 index 00000000..cc55188e --- /dev/null +++ b/app.ts @@ -0,0 +1,145 @@ +// var window = document.getElementById("display"); +// var userInput = document.getElementById("user_input"); +// var button = document.getElementById("submitButton"); +// var TEST_INPUT; + +// function addToDisplayText(text: string) { +// window.innerText += '\n'; +// window.innerText += text; +// } + +// function waitAndGetUserInputString(): string { +// var theNumber; +// button.addEventListener("onclick", (e: Event) => theNumber = userInput.value); +// while (theNumber == null) { +// if (theNumber != null) { +// break; +// } +// } +// button.removeEventListener("onclick", waitAndGetUserInputString); +// return theNumber; +// } + +// function waitAndGetUserInputNumber(): number { +// var theNumber; +// button.addEventListener("click", (e: Event) => theNumber = +userInput.value); +// while (theNumber == null) { +// if (theNumber != null) { +// break; +// } +// } +// button.removeEventListener("click", waitAndGetUserInputNumber); +// return theNumber; +// } + +class Profile { + private id: number = 1; + private _name: string = null; + private _balance: number = 0; + constructor() {} + get balance(): number { + return this.balance; + } + set balance(theBalance: number) { + this.balance = theBalance; + } + set name(theName: string) { + this._name = theName; + } +} + +// sigh +interface GameInterface { + start(); +} + +interface GamblingInterface { + bet(); +} + +// Player initialization had to be removed to here because this language is bleh +var player:Profile = null; + +class SlotMachine { + public static start() { + UI.display("Welcome to slot machine! Win triple your bet for 3 matching numbers or 1.5x for 2."); + while(true) { + var currentInput; + var currentBalance = player.balance; + var payout; + UI.display("You have $" + currentBalance + ". Enter a number less than your total to bet."); + UI.display("Enter anything else to quit."); + currentInput = UI.lastInput; + player.balance = currentBalance - currentInput; + UI.display("You entered " + currentInput + "."); + if ((!isNaN(currentInput)) && (currentInput <= currentBalance)) { + UI.display("Valid input! Spinning reels..."); + var firstReel = Math.floor(Math.random() * 5) + 1; + var secondReel = Math.floor(Math.random() * 5) + 1; + var thirdReel = Math.floor(Math.random() * 5) + 1; + UI.display("|| " + firstReel + " | " + secondReel + " | " + thirdReel + " ||"); + if (firstReel == secondReel && thirdReel) { + payout = currentInput * 3; + UI.display("JACKPOT!!") + } else if (((firstReel == secondReel) && (firstReel != thirdReel)) || + ((firstReel == thirdReel) && (firstReel != secondReel)) || + ((secondReel == thirdReel) && (secondReel != firstReel))) { + payout = Math.floor(currentInput * 1.5); + } else { + payout = 0; + } + UI.display("Your payout: $" + payout); + player.balance += payout; + } else { + UI.display("Invalid input! Bye-bye!"); + break; + } + } + } +} + +class Startup { + public static main(): void { + UI.display("Welcome to the worst casino you've ever seen!"); + UI.display("Please enter your name:"); + player.name = UI.lastInput; + // button.addEventListener("click", (e: Event) => player.name = userInput.value); + UI.display("Please enter how many dollary doos you want to start with:") + player.balance = UI.lastInput; + // button.addEventListener("click", (e: Event) => player.balance = +userInput.value); + } +} + +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: any): 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; + } + +} + +const UIInstance = UI.Instance; +Startup.main(); +SlotMachine.start(); \ No newline at end of file diff --git a/index.html b/index.html index d2c3c254..62d4bebc 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..f9e41e42 --- /dev/null +++ b/js/app.js @@ -0,0 +1,148 @@ +// var window = document.getElementById("display"); +// var userInput = document.getElementById("user_input"); +// var button = document.getElementById("submitButton"); +// var TEST_INPUT; +// function addToDisplayText(text: string) { +// window.innerText += '\n'; +// window.innerText += text; +// } +// function waitAndGetUserInputString(): string { +// var theNumber; +// button.addEventListener("onclick", (e: Event) => theNumber = userInput.value); +// while (theNumber == null) { +// if (theNumber != null) { +// break; +// } +// } +// button.removeEventListener("onclick", waitAndGetUserInputString); +// return theNumber; +// } +// function waitAndGetUserInputNumber(): number { +// var theNumber; +// button.addEventListener("click", (e: Event) => theNumber = +userInput.value); +// while (theNumber == null) { +// if (theNumber != null) { +// break; +// } +// } +// button.removeEventListener("click", waitAndGetUserInputNumber); +// return theNumber; +// } +var Profile = /** @class */ (function () { + function Profile() { + this.id = 1; + this._name = null; + this._balance = 0; + } + Object.defineProperty(Profile.prototype, "balance", { + get: function () { + return this.balance; + }, + set: function (theBalance) { + this.balance = theBalance; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Profile.prototype, "name", { + set: function (theName) { + this._name = theName; + }, + enumerable: true, + configurable: true + }); + return Profile; +}()); +// Player initialization had to be removed to here because this language is bleh +var player = null; +var SlotMachine = /** @class */ (function () { + function SlotMachine() { + } + SlotMachine.start = function () { + UI.display("Welcome to slot machine! Win triple your bet for 3 matching numbers or 1.5x for 2."); + while (true) { + var currentInput; + var currentBalance = player.balance; + var payout; + UI.display("You have $" + currentBalance + ". Enter a number less than your total to bet."); + UI.display("Enter anything else to quit."); + currentInput = UI.lastInput; + player.balance = currentBalance - currentInput; + UI.display("You entered " + currentInput + "."); + if ((!isNaN(currentInput)) && (currentInput <= currentBalance)) { + UI.display("Valid input! Spinning reels..."); + var firstReel = Math.floor(Math.random() * 5) + 1; + var secondReel = Math.floor(Math.random() * 5) + 1; + var thirdReel = Math.floor(Math.random() * 5) + 1; + UI.display("|| " + firstReel + " | " + secondReel + " | " + thirdReel + " ||"); + if (firstReel == secondReel && thirdReel) { + payout = currentInput * 3; + UI.display("JACKPOT!!"); + } + else if (((firstReel == secondReel) && (firstReel != thirdReel)) || + ((firstReel == thirdReel) && (firstReel != secondReel)) || + ((secondReel == thirdReel) && (secondReel != firstReel))) { + payout = Math.floor(currentInput * 1.5); + } + else { + payout = 0; + } + UI.display("Your payout: $" + payout); + player.balance += payout; + } + else { + UI.display("Invalid input! Bye-bye!"); + break; + } + } + }; + return SlotMachine; +}()); +var Startup = /** @class */ (function () { + function Startup() { + } + Startup.main = function () { + UI.display("Welcome to the worst casino you've ever seen!"); + UI.display("Please enter your name:"); + player.name = UI.lastInput; + // button.addEventListener("click", (e: Event) => player.name = userInput.value); + UI.display("Please enter how many dollary doos you want to start with:"); + player.balance = UI.lastInput; + // button.addEventListener("click", (e: Event) => player.balance = +userInput.value); + }; + return Startup; +}()); +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 = ''; + }; + 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 UIInstance = UI.Instance; +Startup.main(); +SlotMachine.start(); +//# 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..2c5670a0 --- /dev/null +++ b/js/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,2EAA2E;AAC3E,wDAAwD;AACxD,kBAAkB;AAElB,4CAA4C;AAC5C,gCAAgC;AAChC,gCAAgC;AAChC,IAAI;AAEJ,iDAAiD;AACjD,qBAAqB;AACrB,qFAAqF;AACrF,kCAAkC;AAClC,mCAAmC;AACnC,qBAAqB;AACrB,YAAY;AACZ,QAAQ;AACR,wEAAwE;AACxE,wBAAwB;AACxB,IAAI;AAEJ,iDAAiD;AACjD,qBAAqB;AACrB,oFAAoF;AACpF,kCAAkC;AAClC,mCAAmC;AACnC,qBAAqB;AACrB,YAAY;AACZ,QAAQ;AACR,sEAAsE;AACtE,wBAAwB;AACxB,IAAI;AAEJ;IAII;QAHQ,OAAE,GAAW,CAAC,CAAC;QACf,UA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E,SAAM,GAAmB,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC5D,SAAM,GAAmB,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAyBtE,SAAC;CAAA,AA5BD,IA4BC;AAED,IAAM,UAAU,GAAG,EAAE,CAAC,QAAQ,CAAC;AAC/B,OAAO,CAAC,IAAI,EAAE,CAAC;AACf,WAAW,CAAC,KAAK,EAAE,CAAC"} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..d0262167 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es5", + "noImplicitAny": false, + "sourceMap": true, + "watch": true, + "outDir": "js" + }, + "compileOnSave": true, + "files": [ + "app.ts" + ] + } \ No newline at end of file