From 78dc2504c77fb7cf9dc73617fe5cc491c424e51e Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Wed, 24 Feb 2021 17:46:31 -0500 Subject: [PATCH 01/10] updated typescript version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee14a9f..7aae9fe 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "license": "ISC", "devDependencies": { "ts-loader": "8.0.17", - "typescript": "4.1.5", + "typescript": "4.2.2", "webpack": "5.22.0", "webpack-cli": "4.5.0", "webpack-dev-server": "3.11.2" From bb553f2f8fed10527980c18081afe2175b89d88c Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Wed, 24 Feb 2021 18:12:16 -0500 Subject: [PATCH 02/10] recorded demo 1 --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5e55df8..911bf7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4117,9 +4117,9 @@ } }, "typescript": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz", - "integrity": "sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==", + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.2.tgz", + "integrity": "sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ==", "dev": true }, "union-value": { From 812b43a52075c557e3f5d913e4c0f45baef0f75d Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Wed, 24 Feb 2021 18:28:09 -0500 Subject: [PATCH 03/10] recorded demo 2 --- app/app.js | 6 ++++++ app/app.ts | 7 +++++++ index.html | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 app/app.js diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000..2f99e03 --- /dev/null +++ b/app/app.js @@ -0,0 +1,6 @@ +function startGame() { + // starting a new game + var messagesElement = document.getElementById('messages'); + messagesElement.innerText = 'Welcome to MultiMath! Starting new game...'; +} +document.getElementById('startGame').addEventListener('click', startGame); diff --git a/app/app.ts b/app/app.ts index e69de29..8aa8b93 100644 --- a/app/app.ts +++ b/app/app.ts @@ -0,0 +1,7 @@ +function startGame() { + // starting a new game + var messagesElement = document.getElementById('messages'); + messagesElement.innerText = 'Welcome to MultiMath! Starting new game...'; +} + +document.getElementById('startGame').addEventListener('click', startGame); \ No newline at end of file diff --git a/index.html b/index.html index c636518..e5223a2 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@

No scores yet

- + From 5e4c0fb14264a362c0927278b3fe5596b36d3b18 Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Thu, 25 Feb 2021 10:19:56 -0500 Subject: [PATCH 04/10] recorded demo 3 --- app/app.ts | 4 +-- index.html | 2 +- {app => js}/app.js | 2 ++ js/app.js.map | 1 + tsconfig.json | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) rename {app => js}/app.js (85%) create mode 100644 js/app.js.map diff --git a/app/app.ts b/app/app.ts index 8aa8b93..77d9b10 100644 --- a/app/app.ts +++ b/app/app.ts @@ -1,7 +1,7 @@ function startGame() { // starting a new game var messagesElement = document.getElementById('messages'); - messagesElement.innerText = 'Welcome to MultiMath! Starting new game...'; + messagesElement!.innerText = 'Welcome to MultiMath! Starting new game...'; } -document.getElementById('startGame').addEventListener('click', startGame); \ No newline at end of file +document.getElementById('startGame')!.addEventListener('click', startGame); \ No newline at end of file diff --git a/index.html b/index.html index e5223a2..fee7adc 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@

No scores yet

- + diff --git a/app/app.js b/js/app.js similarity index 85% rename from app/app.js rename to js/app.js index 2f99e03..35fa869 100644 --- a/app/app.js +++ b/js/app.js @@ -1,6 +1,8 @@ +"use strict"; function startGame() { // starting a new game var messagesElement = document.getElementById('messages'); messagesElement.innerText = 'Welcome to MultiMath! Starting new game...'; } document.getElementById('startGame').addEventListener('click', startGame); +//# 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 0000000..ec58a15 --- /dev/null +++ b/js/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/app.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS;IAChB,sBAAsB;IACtB,IAAI,eAAe,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1D,eAAgB,CAAC,SAAS,GAAG,4CAA4C,CAAC;AAC5E,CAAC;AAED,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e69de29..21fad08 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -0,0 +1,75 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + // "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', 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', 'react', 'react-jsx' or 'react-jsxdev'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "js", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "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. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "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. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* 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. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* 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. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ + "watch": true + }, + "files": [ + "app/app.ts" + ] +} From dcce840bdb57f26af997f191b202c0187e9b5446 Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Thu, 25 Feb 2021 10:40:23 -0500 Subject: [PATCH 05/10] recorded demo 4 --- app/tsconfig.json | 9 +++++++++ js/app.js | 1 - js/app.js.map | 2 +- tsconfig.json => tsconfig.base.json | 5 +---- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 app/tsconfig.json rename tsconfig.json => tsconfig.base.json (99%) diff --git a/app/tsconfig.json b/app/tsconfig.json new file mode 100644 index 0000000..b90a603 --- /dev/null +++ b/app/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.base", + "compilerOptions": { + "removeComments": true + }, + "include": [ + "./**/*" + ] +} \ No newline at end of file diff --git a/js/app.js b/js/app.js index 35fa869..07f8031 100644 --- a/js/app.js +++ b/js/app.js @@ -1,6 +1,5 @@ "use strict"; function startGame() { - // starting a new game var messagesElement = document.getElementById('messages'); messagesElement.innerText = 'Welcome to MultiMath! Starting new game...'; } diff --git a/js/app.js.map b/js/app.js.map index ec58a15..3bdf330 100644 --- a/js/app.js.map +++ b/js/app.js.map @@ -1 +1 @@ -{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/app.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS;IAChB,sBAAsB;IACtB,IAAI,eAAe,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1D,eAAgB,CAAC,SAAS,GAAG,4CAA4C,CAAC;AAC5E,CAAC;AAED,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/app.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS;IAEhB,IAAI,eAAe,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1D,eAAgB,CAAC,SAAS,GAAG,4CAA4C,CAAC;AAC5E,CAAC;AAED,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.base.json similarity index 99% rename from tsconfig.json rename to tsconfig.base.json index 21fad08..0d40725 100644 --- a/tsconfig.json +++ b/tsconfig.base.json @@ -68,8 +68,5 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ "watch": true - }, - "files": [ - "app/app.ts" - ] + } } From 7b13965965aa46bf4b4dc53fc1d6bf7f292162c4 Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Thu, 25 Feb 2021 10:45:29 -0500 Subject: [PATCH 06/10] recorded demo 5 --- index.html | 2 +- js/app.js | 7 ------- js/app.js.map | 1 - 3 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 js/app.js delete mode 100644 js/app.js.map diff --git a/index.html b/index.html index fee7adc..d343248 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@

No scores yet

- + diff --git a/js/app.js b/js/app.js deleted file mode 100644 index 07f8031..0000000 --- a/js/app.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -function startGame() { - var messagesElement = document.getElementById('messages'); - messagesElement.innerText = 'Welcome to MultiMath! Starting new game...'; -} -document.getElementById('startGame').addEventListener('click', startGame); -//# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/js/app.js.map b/js/app.js.map deleted file mode 100644 index 3bdf330..0000000 --- a/js/app.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/app.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS;IAEhB,IAAI,eAAe,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1D,eAAgB,CAAC,SAAS,GAAG,4CAA4C,CAAC;AAC5E,CAAC;AAED,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC"} \ No newline at end of file From 45fa5c04bb4428a28b2cf9f794df24bd1b7842e1 Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Thu, 25 Feb 2021 16:20:55 -0500 Subject: [PATCH 07/10] add m3 code --- app/app.ts | 12 ++++++++++-- tsconfig.base.json | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/app.ts b/app/app.ts index 77d9b10..61b9d40 100644 --- a/app/app.ts +++ b/app/app.ts @@ -1,7 +1,15 @@ function startGame() { // starting a new game - var messagesElement = document.getElementById('messages'); + + let playerName: string = 'Audrey'; + logPlayer(playerName); + + let messagesElement = document.getElementById('messages'); + messagesElement!.innerText = 'Welcome to MultiMath! Starting new game...'; } -document.getElementById('startGame')!.addEventListener('click', startGame); \ No newline at end of file +function logPlayer(name) { + console.log(`New game starting for player: ${name}`); +} +document.getElementById('startGame')!.addEventListener('click', startGame); diff --git a/tsconfig.base.json b/tsconfig.base.json index 0d40725..1c25aba 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -25,9 +25,9 @@ // "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. */ + // "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": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ From 561b6157a5d4cd526e4a2866b0516b3cbef026f5 Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Thu, 25 Feb 2021 16:56:37 -0500 Subject: [PATCH 08/10] code for m4 --- app/app.ts | 45 ++++++++++++++++++++++++++++++++++++++++----- index.html | 2 +- tsconfig.base.json | 2 +- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/app.ts b/app/app.ts index 61b9d40..814f956 100644 --- a/app/app.ts +++ b/app/app.ts @@ -1,15 +1,50 @@ function startGame() { // starting a new game - let playerName: string = 'Audrey'; + let playerName: string | undefined = getInputValue('playername'); logPlayer(playerName); - let messagesElement = document.getElementById('messages'); - - messagesElement!.innerText = 'Welcome to MultiMath! Starting new game...'; + postScore(80, playerName); + postScore(-5, playerName); } -function logPlayer(name) { +function logPlayer(name: string = 'MultiMath Player'): void { console.log(`New game starting for player: ${name}`); } + +function getInputValue(elementID: string): string | undefined { + + const inputElement: HTMLInputElement = document.getElementById(elementID); + + if (inputElement.value === '') { + return undefined; + } + else { + return inputElement.value; + } +} + +function postScore(score: number, playerName: string = 'MultiMath Player'): void { + + let logger: (value: string) => void; + + if (score < 0) { + logger = logError; + } + else { + logger = logMessage; + } + + const scoreElement: HTMLElement | null = document.getElementById('postedScores'); + scoreElement!.innerText = `${score} - ${playerName}`; + + logger(`Score: ${score}`); +} + document.getElementById('startGame')!.addEventListener('click', startGame); + +const logMessage = (message: string) => console.log(message); + +function logError(err: string): void { + console.error(err); +} \ No newline at end of file diff --git a/index.html b/index.html index d343248..4f52d1a 100644 --- a/index.html +++ b/index.html @@ -49,7 +49,7 @@

Scoreboard

-

No scores yet

+

No scores yet

diff --git a/tsconfig.base.json b/tsconfig.base.json index 1c25aba..ecde916 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -26,7 +26,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. */ + "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. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ From 158c29e58eebe52267ffd6ed5bec1c67e8a64763 Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Thu, 25 Feb 2021 18:11:26 -0500 Subject: [PATCH 09/10] added m5 code --- app/app.ts | 61 +++++++++----------------------- app/game.ts | 59 +++++++++++++++++++++++++++++++ app/person.ts | 5 +++ app/player.ts | 11 ++++++ app/result.ts | 6 ++++ app/scoreboard.ts | 24 +++++++++++++ app/tsconfig.json | 7 ++-- app/utility.ts | 9 +++++ index.html | 2 +- js/app.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++ js/app.js.map | 1 + webpack.config.js | 36 +++++++++---------- 12 files changed, 244 insertions(+), 67 deletions(-) create mode 100644 app/game.ts create mode 100644 app/person.ts create mode 100644 app/player.ts create mode 100644 app/result.ts create mode 100644 app/scoreboard.ts create mode 100644 app/utility.ts create mode 100644 js/app.js create mode 100644 js/app.js.map diff --git a/app/app.ts b/app/app.ts index 814f956..3b01dbb 100644 --- a/app/app.ts +++ b/app/app.ts @@ -1,50 +1,21 @@ -function startGame() { - // starting a new game +/// +/// - let playerName: string | undefined = getInputValue('playername'); - logPlayer(playerName); - - postScore(80, playerName); - postScore(-5, playerName); -} +let newGame: Game; -function logPlayer(name: string = 'MultiMath Player'): void { - console.log(`New game starting for player: ${name}`); -} +// add click handler to the start game button +document.getElementById('startGame')!.addEventListener('click', () => { + const player: Player = new Player(); + player.name = Utility.getInputValue('playername'); -function getInputValue(elementID: string): string | undefined { + const problemCount: number = Number(Utility.getInputValue('problemCount')); + const factor: number = Number(Utility.getInputValue('factor')); - const inputElement: HTMLInputElement = document.getElementById(elementID); + newGame = new Game(player, problemCount, factor); + newGame.displayGame(); +}); - if (inputElement.value === '') { - return undefined; - } - else { - return inputElement.value; - } -} - -function postScore(score: number, playerName: string = 'MultiMath Player'): void { - - let logger: (value: string) => void; - - if (score < 0) { - logger = logError; - } - else { - logger = logMessage; - } - - const scoreElement: HTMLElement | null = document.getElementById('postedScores'); - scoreElement!.innerText = `${score} - ${playerName}`; - - logger(`Score: ${score}`); -} - -document.getElementById('startGame')!.addEventListener('click', startGame); - -const logMessage = (message: string) => console.log(message); - -function logError(err: string): void { - console.error(err); -} \ No newline at end of file +// add click handler to the calculate score button +document.getElementById('calculate')!.addEventListener('click', () => { + newGame.calculateScore(); +}); \ No newline at end of file diff --git a/app/game.ts b/app/game.ts new file mode 100644 index 0000000..3fb00e1 --- /dev/null +++ b/app/game.ts @@ -0,0 +1,59 @@ +/// +/// +/// +/// + +class Game { + private scoreboard: Scoreboard = new Scoreboard(); + + constructor(public player: Player, public problemCount: number, public factor: number) { + } + + displayGame(): void { + + // create the html for the current game + let gameForm: string = ''; + for (let i = 1; i <= this.problemCount; i++) { + gameForm += '
'; + gameForm += ''; + gameForm += '
'; + gameForm += '
'; + } + + // add the new game to the page + const gameElement: HTMLElement = document.getElementById('game')!; + gameElement.innerHTML = gameForm; + + // enable the calculate score button + document.getElementById('calculate')!.removeAttribute('disabled'); + } + + calculateScore(): void { + + let score: number = 0; + + // loop through the text boxes and calculate the number that are correct + for (let i = 1; i <= this.problemCount; i++) { + const answer: number = Number(Utility.getInputValue('answer' + i)); + if (i * this.factor === answer) { + score++; + } + } + + // create a new result object to pass to the scoreboard + const result: Result = { + playerName: this.player.name, + score: score, + problemCount: this.problemCount, + factor: this.factor + }; + + // add the result and update the scoreboard + this.scoreboard.addResult(result); + this.scoreboard.updateScoreboard(); + + // disable the calculate score button + document.getElementById('calculate')!.setAttribute('disabled', 'true'); + } +} \ No newline at end of file diff --git a/app/person.ts b/app/person.ts new file mode 100644 index 0000000..f6f75f7 --- /dev/null +++ b/app/person.ts @@ -0,0 +1,5 @@ +interface Person { + name: string; + age?: number; + formatName: () => string; +} \ No newline at end of file diff --git a/app/player.ts b/app/player.ts new file mode 100644 index 0000000..618a8fd --- /dev/null +++ b/app/player.ts @@ -0,0 +1,11 @@ +/// + +class Player implements Person { + name: string; + age: number; + highScore: number; + + formatName() { + return this.name.toUpperCase(); + } +} \ No newline at end of file diff --git a/app/result.ts b/app/result.ts new file mode 100644 index 0000000..4264ded --- /dev/null +++ b/app/result.ts @@ -0,0 +1,6 @@ +interface Result { + playerName: string; + score: number; + problemCount: number; + factor: number; +} \ No newline at end of file diff --git a/app/scoreboard.ts b/app/scoreboard.ts new file mode 100644 index 0000000..accbb5a --- /dev/null +++ b/app/scoreboard.ts @@ -0,0 +1,24 @@ +/// + +class Scoreboard { + + private results: Result[] = []; + + addResult(newResult: Result): void { + this.results.push(newResult); + } + + updateScoreboard(): void { + let output: string = '

Scoreboard

'; + + for (let index = 0; index < this.results.length; index++) { + const result: Result = this.results[index]; + output += '

'; + output += result.playerName + ': ' + result.score + '/' + result.problemCount + ' for factor ' + result.factor; + output += '

'; + } + + const scoresElement: HTMLElement = document.getElementById('scores')!; + scoresElement.innerHTML = output; + } +} \ No newline at end of file diff --git a/app/tsconfig.json b/app/tsconfig.json index b90a603..eda1091 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -1,9 +1,10 @@ { "extends": "../tsconfig.base", "compilerOptions": { - "removeComments": true + "removeComments": true, + "outFile": "../js/app.js" }, - "include": [ - "./**/*" + "files": [ + "./app.ts" ] } \ No newline at end of file diff --git a/app/utility.ts b/app/utility.ts new file mode 100644 index 0000000..34c8281 --- /dev/null +++ b/app/utility.ts @@ -0,0 +1,9 @@ +class Utility { + + static getInputValue(elementID: string): string { + + const inputElement: HTMLInputElement = document.getElementById(elementID); + return inputElement.value; + } + +} \ No newline at end of file diff --git a/index.html b/index.html index 4f52d1a..df3c776 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@

No scores yet

- + diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..51d5b3b --- /dev/null +++ b/js/app.js @@ -0,0 +1,90 @@ +var Player = (function () { + function Player() { + } + Player.prototype.formatName = function () { + return this.name.toUpperCase(); + }; + return Player; +}()); +var Utility = (function () { + function Utility() { + } + Utility.getInputValue = function (elementID) { + var inputElement = document.getElementById(elementID); + return inputElement.value; + }; + return Utility; +}()); +var Scoreboard = (function () { + function Scoreboard() { + this.results = []; + } + Scoreboard.prototype.addResult = function (newResult) { + this.results.push(newResult); + }; + Scoreboard.prototype.updateScoreboard = function () { + var output = '

Scoreboard

'; + for (var index = 0; index < this.results.length; index++) { + var result = this.results[index]; + output += '

'; + output += result.playerName + ': ' + result.score + '/' + result.problemCount + ' for factor ' + result.factor; + output += '

'; + } + var scoresElement = document.getElementById('scores'); + scoresElement.innerHTML = output; + }; + return Scoreboard; +}()); +var Game = (function () { + function Game(player, problemCount, factor) { + this.player = player; + this.problemCount = problemCount; + this.factor = factor; + this.scoreboard = new Scoreboard(); + } + Game.prototype.displayGame = function () { + var gameForm = ''; + for (var i = 1; i <= this.problemCount; i++) { + gameForm += '
'; + gameForm += ''; + gameForm += '
'; + gameForm += '
'; + } + var gameElement = document.getElementById('game'); + gameElement.innerHTML = gameForm; + document.getElementById('calculate').removeAttribute('disabled'); + }; + Game.prototype.calculateScore = function () { + var score = 0; + for (var i = 1; i <= this.problemCount; i++) { + var answer = Number(Utility.getInputValue('answer' + i)); + if (i * this.factor === answer) { + score++; + } + } + var result = { + playerName: this.player.name, + score: score, + problemCount: this.problemCount, + factor: this.factor + }; + this.scoreboard.addResult(result); + this.scoreboard.updateScoreboard(); + document.getElementById('calculate').setAttribute('disabled', 'true'); + }; + return Game; +}()); +var newGame; +document.getElementById('startGame').addEventListener('click', function () { + var player = new Player(); + player.name = Utility.getInputValue('playername'); + var problemCount = Number(Utility.getInputValue('problemCount')); + var factor = Number(Utility.getInputValue('factor')); + newGame = new Game(player, problemCount, factor); + newGame.displayGame(); +}); +document.getElementById('calculate').addEventListener('click', function () { + newGame.calculateScore(); +}); +//# 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 0000000..e8a2d58 --- /dev/null +++ b/js/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/person.ts","../app/player.ts","../app/utility.ts","../app/result.ts","../app/scoreboard.ts","../app/game.ts","../app/app.ts"],"names":[],"mappings":"ACEA;IAAA;IAQA,CAAC;IAHC,2BAAU,GAAV;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC;IACH,aAAC;AAAD,CAAC,AARD,IAQC;ACVD;IAAA;IAQA,CAAC;IANQ,qBAAa,GAApB,UAAqB,SAAiB;QAEpC,IAAM,YAAY,GAAuC,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC5F,OAAO,YAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;IAEH,cAAC;AAAD,CAAC,AARD,IAQC;AEND;IAAA;QAEU,YAAO,GAAa,EAAE,CAAC;IAmBjC,CAAC;IAjBC,8BAAS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GAAW,IAAI,MAAM,EAAE,CAAC;IACpC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAElD,IAAM,YAAY,GAAW,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;IAC3E,IAAM,MAAM,GAAW,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/D,OAAO,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,WAAW,EAAE,CAAC;AACxB,CAAC,CAAC,CAAC;AAGH,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE;IAC9D,OAAO,CAAC,cAAc,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 8141e29..089f293 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,22 +1,22 @@ module.exports = { - entry: './app/app.ts', - devtool: 'inline-source-map', - mode: 'development', - module: { - rules: [ - { - test: /\.tsx?$/, - use: 'ts-loader', - exclude: /node_modules/ - } - ] - }, - resolve: { - extensions: [ '.tsx', '.ts', '.js' ] - }, - output: { - filename: 'bundle.js' - }, + entry: './js/app.js', + // devtool: 'inline-source-map', + // mode: 'development', + // module: { + // rules: [ + // { + // test: /\.tsx?$/, + // use: 'ts-loader', + // exclude: /node_modules/ + // } + // ] + // }, + // resolve: { + // extensions: [ '.tsx', '.ts', '.js' ] + // }, + // output: { + // filename: 'bundle.js' + // }, devServer: { inline: false } From 729fd77df1aac76ddfad753504c0c13d533eec7b Mon Sep 17 00:00:00 2001 From: Brice Wilson Date: Fri, 26 Feb 2021 12:42:12 -0500 Subject: [PATCH 10/10] code for m6 --- app/app.ts | 11 ++--- app/game.ts | 14 +++--- app/person.ts | 2 +- app/player.ts | 4 +- app/result.ts | 2 +- app/scoreboard.ts | 4 +- app/tsconfig.json | 4 +- app/utility.ts | 14 +++--- index.html | 2 +- js/app.js | 92 +++++----------------------------------- js/app.js.map | 2 +- js/game.js | 47 ++++++++++++++++++++ js/game.js.map | 1 + js/modules/person.js | 3 ++ js/modules/person.js.map | 1 + js/person.js | 3 ++ js/person.js.map | 1 + js/player.js | 13 ++++++ js/player.js.map | 1 + js/result.js | 3 ++ js/result.js.map | 1 + js/scoreboard.js | 25 +++++++++++ js/scoreboard.js.map | 1 + js/utility.js | 13 ++++++ js/utility.js.map | 1 + webpack.config.js | 36 ++++++++-------- 26 files changed, 174 insertions(+), 127 deletions(-) create mode 100644 js/game.js create mode 100644 js/game.js.map create mode 100644 js/modules/person.js create mode 100644 js/modules/person.js.map create mode 100644 js/person.js create mode 100644 js/person.js.map create mode 100644 js/player.js create mode 100644 js/player.js.map create mode 100644 js/result.js create mode 100644 js/result.js.map create mode 100644 js/scoreboard.js create mode 100644 js/scoreboard.js.map create mode 100644 js/utility.js create mode 100644 js/utility.js.map diff --git a/app/app.ts b/app/app.ts index 3b01dbb..e5fcd9d 100644 --- a/app/app.ts +++ b/app/app.ts @@ -1,15 +1,16 @@ -/// -/// +import { Player } from './player'; +import { Game } from './game'; +import * as Helpers from './utility'; let newGame: Game; // add click handler to the start game button document.getElementById('startGame')!.addEventListener('click', () => { const player: Player = new Player(); - player.name = Utility.getInputValue('playername'); + player.name = Helpers.getValue('playername'); - const problemCount: number = Number(Utility.getInputValue('problemCount')); - const factor: number = Number(Utility.getInputValue('factor')); + const problemCount: number = Number(Helpers.getValue('problemCount')); + const factor: number = Number(Helpers.getValue('factor')); newGame = new Game(player, problemCount, factor); newGame.displayGame(); diff --git a/app/game.ts b/app/game.ts index 3fb00e1..4b4d2cb 100644 --- a/app/game.ts +++ b/app/game.ts @@ -1,10 +1,10 @@ -/// -/// -/// -/// +import { getValue } from './utility'; +import { Result } from './result'; +import { Player } from './player'; +import { Scoreboard as ResultPanel } from './scoreboard'; -class Game { - private scoreboard: Scoreboard = new Scoreboard(); +export class Game { + private scoreboard: ResultPanel = new ResultPanel(); constructor(public player: Player, public problemCount: number, public factor: number) { } @@ -35,7 +35,7 @@ class Game { // loop through the text boxes and calculate the number that are correct for (let i = 1; i <= this.problemCount; i++) { - const answer: number = Number(Utility.getInputValue('answer' + i)); + const answer: number = Number(getValue('answer' + i)); if (i * this.factor === answer) { score++; } diff --git a/app/person.ts b/app/person.ts index f6f75f7..6932f75 100644 --- a/app/person.ts +++ b/app/person.ts @@ -1,4 +1,4 @@ -interface Person { +export interface Person { name: string; age?: number; formatName: () => string; diff --git a/app/player.ts b/app/player.ts index 618a8fd..b7b7099 100644 --- a/app/player.ts +++ b/app/player.ts @@ -1,6 +1,6 @@ -/// +import { Person } from './person'; -class Player implements Person { +export class Player implements Person { name: string; age: number; highScore: number; diff --git a/app/result.ts b/app/result.ts index 4264ded..3d631f6 100644 --- a/app/result.ts +++ b/app/result.ts @@ -1,4 +1,4 @@ -interface Result { +export interface Result { playerName: string; score: number; problemCount: number; diff --git a/app/scoreboard.ts b/app/scoreboard.ts index accbb5a..b2f6fdb 100644 --- a/app/scoreboard.ts +++ b/app/scoreboard.ts @@ -1,6 +1,6 @@ -/// +import { Result } from './result'; -class Scoreboard { +export class Scoreboard { private results: Result[] = []; diff --git a/app/tsconfig.json b/app/tsconfig.json index eda1091..1c48055 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../tsconfig.base", "compilerOptions": { "removeComments": true, - "outFile": "../js/app.js" + "module": "commonjs", + "moduleResolution": "node", + "traceResolution": true }, "files": [ "./app.ts" diff --git a/app/utility.ts b/app/utility.ts index 34c8281..e41c4a1 100644 --- a/app/utility.ts +++ b/app/utility.ts @@ -1,9 +1,11 @@ -class Utility { +function getInputValue(elementID: string): string { - static getInputValue(elementID: string): string { + const inputElement: HTMLInputElement = document.getElementById(elementID); + return inputElement.value; +} - const inputElement: HTMLInputElement = document.getElementById(elementID); - return inputElement.value; - } +function logger(message: string): void { + console.log(message); +} -} \ No newline at end of file +export { getInputValue as getValue, logger } \ No newline at end of file diff --git a/index.html b/index.html index df3c776..4f52d1a 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@

No scores yet

- + diff --git a/js/app.js b/js/app.js index 51d5b3b..a5e0077 100644 --- a/js/app.js +++ b/js/app.js @@ -1,87 +1,15 @@ -var Player = (function () { - function Player() { - } - Player.prototype.formatName = function () { - return this.name.toUpperCase(); - }; - return Player; -}()); -var Utility = (function () { - function Utility() { - } - Utility.getInputValue = function (elementID) { - var inputElement = document.getElementById(elementID); - return inputElement.value; - }; - return Utility; -}()); -var Scoreboard = (function () { - function Scoreboard() { - this.results = []; - } - Scoreboard.prototype.addResult = function (newResult) { - this.results.push(newResult); - }; - Scoreboard.prototype.updateScoreboard = function () { - var output = '

Scoreboard

'; - for (var index = 0; index < this.results.length; index++) { - var result = this.results[index]; - output += '

'; - output += result.playerName + ': ' + result.score + '/' + result.problemCount + ' for factor ' + result.factor; - output += '

'; - } - var scoresElement = document.getElementById('scores'); - scoresElement.innerHTML = output; - }; - return Scoreboard; -}()); -var Game = (function () { - function Game(player, problemCount, factor) { - this.player = player; - this.problemCount = problemCount; - this.factor = factor; - this.scoreboard = new Scoreboard(); - } - Game.prototype.displayGame = function () { - var gameForm = ''; - for (var i = 1; i <= this.problemCount; i++) { - gameForm += '
'; - gameForm += ''; - gameForm += '
'; - gameForm += '
'; - } - var gameElement = document.getElementById('game'); - gameElement.innerHTML = gameForm; - document.getElementById('calculate').removeAttribute('disabled'); - }; - Game.prototype.calculateScore = function () { - var score = 0; - for (var i = 1; i <= this.problemCount; i++) { - var answer = Number(Utility.getInputValue('answer' + i)); - if (i * this.factor === answer) { - score++; - } - } - var result = { - playerName: this.player.name, - score: score, - problemCount: this.problemCount, - factor: this.factor - }; - this.scoreboard.addResult(result); - this.scoreboard.updateScoreboard(); - document.getElementById('calculate').setAttribute('disabled', 'true'); - }; - return Game; -}()); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var player_1 = require("./player"); +var game_1 = require("./game"); +var Helpers = require("./utility"); var newGame; document.getElementById('startGame').addEventListener('click', function () { - var player = new Player(); - player.name = Utility.getInputValue('playername'); - var problemCount = Number(Utility.getInputValue('problemCount')); - var factor = Number(Utility.getInputValue('factor')); - newGame = new Game(player, problemCount, factor); + var player = new player_1.Player(); + player.name = Helpers.getValue('playername'); + var problemCount = Number(Helpers.getValue('problemCount')); + var factor = Number(Helpers.getValue('factor')); + newGame = new game_1.Game(player, problemCount, factor); newGame.displayGame(); }); document.getElementById('calculate').addEventListener('click', function () { diff --git a/js/app.js.map b/js/app.js.map index e8a2d58..a6b722a 100644 --- a/js/app.js.map +++ b/js/app.js.map @@ -1 +1 @@ -{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/person.ts","../app/player.ts","../app/utility.ts","../app/result.ts","../app/scoreboard.ts","../app/game.ts","../app/app.ts"],"names":[],"mappings":"ACEA;IAAA;IAQA,CAAC;IAHC,2BAAU,GAAV;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC;IACH,aAAC;AAAD,CAAC,AARD,IAQC;ACVD;IAAA;IAQA,CAAC;IANQ,qBAAa,GAApB,UAAqB,SAAiB;QAEpC,IAAM,YAAY,GAAuC,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC5F,OAAO,YAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;IAEH,cAAC;AAAD,CAAC,AARD,IAQC;AEND;IAAA;QAEU,YAAO,GAAa,EAAE,CAAC;IAmBjC,CAAC;IAjBC,8BAAS,GAAT,UAAU,SAAiB;QACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,qCAAgB,GAAhB;QACE,IAAI,MAAM,GAAW,qBAAqB,CAAC;QAE3C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAA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,GAAW,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/D,OAAO,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,WAAW,EAAE,CAAC;AACxB,CAAC,CAAC,CAAC;AAGH,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE;IAC9D,OAAO,CAAC,cAAc,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"app.js","sourceRoot":"","sources":["../app/app.ts"],"names":[],"mappings":";;AAAA,mCAAkC;AAClC,+BAA8B;AAC9B,mCAAqC;AAErC,IAAI,OAAa,CAAC;AAGlB,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE;IAC9D,IAAM,MAAM,GAAW,IAAI,eAAM,EAAE,CAAC;IACpC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAE7C,IAAM,YAAY,GAAW,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;IACtE,IAAM,MAAM,GAAW,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE1D,OAAO,GAAG,IAAI,WAAI,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,WAAW,EAAE,CAAC;AACxB,CAAC,CAAC,CAAC;AAGH,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE;IAC9D,OAAO,CAAC,cAAc,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/js/game.js b/js/game.js new file mode 100644 index 0000000..cf1a41d --- /dev/null +++ b/js/game.js @@ -0,0 +1,47 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Game = void 0; +var utility_1 = require("./utility"); +var scoreboard_1 = require("./scoreboard"); +var Game = (function () { + function Game(player, problemCount, factor) { + this.player = player; + this.problemCount = problemCount; + this.factor = factor; + this.scoreboard = new scoreboard_1.Scoreboard(); + } + Game.prototype.displayGame = function () { + var gameForm = ''; + for (var i = 1; i <= this.problemCount; i++) { + gameForm += '
'; + gameForm += ''; + gameForm += '
'; + gameForm += '
'; + } + var gameElement = document.getElementById('game'); + gameElement.innerHTML = gameForm; + document.getElementById('calculate').removeAttribute('disabled'); + }; + Game.prototype.calculateScore = function () { + var score = 0; + for (var i = 1; i <= this.problemCount; i++) { + var answer = Number(utility_1.getValue('answer' + i)); + if (i * this.factor === answer) { + score++; + } + } + var result = { + playerName: this.player.name, + score: score, + problemCount: this.problemCount, + factor: this.factor + }; + this.scoreboard.addResult(result); + this.scoreboard.updateScoreboard(); + document.getElementById('calculate').setAttribute('disabled', 'true'); + }; + return Game; +}()); +exports.Game = Game; +//# sourceMappingURL=game.js.map \ No newline at end of file diff --git a/js/game.js.map b/js/game.js.map new file mode 100644 index 0000000..c5de2dd --- /dev/null +++ b/js/game.js.map @@ -0,0 +1 @@ +{"version":3,"file":"game.js","sourceRoot":"","sources":["../app/game.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAGrC,2CAAyD;AAEzD;IAGE,cAAmB,MAAc,EAAS,YAAoB,EAAS,MAAc;QAAlE,WAAM,GAAN,MAAM,CAAQ;QAAS,iBAAY,GAAZ,YAAY,CAAQ;QAAS,WAAM,GAAN,MAAM,CAAQ;QAF7E,eAAU,GAAgB,IAAI,uBAAW,EAAE,CAAC;IAGpD,CAAC;IAED,0BAAW,GAAX;QAGE,IAAI,QAAQ,GAAW,EAAE,CAAC;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE;YAC3C,QAAQ,IA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,CAAC,AArDD,IAqDC;AArDY,oBAAI"} \ No newline at end of file diff --git a/js/modules/person.js b/js/modules/person.js new file mode 100644 index 0000000..6851662 --- /dev/null +++ b/js/modules/person.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=person.js.map \ No newline at end of file diff --git a/js/modules/person.js.map b/js/modules/person.js.map new file mode 100644 index 0000000..1665d29 --- /dev/null +++ b/js/modules/person.js.map @@ -0,0 +1 @@ +{"version":3,"file":"person.js","sourceRoot":"","sources":["../../app/modules/person.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/js/person.js b/js/person.js new file mode 100644 index 0000000..6851662 --- /dev/null +++ b/js/person.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=person.js.map \ No newline at end of file diff --git a/js/person.js.map b/js/person.js.map new file mode 100644 index 0000000..b4dbf57 --- /dev/null +++ b/js/person.js.map @@ -0,0 +1 @@ +{"version":3,"file":"person.js","sourceRoot":"","sources":["../app/person.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/js/player.js b/js/player.js new file mode 100644 index 0000000..663a9e8 --- /dev/null +++ b/js/player.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Player = void 0; +var Player = (function () { + function Player() { + } + Player.prototype.formatName = function () { + return this.name.toUpperCase(); + }; + return Player; +}()); +exports.Player = Player; +//# sourceMappingURL=player.js.map \ No newline at end of file diff --git a/js/player.js.map b/js/player.js.map new file mode 100644 index 0000000..6bde91b --- /dev/null +++ b/js/player.js.map @@ -0,0 +1 @@ +{"version":3,"file":"player.js","sourceRoot":"","sources":["../app/player.ts"],"names":[],"mappings":";;;AAEA;IAAA;IAQA,CAAC;IAHC,2BAAU,GAAV;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC;IACH,aAAC;AAAD,CAAC,AARD,IAQC;AARY,wBAAM"} \ No newline at end of file diff --git a/js/result.js b/js/result.js new file mode 100644 index 0000000..597898e --- /dev/null +++ b/js/result.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=result.js.map \ No newline at end of file diff --git a/js/result.js.map b/js/result.js.map new file mode 100644 index 0000000..f4a66e9 --- /dev/null +++ b/js/result.js.map @@ -0,0 +1 @@ +{"version":3,"file":"result.js","sourceRoot":"","sources":["../app/result.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/js/scoreboard.js b/js/scoreboard.js new file mode 100644 index 0000000..83618ef --- /dev/null +++ b/js/scoreboard.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Scoreboard = void 0; +var Scoreboard = (function () { + function Scoreboard() { + this.results = []; + } + Scoreboard.prototype.addResult = function (newResult) { + this.results.push(newResult); + }; + Scoreboard.prototype.updateScoreboard = function () { + var output = '

Scoreboard

'; + for (var index = 0; index < this.results.length; index++) { + var result = this.results[index]; + output += '

'; + output += result.playerName + ': ' + result.score + '/' + result.problemCount + ' for factor ' + result.factor; + output += '

'; + } + var scoresElement = document.getElementById('scores'); + scoresElement.innerHTML = output; + }; + return Scoreboard; +}()); +exports.Scoreboard = Scoreboard; +//# sourceMappingURL=scoreboard.js.map \ No newline at end of file diff --git a/js/scoreboard.js.map b/js/scoreboard.js.map new file mode 100644 index 0000000..5c47fe0 --- /dev/null +++ b/js/scoreboard.js.map @@ -0,0 +1 @@ +{"version":3,"file":"scoreboard.js","sourceRoot":"","sources":["../app/scoreboard.ts"],"names":[],"mappings":";;;AAEA;IAAA;QAEU,YAAO,GAAa,EAAE,CAAC;IAmBjC,CAAC;IAjBC,8BAAS,GAAT,UAAU,SAAiB;QACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,qCAAgB,GAAhB;QACE,IAAI,MAAM,GAAW,qBAAqB,CAAC;QAE3C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACxD,IAAM,MAAM,GAAW,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC3C,MAAM,IAAI,MAAM,CAAC;YACjB,MAAM,IAAI,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,MAAM,CAAC,KAAK,GAAG,GAAG,GAAG,MAAM,CAAC,YAAY,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;YAC/G,MAAM,IAAI,OAAO,CAAC;SACnB;QAED,IAAM,aAAa,GAAgB,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAE,CAAC;QACtE,aAAa,CAAC,SAAS,GAAG,MAAM,CAAC;IACnC,CAAC;IACH,iBAAC;AAAD,CAAC,AArBD,IAqBC;AArBY,gCAAU"} \ No newline at end of file diff --git a/js/utility.js b/js/utility.js new file mode 100644 index 0000000..487a0d5 --- /dev/null +++ b/js/utility.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.logger = exports.getValue = void 0; +function getInputValue(elementID) { + var inputElement = document.getElementById(elementID); + return inputElement.value; +} +exports.getValue = getInputValue; +function logger(message) { + console.log(message); +} +exports.logger = logger; +//# sourceMappingURL=utility.js.map \ No newline at end of file diff --git a/js/utility.js.map b/js/utility.js.map new file mode 100644 index 0000000..b5a004c --- /dev/null +++ b/js/utility.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utility.js","sourceRoot":"","sources":["../app/utility.ts"],"names":[],"mappings":";;;AAAA,SAAS,aAAa,CAAC,SAAiB;IAEtC,IAAM,YAAY,GAAuC,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC5F,OAAO,YAAY,CAAC,KAAK,CAAC;AAC5B,CAAC;AAMyB,iCAAQ;AAJlC,SAAS,MAAM,CAAC,OAAe;IAC7B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC;AAEmC,wBAAM"} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 089f293..8141e29 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,22 +1,22 @@ module.exports = { - entry: './js/app.js', - // devtool: 'inline-source-map', - // mode: 'development', - // module: { - // rules: [ - // { - // test: /\.tsx?$/, - // use: 'ts-loader', - // exclude: /node_modules/ - // } - // ] - // }, - // resolve: { - // extensions: [ '.tsx', '.ts', '.js' ] - // }, - // output: { - // filename: 'bundle.js' - // }, + entry: './app/app.ts', + devtool: 'inline-source-map', + mode: 'development', + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/ + } + ] + }, + resolve: { + extensions: [ '.tsx', '.ts', '.js' ] + }, + output: { + filename: 'bundle.js' + }, devServer: { inline: false }