Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
18 changes: 18 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
145 changes: 145 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// var window = document.getElementById("display");
// var userInput = <HTMLInputElement>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 = <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) => { 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();
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>TypeScript Casino</h1>
<div id="display"></div>
<div id="input">
<input type="text" name="user_input" id="user_input">
<input type="submit" value="submit">
<input type="button" value="submit" id="submitButton">
</div>
</section>

Expand Down
148 changes: 148 additions & 0 deletions js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/app.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading