From 779be65cf65daeb0a20e7601845d84bb6e35763b Mon Sep 17 00:00:00 2001 From: Omoor Date: Sun, 29 Oct 2023 12:32:30 +0200 Subject: [PATCH 1/9] [#65] Added colors for different logs --- .eslintrc.json | 122 +++---- .github/workflows/checkin.yml | 4 +- .github/workflows/commit-message-checker.yml | 10 +- .github/workflows/style-checker.yml | 4 +- LICENSE.md | 366 +++++++++---------- README.md | 18 +- development/src/board.ts | 64 ++-- development/src/boards.ts | 40 +- development/src/events.ts | 48 +-- development/src/game.ts | 32 +- development/src/items.ts | 51 +-- development/src/logger.ts | 23 +- development/src/logic.ts | 87 ++--- development/src/pieces.ts | 129 ++++--- development/src/players.ts | 2 +- development/src/rules.ts | 39 +- development/views/index.html | 2 +- jest.config.ts | 8 +- 18 files changed, 559 insertions(+), 490 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 80638608..4cbef6cc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,61 +1,61 @@ -{ - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier" - ], - "overrides": [ - { - "env": { - "node": true - }, - "files": [".eslintrc.{js,cjs}"], - "parserOptions": { - "sourceType": "script" - } - } - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": ["@typescript-eslint"], - "rules": { - "indent": [ - "error", - 2, - { - "SwitchCase": 1, - "offsetTernaryExpressions": true - } - ], - "quotes": ["error", "single"], - "semi": ["error", "always"], - "prefer-const": ["error"], - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": [ - "error", - { - "vars": "all", - "varsIgnorePattern": "_", - "argsIgnorePattern": "_", - "caughtErrorsIgnorePattern": "_" - } - ], - "no-unneeded-ternary": ["error"], - "max-len": [ - "warn", - { - "ignoreComments": true, - "ignoreStrings": true - } - ], - "comma-dangle": ["error", "always-multiline"], - "camelcase": ["error"] - } -} \ No newline at end of file +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "overrides": [ + { + "env": { + "node": true + }, + "files": [".eslintrc.{js,cjs}"], + "parserOptions": { + "sourceType": "script" + } + } + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["@typescript-eslint"], + "rules": { + "indent": [ + "error", + 2, + { + "SwitchCase": 1, + "offsetTernaryExpressions": true + } + ], + "quotes": ["error", "single"], + "semi": ["error", "always"], + "prefer-const": ["error"], + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + "vars": "all", + "varsIgnorePattern": "_", + "argsIgnorePattern": "_", + "caughtErrorsIgnorePattern": "_" + } + ], + "no-unneeded-ternary": ["error"], + "max-len": [ + "warn", + { + "ignoreComments": true, + "ignoreStrings": true + } + ], + "comma-dangle": ["error", "always-multiline"], + "camelcase": ["error"] + } +} diff --git a/.github/workflows/checkin.yml b/.github/workflows/checkin.yml index 7563e179..e03ae678 100644 --- a/.github/workflows/checkin.yml +++ b/.github/workflows/checkin.yml @@ -1,5 +1,5 @@ -name: '[🔨] Checkin' -run-name: '[🔨] Checkin: ${{ github.ref }}' +name: "[🔨] Checkin" +run-name: "[🔨] Checkin: ${{ github.ref }}" on: workflow_dispatch: pull_request: diff --git a/.github/workflows/commit-message-checker.yml b/.github/workflows/commit-message-checker.yml index 6342656c..68f2a887 100644 --- a/.github/workflows/commit-message-checker.yml +++ b/.github/workflows/commit-message-checker.yml @@ -1,5 +1,5 @@ -name: '[📒] Commit Message Checker' -run-name: '[📒] Commit Message Checker: ${{ github.ref }}' +name: "[📒] Commit Message Checker" +run-name: "[📒] Commit Message Checker: ${{ github.ref }}" on: pull_request: types: @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Get PR Commits - id: 'get-pr-commits' + id: "get-pr-commits" uses: tim-actions/get-pr-commits@master with: token: ${{ secrets.GITHUB_TOKEN }} @@ -23,11 +23,11 @@ jobs: with: commits: ${{ steps.get-pr-commits.outputs.commits }} pattern: '^.{0,75}(\n.*)*$' - error: 'Subject too long (max 75)' + error: "Subject too long (max 75)" - name: Check Syntax uses: tim-actions/commit-message-checker-with-regex@v0.3.1 with: commits: ${{ steps.get-pr-commits.outputs.commits }} pattern: '\[#\d+\] [a-zA-Z]+|\[trivial\] [a-zA-Z]+|Merge [a-zA-Z]+' error: 'Commit messages must start with an issue number. For example "[#21] MESSAGE" or "[trivial] MESSAGE" or "Merge MESSAGE".' - one_pass_all_pass: 'false' + one_pass_all_pass: "false" diff --git a/.github/workflows/style-checker.yml b/.github/workflows/style-checker.yml index 5548cdae..2cdbac7b 100644 --- a/.github/workflows/style-checker.yml +++ b/.github/workflows/style-checker.yml @@ -1,5 +1,5 @@ -name: '[🎨] Style Checker' -run-name: '[🎨] Style Checker: ${{ github.ref }}' +name: "[🎨] Style Checker" +run-name: "[🎨] Style Checker: ${{ github.ref }}" on: workflow_dispatch: pull_request: diff --git a/LICENSE.md b/LICENSE.md index 261eeb9e..c61b6639 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,180 +2,180 @@ Version 2.0, January 2004 http://www.apache.org/licenses/ - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" @@ -186,16 +186,16 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] +Copyright [yyyy] [name of copyright owner] - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md index 07b1b8e3..9b1c8687 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@
+ # :notebook_with_decorative_cover: Table of Contents - [About the Project](#star2-about-the-project) @@ -45,11 +46,15 @@ - [License](#warning-license) + ## :star2: About the Project + Chess But Better acts as multiple additional layers on top of your average chess game. This innovative project aims to take the timeless game of chess and infuse it with a touch of excitement, complexity, and creativity. By incorporating a set of unique features, Chess But Better offers anyone the opportunity to explore a chess experience unlike any other. + ### :dart: Features + - **Secret Rules:** The game introduces random additional rules, which remain hidden until triggered. - **Extra Pieces:** Discover unique and powerful new pieces, each with its own advantages and drawbacks. - **Items:** Make strategic use of various items on the chessboard to gain temporary advantages. @@ -58,11 +63,12 @@ Chess But Better acts as multiple additional layers on top of your average chess - **Upgrades System:** Utilize Experience Points to enhance and evolve your chess pieces into more powerful variants. - **And a lot more!** - -## :toolbox: Getting Started + +## :toolbox: Getting Started + ### :running: Run Locally Clone the project @@ -90,6 +96,7 @@ npm run start ``` + ## :wave: Contributing @@ -99,25 +106,30 @@ npm run start Contributions are always welcome! + ## :grey_question: FAQ - What is Chess But Better? + + Chess But Better is an innovative chess project that enhances the traditional game by introducing multiple extra layers of complexity on top of the rules of chess. - How can I play Chess But Better? + + You can access Chess But Better by cloning this repository and following the [setup instructions](#running-run-locally). - Is Chess But Better suitable for all skill levels? + + Yes, Chess But Better is designed to cater to players of all skill levels. Whether you're a novice or a seasoned chess enthusiast, there's something for everyone to enjoy. - Can I contribute to Chess But Better? + + Absolutely! Chess But Better is an open-source project, and we welcome contributions from developers and chess enthusiasts. - How often is Chess But Better updated with new features or content? + The frequency of updates may vary, but we are committed to regularly enhancing and expanding the project based on community feedback and contributions. - + ## :warning: License Distributed under the Apache-2.0 license. See LICENSE.txt for more information. diff --git a/development/src/board.ts b/development/src/board.ts index 521c1a07..298e9201 100644 --- a/development/src/board.ts +++ b/development/src/board.ts @@ -1,9 +1,9 @@ -import { Item } from './items'; -import { pieces } from './logic'; -import { Piece, Square } from './pieces'; +import { Item } from "./items"; +import { pieces } from "./logic"; +import { Piece, Square } from "./pieces"; -export const NOTATIONS_LETTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; -export const NOTATIONS_NUMBERS = ['8', '7', '6', '5', '4', '3', '2', '1']; +export const NOTATIONS_LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h"]; +export const NOTATIONS_NUMBERS = ["8", "7", "6", "5", "4", "3", "2", "1"]; export const BOARD_WIDTH = 8; interface ChessBoardType { @@ -36,11 +36,11 @@ export class ChessBoard implements ChessBoardType { } } - const leftNotationsContainer = document.createElement('div'); - leftNotationsContainer.id = 'left-notations-container'; + const leftNotationsContainer = document.createElement("div"); + leftNotationsContainer.id = "left-notations-container"; - const bottomNotationsContainer = document.createElement('div'); - bottomNotationsContainer.id = 'bottom-notations-container'; + const bottomNotationsContainer = document.createElement("div"); + bottomNotationsContainer.id = "bottom-notations-container"; this.boardElement.appendChild(leftNotationsContainer); this.boardElement.appendChild(bottomNotationsContainer); @@ -50,7 +50,7 @@ export class ChessBoard implements ChessBoardType { this.createNotation(NOTATIONS_LETTERS[index]); } - const isCollapsed = this.boardElement.classList.contains('collapsed'); + const isCollapsed = this.boardElement.classList.contains("collapsed"); if (!isCollapsed) { pieces.forEach((piece) => { const pieceElement = this.createPieceElement(piece); @@ -63,9 +63,9 @@ export class ChessBoard implements ChessBoardType { } createSquare(position: [number, number]) { - const squareElement = document.createElement('div'); - squareElement.classList.add('square'); - squareElement.setAttribute('square-id', position.join(',')); + const squareElement = document.createElement("div"); + squareElement.classList.add("square"); + squareElement.setAttribute("square-id", position.join(",")); const backgroundColor = this.getBackgroundColor(position); squareElement.classList.add(backgroundColor); @@ -74,20 +74,20 @@ export class ChessBoard implements ChessBoardType { } createNotation(notation: string) { - const notationElement = document.createElement('p'); - notationElement.classList.add('notation'); + const notationElement = document.createElement("p"); + notationElement.classList.add("notation"); notationElement.innerHTML = notation; if (NOTATIONS_LETTERS.includes(notation)) { - notationElement.classList.add('letter'); + notationElement.classList.add("letter"); const bottomBoardContainer = this.boardElement.querySelector( - '#bottom-notations-container', + "#bottom-notations-container", ); bottomBoardContainer!.appendChild(notationElement); } else { - notationElement.classList.add('number'); + notationElement.classList.add("number"); const leftBoardContainer = this.boardElement.querySelector( - '#left-notations-container', + "#left-notations-container", ); leftBoardContainer!.appendChild(notationElement); } @@ -101,15 +101,15 @@ export class ChessBoard implements ChessBoardType { ? this.lightSquareColor : this.darkSquareColor : isEvenColumn - ? this.darkSquareColor - : this.lightSquareColor; + ? this.darkSquareColor + : this.lightSquareColor; } createPieceElement(piece: Piece): HTMLElement { - const pieceElement = document.createElement('div'); - pieceElement.classList.add('piece'); - pieceElement.setAttribute('draggable', 'true'); - pieceElement.setAttribute('id', piece.name); + const pieceElement = document.createElement("div"); + pieceElement.classList.add("piece"); + pieceElement.setAttribute("draggable", "true"); + pieceElement.setAttribute("id", piece.name); pieceElement.classList.add(piece.player.color.toLowerCase()); @@ -119,9 +119,9 @@ export class ChessBoard implements ChessBoardType { } createItemElement(item: Item): HTMLElement { - const itemElement = document.createElement('div'); - itemElement.classList.add('item'); - itemElement.setAttribute('id', item.name); + const itemElement = document.createElement("div"); + itemElement.classList.add("item"); + itemElement.setAttribute("id", item.name); itemElement.classList.add(item.player.color.toLowerCase()); @@ -132,13 +132,13 @@ export class ChessBoard implements ChessBoardType { movePieceOnBoard(draggedPiece: Piece, targetSquare: Square) { const draggedPieceSquareElement = this.boardElement.querySelector( - `[square-id="${draggedPiece.position.coordinates.join(',')}"]`, + `[square-id="${draggedPiece.position.coordinates.join(",")}"]`, ) as HTMLElement; const draggedPieceElement = draggedPieceSquareElement?.firstElementChild as HTMLElement; const targetSquareElement = this.boardElement.querySelector( - `[square-id="${targetSquare.position.coordinates.join(',')}"]`, + `[square-id="${targetSquare.position.coordinates.join(",")}"]`, ) as HTMLElement; targetSquareElement.appendChild(draggedPieceElement); @@ -146,7 +146,7 @@ export class ChessBoard implements ChessBoardType { destroyPieceOnBoard(targetPiece: Piece) { const targetPieceSquareElement = this.boardElement.querySelector( - `[square-id="${targetPiece.position.coordinates.join(',')}"]`, + `[square-id="${targetPiece.position.coordinates.join(",")}"]`, ); const targetPieceElement = targetPieceSquareElement?.firstElementChild as HTMLElement; @@ -156,7 +156,7 @@ export class ChessBoard implements ChessBoardType { destroyItemOnBoard(targetItem: Item) { const targetItemSquareElement = this.boardElement.querySelector( - `[square-id="${targetItem.position.coordinates!.join(',')}"]`, + `[square-id="${targetItem.position.coordinates!.join(",")}"]`, ); const targetItemElement = targetItemSquareElement?.firstElementChild as HTMLElement; diff --git a/development/src/boards.ts b/development/src/boards.ts index 4325f3f9..ae57f1f0 100644 --- a/development/src/boards.ts +++ b/development/src/boards.ts @@ -1,14 +1,14 @@ -import { ChessBoard } from './board'; -import { Item } from './items'; -import { Piece, Square } from './pieces'; +import { ChessBoard } from "./board"; +import { Item } from "./items"; +import { Piece, Square } from "./pieces"; let overworld: ChessBoard; let hell: ChessBoard; let heaven: ChessBoard; -export const OVERWORLD_BOARD_ID = 'board-overworld'; -export const HELL_BOARD_ID = 'board-hell'; -export const HEAVEN_BOARD_ID = 'board-heaven'; +export const OVERWORLD_BOARD_ID = "board-overworld"; +export const HELL_BOARD_ID = "board-hell"; +export const HEAVEN_BOARD_ID = "board-heaven"; export const OVERWORLD_BOARD = document.getElementById( OVERWORLD_BOARD_ID, @@ -19,18 +19,18 @@ export const HEAVEN_BOARD = document.getElementById( ) as HTMLElement; const HELL_BOARD_BUTTON = document.getElementById( - 'board-hell-button', + "board-hell-button", ) as HTMLElement; const HEAVEN_BOARD_BUTTON = document.getElementById( - 'board-heaven-button', + "board-heaven-button", ) as HTMLElement; -const lightOverworldSquareColor = 'beige-background'; -const darkOverworldSquareColor = 'brown-background'; -const lightHellSquareColor = 'dark-orange-background'; -const darkHellSquareColor = 'dark-red-background'; -const lightHeavenSquareColor = 'water-background'; -const darkHeavenSquareColor = 'blue-background'; +const lightOverworldSquareColor = "beige-background"; +const darkOverworldSquareColor = "brown-background"; +const lightHellSquareColor = "dark-orange-background"; +const darkHellSquareColor = "dark-red-background"; +const lightHeavenSquareColor = "water-background"; +const darkHeavenSquareColor = "blue-background"; export function initializeBoards() { overworld = new ChessBoard( @@ -91,11 +91,11 @@ export function spawnPieceOnBoard(piece: Piece) { switch (piece.position.board) { case HELL_BOARD_ID: hell.spawnPieceOnBoard(piece); - HELL_BOARD_BUTTON.classList.remove('collapsed'); + HELL_BOARD_BUTTON.classList.remove("collapsed"); break; case HEAVEN_BOARD_ID: heaven.spawnPieceOnBoard(piece); - HEAVEN_BOARD_BUTTON.classList.remove('collapsed'); + HEAVEN_BOARD_BUTTON.classList.remove("collapsed"); break; default: return; @@ -119,14 +119,14 @@ export function spawnItemOnBoard(item: Item) { } export function highlightSquare(target: HTMLElement, shouldHighlight: boolean) { - while (!target.classList.contains('square')) { + while (!target.classList.contains("square")) { target = target.parentNode as HTMLElement; } - if (target.classList.contains('square')) { + if (target.classList.contains("square")) { if (shouldHighlight) { - target.classList.add('light-gray-background'); + target.classList.add("light-gray-background"); } else { - target.classList.remove('light-gray-background'); + target.classList.remove("light-gray-background"); } } } diff --git a/development/src/events.ts b/development/src/events.ts index cc2ccc3c..2d4e1da0 100644 --- a/development/src/events.ts +++ b/development/src/events.ts @@ -1,4 +1,4 @@ -import { HEAVEN_BOARD, HELL_BOARD, OVERWORLD_BOARD } from './boards'; +import { HEAVEN_BOARD, HELL_BOARD, OVERWORLD_BOARD } from "./boards"; let draggedElement: HTMLElement; @@ -12,36 +12,38 @@ let triggerOnFallOffTheBoard: ( board: string, ) => void; -const OVERWORLD_BOARD_BUTTON = document.getElementById('board-overworld-button')!; -const HELL_BOARD_BUTTON = document.getElementById('board-hell-button')!; -const HEAVEN_BOARD_BUTTON = document.getElementById('board-heaven-button')!; +const OVERWORLD_BOARD_BUTTON = document.getElementById( + "board-overworld-button", +)!; +const HELL_BOARD_BUTTON = document.getElementById("board-hell-button")!; +const HEAVEN_BOARD_BUTTON = document.getElementById("board-heaven-button")!; let triggerOnHighlight: (target: HTMLElement, shouldHighlight: boolean) => void; export function initializeEventListeners() { - const squares = document.querySelectorAll('.square'); + const squares = document.querySelectorAll(".square"); // Listen for mouse events squares.forEach((square) => { - square.addEventListener('dragstart', onDragStart); - square.addEventListener('dragover', onDragOver); - square.addEventListener('drop', onDragDrop); - square.addEventListener('mouseover', onMouseOver); - square.addEventListener('mouseout', onMouseOut); + square.addEventListener("dragstart", onDragStart); + square.addEventListener("dragover", onDragOver); + square.addEventListener("drop", onDragDrop); + square.addEventListener("mouseover", onMouseOver); + square.addEventListener("mouseout", onMouseOut); }); // Support pieces falling off the board - document.body.addEventListener('dragover', onDragOver); - document.body.addEventListener('drop', onDragOffTheBoard); + document.body.addEventListener("dragover", onDragOver); + document.body.addEventListener("drop", onDragOffTheBoard); // Listen for boards' buttons clicks - OVERWORLD_BOARD_BUTTON.addEventListener('click', handleButtonPress); - HELL_BOARD_BUTTON.addEventListener('click', handleButtonPress); - HEAVEN_BOARD_BUTTON.addEventListener('click', handleButtonPress); + OVERWORLD_BOARD_BUTTON.addEventListener("click", handleButtonPress); + HELL_BOARD_BUTTON.addEventListener("click", handleButtonPress); + HEAVEN_BOARD_BUTTON.addEventListener("click", handleButtonPress); } function onDragStart(event: Event) { const targetElement = event.target as HTMLElement; - if (targetElement.classList.contains('piece')) { + if (targetElement.classList.contains("piece")) { draggedElement = event.target as HTMLElement; } } @@ -50,12 +52,12 @@ function onDragDrop(event: Event) { event.stopPropagation(); let targetElement = event.target as HTMLElement; // Make sure target is not a resource - while (targetElement.classList.contains('untargetable')) { + while (targetElement.classList.contains("untargetable")) { targetElement = targetElement.parentNode as HTMLElement; } let board = targetElement as HTMLElement; - while (!board.classList.contains('board')) { + while (!board.classList.contains("board")) { board = board.parentNode as HTMLElement; } @@ -68,7 +70,7 @@ function onDragOver(event: Event) { function onDragOffTheBoard(_: Event) { let board = draggedElement; - while (!board.classList.contains('board')) { + while (!board.classList.contains("board")) { board = board.parentNode as HTMLElement; } @@ -116,11 +118,11 @@ export function setOnHighlight( function showBoard(boardId: string) { const boardElement = document.getElementById(boardId) as HTMLElement; - OVERWORLD_BOARD.classList.add('collapsed'); - HELL_BOARD.classList.add('collapsed'); - HEAVEN_BOARD.classList.add('collapsed'); + OVERWORLD_BOARD.classList.add("collapsed"); + HELL_BOARD.classList.add("collapsed"); + HEAVEN_BOARD.classList.add("collapsed"); - boardElement.classList.remove('collapsed'); + boardElement.classList.remove("collapsed"); } export function handleButtonPress(event: Event) { diff --git a/development/src/game.ts b/development/src/game.ts index 36dcafcc..939958f0 100644 --- a/development/src/game.ts +++ b/development/src/game.ts @@ -1,39 +1,39 @@ -import { Logger } from './logger'; +import { Logger } from "./logger"; import { initializeEventListeners, setOnAction, setOnFallOffTheBoard, setOnHighlight, -} from './events'; -import { highlightSquare, initializeBoards } from './boards'; +} from "./events"; +import { highlightSquare, initializeBoards } from "./boards"; import { onAction, onFallOffTheBoard, getCurrentPlayer, players, roundCounter, -} from './logic'; -import { Rule } from './rules'; +} from "./logic"; +import { Rule } from "./rules"; -const infoDisplay = document.getElementById('info-display')!; -const rulesContainer = document.getElementById('rules-container')!; +const infoDisplay = document.getElementById("info-display")!; +const rulesContainer = document.getElementById("rules-container")!; export function updatePlayersInformation() { - infoDisplay.textContent = ''; + infoDisplay.textContent = ""; - const roundElement = document.createElement('p'); + const roundElement = document.createElement("p"); roundElement.innerHTML = `Round: ${roundCounter}`; infoDisplay.appendChild(roundElement); - const playersElement = document.createElement('p'); - playersElement.innerHTML = 'Players:'; + const playersElement = document.createElement("p"); + playersElement.innerHTML = "Players:"; players.forEach((player) => { - const playerInformationElement = document.createElement('div'); + const playerInformationElement = document.createElement("div"); - const statusElement = document.createElement('p'); + const statusElement = document.createElement("p"); const isCurrentPlayer = getCurrentPlayer() === player; - const title = `${isCurrentPlayer ? '> ' : ''} ${player.color} Player:`; + const title = `${isCurrentPlayer ? "> " : ""} ${player.color} Player:`; const status = `${title} ${player.xp} XP; ${player.gold} Gold.`; statusElement.innerHTML = status; @@ -49,13 +49,13 @@ export function updatePlayersInformation() { } export function updateRules(rule: Rule) { - const ruleElement = document.createElement('p'); + const ruleElement = document.createElement("p"); ruleElement.innerHTML = `${rule.id + 1}) ${rule.description}`; rulesContainer.appendChild(ruleElement); } function initializeGame() { - Logger.log('Game started!'); + Logger.log("Game started!", "black"); initializeBoards(); initializeEventListeners(); updatePlayersInformation(); diff --git a/development/src/items.ts b/development/src/items.ts index b0141009..f60e63e2 100644 --- a/development/src/items.ts +++ b/development/src/items.ts @@ -1,30 +1,31 @@ -import { spawnItemOnBoard } from './boards'; -import { Logger } from './logger'; -import { items } from './logic'; -import { Piece, Position } from './pieces'; -import { Player } from './players'; -import { trapResource } from './resources'; +import { spawnItemOnBoard } from "./boards"; +import { Logger } from "./logger"; +import { items } from "./logic"; +import { Piece, Position } from "./pieces"; +import { Player } from "./players"; +import { trapResource } from "./resources"; + +const logColor = "green"; export class Inventory { items: Array = []; - addItem(item: Item) { this.items.push(item); - Logger.log(`${item.player.color} received a ${item.name}.`); + Logger.log(`${item.player.color} received a ${item.name}.`, logColor); } removeItem(item: Item) { const index = this.items.indexOf(item); if (index !== -1) { this.items.splice(index, 1); - Logger.log(`${item.name} was destroyed.`); + Logger.log(`${item.name} was destroyed.`, logColor); } } toHTMLElement(): HTMLElement { - const inventoryElement = document.createElement('ul'); + const inventoryElement = document.createElement("ul"); this.items.forEach((item) => { - const inventoryItemElement = document.createElement('li'); + const inventoryItemElement = document.createElement("li"); inventoryItemElement.innerHTML = item.name; inventoryElement.appendChild(inventoryItemElement); @@ -35,11 +36,11 @@ export class Inventory { } interface ItemType { - name: string, - resource: string, - player: Player, - position: Position, - apply: (piece: Piece) => void; + name: string; + resource: string; + player: Player; + position: Position; + apply: (piece: Piece) => void; } export class Item implements ItemType { @@ -48,7 +49,12 @@ export class Item implements ItemType { player: Player; position: Position; - constructor(name: string, resource: string, player: Player, position: Position) { + constructor( + name: string, + resource: string, + player: Player, + position: Position, + ) { this.name = name; this.resource = resource; this.player = player; @@ -56,17 +62,20 @@ export class Item implements ItemType { } apply(piece: Piece) { - Logger.log(`${piece.player.color} used a ${this.name}.`); - }; + Logger.log(`${piece.player.color} used a ${this.name}.`, logColor); + } } export class Trap extends Item { constructor(player: Player, position: Position) { - super('trap', trapResource, player, position); + super("trap", trapResource, player, position); } apply(piece: Piece) { - Logger.log(`${this.player.color} ${piece.name} placed a ${this.name} on ${piece.position.coordinates}.`); + Logger.log( + `${this.player.color} ${piece.name} placed a ${this.name} on ${piece.position.coordinates}.`, + logColor, + ); this.position = piece.position; items.push(this); diff --git a/development/src/logger.ts b/development/src/logger.ts index 143476ac..01fc106c 100644 --- a/development/src/logger.ts +++ b/development/src/logger.ts @@ -1,18 +1,25 @@ -import { NOTATIONS_LETTERS, NOTATIONS_NUMBERS } from './board'; -import { Piece, Square } from './pieces'; +import { NOTATIONS_LETTERS, NOTATIONS_NUMBERS } from "./board"; +import { Piece, Square } from "./pieces"; export class Logger { - static log(message: string) { - const logsContainer = document.getElementById('logs-container')!; - logsContainer.innerHTML += `

> ${message}

`; + static log(message: string, color: string) { + const logsContainer = document.getElementById("logs-container")!; + logsContainer.innerHTML += `

> ${message}

`; logsContainer.scrollTop = logsContainer.scrollHeight; // Scroll to the last log } static logMovement(draggedPiece: Piece, targetSquare: Square) { - const fromNotation = this.convertPositionToNotation(draggedPiece.position.coordinates); - const toNotation = this.convertPositionToNotation(targetSquare.position.coordinates); - this.log(`${draggedPiece.player.color} ${draggedPiece.name} moved from ${fromNotation} to ${toNotation}.`); + const fromNotation = this.convertPositionToNotation( + draggedPiece.position.coordinates, + ); + const toNotation = this.convertPositionToNotation( + targetSquare.position.coordinates, + ); + this.log( + `${draggedPiece.player.color} ${draggedPiece.name} moved from ${fromNotation} to ${toNotation}.`, + "gray", + ); } private static convertPositionToNotation(position: [number, number]) { diff --git a/development/src/logic.ts b/development/src/logic.ts index 3e9102b3..80fbe9b4 100644 --- a/development/src/logic.ts +++ b/development/src/logic.ts @@ -1,4 +1,4 @@ -import { Player } from './players'; +import { Player } from "./players"; import { Piece, Pawn, @@ -9,8 +9,8 @@ import { King, Square, Position, -} from './pieces'; -import { Logger } from './logger'; +} from "./pieces"; +import { Logger } from "./logger"; import { movePieceOnBoard, destroyPieceOnBoard, @@ -19,15 +19,15 @@ import { HELL_BOARD_ID, HEAVEN_BOARD_ID, destroyItemOnBoard, -} from './boards'; -import { activeRules } from './rules'; -import { updatePlayersInformation } from './game'; -import { Item } from './items'; +} from "./boards"; +import { activeRules } from "./rules"; +import { updatePlayersInformation } from "./game"; +import { Item } from "./items"; export enum PlayerColors { - WHITE = 'White', - BLACK = 'Black', -}; + WHITE = "White", + BLACK = "Black", +} const whitePlayer = new Player(PlayerColors.WHITE); const blackPlayer = new Player(PlayerColors.BLACK); @@ -80,6 +80,9 @@ export let isPieceKilled = false; export let fellOffTheBoardPiece: Piece | undefined; +const killColor = "red"; +const castleColor = "gray"; + export function getCurrentPlayer(): Player { return players[currentPlayerIndex]; } @@ -100,9 +103,7 @@ export function switchIsCastling() { isCastling = !isCastling; } -export function getPieceByPosition( - position: Position, -): Piece | undefined { +export function getPieceByPosition(position: Position): Piece | undefined { return pieces.find((piece) => comparePositions(position, piece.position)); } @@ -115,7 +116,7 @@ export function getPieceByPositionAndBoard( } function convertSquareIdToPosition(squareId: string): [number, number] { - return squareId.split(',').map((str) => parseInt(str)) as [number, number]; + return squareId.split(",").map((str) => parseInt(str)) as [number, number]; } export function onAction( @@ -127,43 +128,39 @@ export function onAction( draggedElement.parentElement as HTMLElement; const draggedElementPosition: Position = { - coordinates: convertSquareIdToPosition(draggedElementParentElement.getAttribute('square-id')!), + coordinates: convertSquareIdToPosition( + draggedElementParentElement.getAttribute("square-id")!, + ), board: board, }; const draggedPiece: Piece | undefined = pieces.find((piece) => - comparePositions( - piece.position, - draggedElementPosition, - ), + comparePositions(piece.position, draggedElementPosition), ); - if (targetElement.classList.contains('piece')) { + if (targetElement.classList.contains("piece")) { const squareElement = targetElement.parentElement!; const targetElementPosition: Position = { coordinates: convertSquareIdToPosition( - squareElement.getAttribute('square-id')!, + squareElement.getAttribute("square-id")!, ), board: board, }; const targetPiece: Piece | undefined = pieces.find((piece) => { - return comparePositions( - targetElementPosition, - piece.position, - ); + return comparePositions(targetElementPosition, piece.position); }); actOnTurn(draggedPiece, targetPiece); - } else if (targetElement.classList.contains('item')) { + } else if (targetElement.classList.contains("item")) { let squareElement = targetElement as HTMLElement; - while (!squareElement.getAttribute('square-id')) { + while (!squareElement.getAttribute("square-id")) { squareElement = squareElement.parentElement as HTMLElement; } const itemPosition: Position = { coordinates: convertSquareIdToPosition( - squareElement.getAttribute('square-id')!, + squareElement.getAttribute("square-id")!, ), board: board, }; @@ -177,7 +174,7 @@ export function onAction( const targetSquare: Square = { position: { coordinates: convertSquareIdToPosition( - targetElement.getAttribute('square-id')!, + targetElement.getAttribute("square-id")!, ), board: board, }, @@ -191,15 +188,12 @@ export function onFallOffTheBoard(draggedElement: HTMLElement, board: string) { const squareElement = draggedElement.parentElement!; const draggedElementPosition: Position = { coordinates: convertSquareIdToPosition( - squareElement.getAttribute('square-id')!, + squareElement.getAttribute("square-id")!, ), board: board, }; - return comparePositions( - draggedElementPosition, - piece.position, - ); + return comparePositions(draggedElementPosition, piece.position); }); if (!draggedPiece) return; @@ -254,7 +248,10 @@ function actOnTurnPieceToPiece(draggedPiece: Piece, targetPiece: Piece) { destroyPieceOnBoard(targetPiece); if (targetPiece.position.board === OVERWORLD_BOARD_ID) { - Logger.log(`A ${targetPiece.player.color} ${targetPiece.name} was killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`); + Logger.log( + `A ${targetPiece.player.color} ${targetPiece.name} was killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`, + killColor, + ); if (targetPiece.hasKilled) { targetPiece.position = { @@ -283,7 +280,10 @@ function actOnTurnPieceToPiece(draggedPiece: Piece, targetPiece: Piece) { spawnPieceOnBoard(targetPiece); } else { - Logger.log(`A ${targetPiece.player.color} ${targetPiece.name} was permanently killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`); + Logger.log( + `A ${targetPiece.player.color} ${targetPiece.name} was permanently killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`, + killColor, + ); killPiece(targetPiece); } @@ -310,8 +310,10 @@ function actOnTurnPieceToTrap(draggedPiece: Piece, targetItem: Item) { destroyItemOnBoard(targetItem); if (draggedPiece.position.board === OVERWORLD_BOARD_ID) { - draggedPiece.position = {...targetItem.position}; - draggedPiece.position.board = draggedPiece.hasKilled ? HELL_BOARD_ID : HEAVEN_BOARD_ID; + draggedPiece.position = { ...targetItem.position }; + draggedPiece.position.board = draggedPiece.hasKilled + ? HELL_BOARD_ID + : HEAVEN_BOARD_ID; spawnPieceOnBoard(draggedPiece); } @@ -330,11 +332,12 @@ function castle(kingPiece: Piece, targetSquare: Square) { return ( piece.player === getCurrentPlayer() && !piece.hasMoved && - piece.name === 'Rook' + piece.name === "Rook" ); }); - const deltaX = targetSquare.position.coordinates[0] - kingPiece.position.coordinates[0]; + const deltaX = + targetSquare.position.coordinates[0] - kingPiece.position.coordinates[0]; // Depends on if it's Kingside or Queenside castling const isKingsideCastling = deltaX > 0; const rookFilter = (piece: Piece) => { @@ -359,7 +362,7 @@ function castle(kingPiece: Piece, targetSquare: Square) { const rookPieceTargetSquare: Square = { position: rookPieceTargetPosition }; move(rookPiece, rookPieceTargetSquare, false); - Logger.log(`${kingPiece.player.color} castled.`); + Logger.log(`${kingPiece.player.color} castled.`, castleColor); return true; } @@ -388,7 +391,7 @@ function endTurn() { currentPlayerIndex + 1 < players.length ? currentPlayerIndex + 1 : 0; turnCounter++; - console.log('dsadsa'); + console.log("dsadsa"); if (turnCounter % players.length === 0) { turnCounter = 0; diff --git a/development/src/pieces.ts b/development/src/pieces.ts index c9487afa..678e63bc 100644 --- a/development/src/pieces.ts +++ b/development/src/pieces.ts @@ -5,8 +5,8 @@ import { rookResource, queenResource, kingResource, -} from './resources'; -import { Player } from './players'; +} from "./resources"; +import { Player } from "./players"; import { getCurrentPlayer, switchIsCastling, @@ -14,14 +14,14 @@ import { items, comparePositions, PlayerColors, -} from './logic'; -import { OVERWORLD_BOARD_ID } from './boards'; -import { Item } from './items'; +} from "./logic"; +import { OVERWORLD_BOARD_ID } from "./boards"; +import { Item } from "./items"; export type Position = { - coordinates: [number, number], - board: string, -} + coordinates: [number, number]; + board: string; +}; interface PieceType { position: Position; @@ -80,12 +80,14 @@ export type Square = { export class Pawn extends Piece { constructor(position: Position, player: Player) { - super(position, player, pawnResource, 'Pawn'); + super(position, player, pawnResource, "Pawn"); } validateMove(target: Piece | Square) { - const deltaX = target.position.coordinates[0] - this.position.coordinates[0]; - const deltaY = target.position.coordinates[1] - this.position.coordinates[1]; + const deltaX = + target.position.coordinates[0] - this.position.coordinates[0]; + const deltaY = + target.position.coordinates[1] - this.position.coordinates[1]; const absoluteDeltaX = Math.abs(deltaX); const absoluteDeltaY = Math.abs(deltaY); @@ -94,8 +96,8 @@ export class Pawn extends Piece { target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; // Make sure pawn does not move backwards. const currentPlayer = getCurrentPlayer(); @@ -108,36 +110,40 @@ export class Pawn extends Piece { // Pawns attack diagonally. if ((target as Piece).name !== undefined) { - return absoluteDeltaY === 1 && absoluteDeltaX === 1 ? target.position : this.position; + return absoluteDeltaY === 1 && absoluteDeltaX === 1 + ? target.position + : this.position; } // Pawns can have an initial two-square move. if (!this.hasMoved && absoluteDeltaY === 2 && absoluteDeltaX === 0) { - return simulateMove( - this.copyPosition(), - target.position, - 0, - stepY, - 2, - ); + return simulateMove(this.copyPosition(), target.position, 0, stepY, 2); } // Pawns move one square forward. - return absoluteDeltaY === 1 && absoluteDeltaX === 0 ? target.position : this.position; + return absoluteDeltaY === 1 && absoluteDeltaX === 0 + ? target.position + : this.position; } } export class Bishop extends Piece { constructor(position: Position, player: Player) { - super(position, player, bishopResource, 'Bishop'); + super(position, player, bishopResource, "Bishop"); } validateMove(target: Piece | Square) { - const stepX = target.position.coordinates[0] > this.position.coordinates[0] ? 1 : -1; - const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : -1; + const stepX = + target.position.coordinates[0] > this.position.coordinates[0] ? 1 : -1; + const stepY = + target.position.coordinates[1] > this.position.coordinates[1] ? 1 : -1; - const absoluteDeltaX = Math.abs(target.position.coordinates[0] - this.position.coordinates[0]); - const absoluteDeltaY = Math.abs(target.position.coordinates[1] - this.position.coordinates[1]); + const absoluteDeltaX = Math.abs( + target.position.coordinates[0] - this.position.coordinates[0], + ); + const absoluteDeltaY = Math.abs( + target.position.coordinates[1] - this.position.coordinates[1], + ); // Bishops can only move diagonally. if (absoluteDeltaY === absoluteDeltaX) { @@ -156,21 +162,27 @@ export class Bishop extends Piece { export class Knight extends Piece { constructor(position: Position, player: Player) { - super(position, player, knightResource, 'Knight'); + super(position, player, knightResource, "Knight"); } validateMove(target: Piece | Square) { - const absoluteDeltaX = Math.abs(target.position.coordinates[0] - this.position.coordinates[0]); - const absoluteDeltaY = Math.abs(target.position.coordinates[1] - this.position.coordinates[1]); + const absoluteDeltaX = Math.abs( + target.position.coordinates[0] - this.position.coordinates[0], + ); + const absoluteDeltaY = Math.abs( + target.position.coordinates[1] - this.position.coordinates[1], + ); // Knights can move two squares in any direction and one square to the side. - return absoluteDeltaY * absoluteDeltaX === 2 ? target.position : this.position; + return absoluteDeltaY * absoluteDeltaX === 2 + ? target.position + : this.position; } } export class Rook extends Piece { constructor(position: Position, player: Player) { - super(position, player, rookResource, 'Rook'); + super(position, player, rookResource, "Rook"); } validateMove(target: Piece | Square) { @@ -178,14 +190,14 @@ export class Rook extends Piece { target.position.coordinates[0] > this.position.coordinates[0] ? 1 : target.position.coordinates[0] < this.position.coordinates[0] - ? -1 - : 0; + ? -1 + : 0; const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; // Rooks can move either vertically or horizontally but not both at the same. if ( @@ -207,7 +219,7 @@ export class Rook extends Piece { export class Queen extends Piece { constructor(position: Position, player: Player) { - super(position, player, queenResource, 'Queen'); + super(position, player, queenResource, "Queen"); } validateMove(target: Piece | Square) { @@ -215,17 +227,21 @@ export class Queen extends Piece { target.position.coordinates[0] > this.position.coordinates[0] ? 1 : target.position.coordinates[0] < this.position.coordinates[0] - ? -1 - : 0; + ? -1 + : 0; const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; - const absoluteDeltaX = Math.abs(target.position.coordinates[0] - this.position.coordinates[0]); - const absoluteDeltaY = Math.abs(target.position.coordinates[1] - this.position.coordinates[1]); + const absoluteDeltaX = Math.abs( + target.position.coordinates[0] - this.position.coordinates[0], + ); + const absoluteDeltaY = Math.abs( + target.position.coordinates[1] - this.position.coordinates[1], + ); // Queens can move vertically, horizontally or diagonally. if ( @@ -248,7 +264,7 @@ export class Queen extends Piece { export class King extends Piece { constructor(position: Position, player: Player) { - super(position, player, kingResource, 'King'); + super(position, player, kingResource, "King"); } validateMove(target: Piece | Square) { @@ -256,17 +272,19 @@ export class King extends Piece { target.position.coordinates[0] > this.position.coordinates[0] ? 1 : target.position.coordinates[0] < this.position.coordinates[0] - ? -1 - : 0; + ? -1 + : 0; const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; - const deltaX = target.position.coordinates[0] - this.position.coordinates[0]; - const deltaY = target.position.coordinates[1] - this.position.coordinates[1]; + const deltaX = + target.position.coordinates[0] - this.position.coordinates[0]; + const deltaY = + target.position.coordinates[1] - this.position.coordinates[1]; const absoluteDeltaX = Math.abs(deltaX); const absoluteDeltaY = Math.abs(deltaY); @@ -342,7 +360,10 @@ function simulateMove( limitCounter !== limit ) { const nextPosition: Position = { - coordinates: [position.coordinates[0] + stepX, position.coordinates[1] + stepY], + coordinates: [ + position.coordinates[0] + stepX, + position.coordinates[1] + stepY, + ], board: position.board, }; @@ -365,14 +386,16 @@ function simulateMove( limitCounter++; } - return comparePositions(position, targetPosition) ? targetPosition : startingPosition; + return comparePositions(position, targetPosition) + ? targetPosition + : startingPosition; } function checkIfPositionContainsTrap(position: Position): boolean { const item = items.find((item) => comparePositions(position, item.position)); if (item) { switch (item.name) { - case ('trap'): { + case "trap": { return true; } } diff --git a/development/src/players.ts b/development/src/players.ts index 394e6560..0f69ae71 100644 --- a/development/src/players.ts +++ b/development/src/players.ts @@ -1,4 +1,4 @@ -import { Inventory } from './items'; +import { Inventory } from "./items"; type PlayerType = { color: string; diff --git a/development/src/rules.ts b/development/src/rules.ts index 7fdca078..503cc45e 100644 --- a/development/src/rules.ts +++ b/development/src/rules.ts @@ -6,9 +6,11 @@ import { isFriendlyFire, roundCounter, players, -} from './logic'; -import { Logger } from './logger'; -import { updateRules } from './game'; +} from "./logic"; +import { Logger } from "./logger"; +import { updateRules } from "./game"; + +const logColor = "purple"; export class Rule { id: number; @@ -38,6 +40,7 @@ export class Rule { const player = getCurrentPlayer(); Logger.log( `${player.color} received XP for revealing a new rule: ${this.description}`, + logColor, ); player.xp++; this.isRevealed = true; @@ -53,7 +56,7 @@ const inactiveRules = []; export const activeRules = [ new Rule( 0, - 'Pieces can fall off the board.', + "Pieces can fall off the board.", false, () => { return !!fellOffTheBoardPiece; @@ -63,38 +66,45 @@ export const activeRules = [ `A ${fellOffTheBoardPiece!.player.color} ${ fellOffTheBoardPiece!.name } fell off the board.`, + logColor, ); }, ), new Rule( 1, - 'First Blood Bonus: The first to kill gets an extra XP.', + "First Blood Bonus: The first to kill gets an extra XP.", false, () => { return deathCounter == 1; }, () => { const player = getCurrentPlayer(); - Logger.log(`${player.color} has made First Blood and received a bonus.`); + Logger.log( + `${player.color} has made First Blood and received a bonus.`, + logColor, + ); player.xp++; }, ), new Rule( 2, - 'Players gain XP on a kill.', + "Players gain XP on a kill.", false, () => { return isPieceKilled; }, () => { const player = getCurrentPlayer(); - Logger.log(`${player.color} received XP for killing another piece.`); + Logger.log( + `${player.color} received XP for killing another piece.`, + logColor, + ); player.xp++; }, ), new Rule( 3, - 'Friendly Fire! Players can attack their own pieces (for a price).', + "Friendly Fire! Players can attack their own pieces (for a price).", false, () => { return isFriendlyFire; @@ -103,30 +113,32 @@ export const activeRules = [ const player = getCurrentPlayer(); Logger.log( `${player.color} attacked his own piece and has to pay compensations.`, + logColor, ); player.gold--; }, ), new Rule( 4, - 'With age comes wisdom.', + "With age comes wisdom.", false, () => { return roundCounter === 20; }, () => { Logger.log( - 'Children of war, you have grown old. Each player gains five XP.', + "Children of war, you have grown old. Each player gains five XP.", + logColor, ); players.forEach((player) => { - Logger.log(`${player.color} gained XP.`); + Logger.log(`${player.color} gained XP.`, logColor); player.xp += 5; }); }, ), new Rule( 5, - 'Empty pockets.', + "Empty pockets.", false, () => { players.forEach((player) => { @@ -141,6 +153,7 @@ export const activeRules = [ if (player === getCurrentPlayer() && player.gold < 0) { Logger.log( `${player.color} is in debt. They lose XP for not handling money properly.`, + logColor, ); player.xp--; return; diff --git a/development/views/index.html b/development/views/index.html index f344aa29..f5465c0c 100644 --- a/development/views/index.html +++ b/development/views/index.html @@ -1,4 +1,4 @@ - + diff --git a/jest.config.ts b/jest.config.ts index 9ec1189d..5f589f5c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,9 +1,9 @@ /* eslint-disable */ export default { - displayName: 'chess-but-better', - coverageDirectory: './coverage/chess-but-better', + displayName: "chess-but-better", + coverageDirectory: "./coverage/chess-but-better", testMatch: [ - '/src/**/__tests__/**/*.[jt]s?(x)', - '/src/**/*(*.)@(spec|test).[jt]s?(x)', + "/src/**/__tests__/**/*.[jt]s?(x)", + "/src/**/*(*.)@(spec|test).[jt]s?(x)", ], }; From 3f04cb263cfa128a7dbd76290011ef216693f049 Mon Sep 17 00:00:00 2001 From: Omoor Date: Sun, 29 Oct 2023 13:08:13 +0200 Subject: [PATCH 2/9] [#65] Changed how color is determined. --- development/src/game.ts | 2 +- development/src/items.ts | 11 ++++------- development/src/logger.ts | 22 ++++++++++++++++++++-- development/src/logic.ts | 11 +++-------- development/src/rules.ts | 27 ++++++++------------------- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/development/src/game.ts b/development/src/game.ts index 939958f0..7b386055 100644 --- a/development/src/game.ts +++ b/development/src/game.ts @@ -55,7 +55,7 @@ export function updateRules(rule: Rule) { } function initializeGame() { - Logger.log("Game started!", "black"); + Logger.log("Game started!"); initializeBoards(); initializeEventListeners(); updatePlayersInformation(); diff --git a/development/src/items.ts b/development/src/items.ts index f60e63e2..a34616e0 100644 --- a/development/src/items.ts +++ b/development/src/items.ts @@ -5,20 +5,18 @@ import { Piece, Position } from "./pieces"; import { Player } from "./players"; import { trapResource } from "./resources"; -const logColor = "green"; - export class Inventory { items: Array = []; addItem(item: Item) { this.items.push(item); - Logger.log(`${item.player.color} received a ${item.name}.`, logColor); + Logger.logItem(`${item.player.color} received a ${item.name}.`); } removeItem(item: Item) { const index = this.items.indexOf(item); if (index !== -1) { this.items.splice(index, 1); - Logger.log(`${item.name} was destroyed.`, logColor); + Logger.logItem(`${item.name} was destroyed.`); } } @@ -62,7 +60,7 @@ export class Item implements ItemType { } apply(piece: Piece) { - Logger.log(`${piece.player.color} used a ${this.name}.`, logColor); + Logger.logItem(`${piece.player.color} used a ${this.name}.`); } } @@ -72,9 +70,8 @@ export class Trap extends Item { } apply(piece: Piece) { - Logger.log( + Logger.logItem( `${this.player.color} ${piece.name} placed a ${this.name} on ${piece.position.coordinates}.`, - logColor, ); this.position = piece.position; diff --git a/development/src/logger.ts b/development/src/logger.ts index 01fc106c..78d394ec 100644 --- a/development/src/logger.ts +++ b/development/src/logger.ts @@ -1,14 +1,33 @@ import { NOTATIONS_LETTERS, NOTATIONS_NUMBERS } from "./board"; import { Piece, Square } from "./pieces"; +const defaultColor = "gray"; +const killColor = "red"; +const ruleColor = "purple"; +const itemColor = "green"; + export class Logger { - static log(message: string, color: string) { + static log(message: string, color?: string) { + if (!color || color == "") color = defaultColor; + const logsContainer = document.getElementById("logs-container")!; logsContainer.innerHTML += `

> ${message}

`; logsContainer.scrollTop = logsContainer.scrollHeight; // Scroll to the last log } + static logKill(message: string) { + this.log(message, killColor); + } + + static logRule(message: string) { + this.log(message, ruleColor); + } + + static logItem(message: string) { + this.log(message, itemColor); + } + static logMovement(draggedPiece: Piece, targetSquare: Square) { const fromNotation = this.convertPositionToNotation( draggedPiece.position.coordinates, @@ -18,7 +37,6 @@ export class Logger { ); this.log( `${draggedPiece.player.color} ${draggedPiece.name} moved from ${fromNotation} to ${toNotation}.`, - "gray", ); } diff --git a/development/src/logic.ts b/development/src/logic.ts index 80fbe9b4..615911a2 100644 --- a/development/src/logic.ts +++ b/development/src/logic.ts @@ -80,9 +80,6 @@ export let isPieceKilled = false; export let fellOffTheBoardPiece: Piece | undefined; -const killColor = "red"; -const castleColor = "gray"; - export function getCurrentPlayer(): Player { return players[currentPlayerIndex]; } @@ -248,9 +245,8 @@ function actOnTurnPieceToPiece(draggedPiece: Piece, targetPiece: Piece) { destroyPieceOnBoard(targetPiece); if (targetPiece.position.board === OVERWORLD_BOARD_ID) { - Logger.log( + Logger.logKill( `A ${targetPiece.player.color} ${targetPiece.name} was killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`, - killColor, ); if (targetPiece.hasKilled) { @@ -280,9 +276,8 @@ function actOnTurnPieceToPiece(draggedPiece: Piece, targetPiece: Piece) { spawnPieceOnBoard(targetPiece); } else { - Logger.log( + Logger.logKill( `A ${targetPiece.player.color} ${targetPiece.name} was permanently killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`, - killColor, ); killPiece(targetPiece); } @@ -362,7 +357,7 @@ function castle(kingPiece: Piece, targetSquare: Square) { const rookPieceTargetSquare: Square = { position: rookPieceTargetPosition }; move(rookPiece, rookPieceTargetSquare, false); - Logger.log(`${kingPiece.player.color} castled.`, castleColor); + Logger.log(`${kingPiece.player.color} castled.`); return true; } diff --git a/development/src/rules.ts b/development/src/rules.ts index 503cc45e..a03007d5 100644 --- a/development/src/rules.ts +++ b/development/src/rules.ts @@ -10,8 +10,6 @@ import { import { Logger } from "./logger"; import { updateRules } from "./game"; -const logColor = "purple"; - export class Rule { id: number; description: string; @@ -38,9 +36,8 @@ export class Rule { this.triggerAction(); if (!this.isRevealed) { const player = getCurrentPlayer(); - Logger.log( + Logger.logRule( `${player.color} received XP for revealing a new rule: ${this.description}`, - logColor, ); player.xp++; this.isRevealed = true; @@ -62,11 +59,10 @@ export const activeRules = [ return !!fellOffTheBoardPiece; }, () => { - Logger.log( + Logger.logRule( `A ${fellOffTheBoardPiece!.player.color} ${ fellOffTheBoardPiece!.name } fell off the board.`, - logColor, ); }, ), @@ -79,9 +75,8 @@ export const activeRules = [ }, () => { const player = getCurrentPlayer(); - Logger.log( + Logger.logRule( `${player.color} has made First Blood and received a bonus.`, - logColor, ); player.xp++; }, @@ -95,10 +90,7 @@ export const activeRules = [ }, () => { const player = getCurrentPlayer(); - Logger.log( - `${player.color} received XP for killing another piece.`, - logColor, - ); + Logger.logRule(`${player.color} received XP for killing another piece.`); player.xp++; }, ), @@ -111,9 +103,8 @@ export const activeRules = [ }, () => { const player = getCurrentPlayer(); - Logger.log( + Logger.logRule( `${player.color} attacked his own piece and has to pay compensations.`, - logColor, ); player.gold--; }, @@ -126,12 +117,11 @@ export const activeRules = [ return roundCounter === 20; }, () => { - Logger.log( + Logger.logRule( "Children of war, you have grown old. Each player gains five XP.", - logColor, ); players.forEach((player) => { - Logger.log(`${player.color} gained XP.`, logColor); + Logger.logRule(`${player.color} gained XP.`); player.xp += 5; }); }, @@ -151,9 +141,8 @@ export const activeRules = [ () => { players.forEach((player) => { if (player === getCurrentPlayer() && player.gold < 0) { - Logger.log( + Logger.logRule( `${player.color} is in debt. They lose XP for not handling money properly.`, - logColor, ); player.xp--; return; From 91619175f55c58b638a11ee5e76f238bf08de961 Mon Sep 17 00:00:00 2001 From: Omoor Date: Sun, 29 Oct 2023 20:07:19 +0200 Subject: [PATCH 3/9] [#65] Fixed lint issue --- development/src/board.ts | 64 +++++++++++++++++++------------------- development/src/boards.ts | 40 ++++++++++++------------ development/src/events.ts | 46 +++++++++++++-------------- development/src/game.ts | 32 +++++++++---------- development/src/items.ts | 18 +++++------ development/src/logger.ts | 18 +++++------ development/src/logic.ts | 40 ++++++++++++------------ development/src/pieces.ts | 52 +++++++++++++++---------------- development/src/players.ts | 2 +- development/src/rules.ts | 20 ++++++------ 10 files changed, 166 insertions(+), 166 deletions(-) diff --git a/development/src/board.ts b/development/src/board.ts index 298e9201..521c1a07 100644 --- a/development/src/board.ts +++ b/development/src/board.ts @@ -1,9 +1,9 @@ -import { Item } from "./items"; -import { pieces } from "./logic"; -import { Piece, Square } from "./pieces"; +import { Item } from './items'; +import { pieces } from './logic'; +import { Piece, Square } from './pieces'; -export const NOTATIONS_LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h"]; -export const NOTATIONS_NUMBERS = ["8", "7", "6", "5", "4", "3", "2", "1"]; +export const NOTATIONS_LETTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; +export const NOTATIONS_NUMBERS = ['8', '7', '6', '5', '4', '3', '2', '1']; export const BOARD_WIDTH = 8; interface ChessBoardType { @@ -36,11 +36,11 @@ export class ChessBoard implements ChessBoardType { } } - const leftNotationsContainer = document.createElement("div"); - leftNotationsContainer.id = "left-notations-container"; + const leftNotationsContainer = document.createElement('div'); + leftNotationsContainer.id = 'left-notations-container'; - const bottomNotationsContainer = document.createElement("div"); - bottomNotationsContainer.id = "bottom-notations-container"; + const bottomNotationsContainer = document.createElement('div'); + bottomNotationsContainer.id = 'bottom-notations-container'; this.boardElement.appendChild(leftNotationsContainer); this.boardElement.appendChild(bottomNotationsContainer); @@ -50,7 +50,7 @@ export class ChessBoard implements ChessBoardType { this.createNotation(NOTATIONS_LETTERS[index]); } - const isCollapsed = this.boardElement.classList.contains("collapsed"); + const isCollapsed = this.boardElement.classList.contains('collapsed'); if (!isCollapsed) { pieces.forEach((piece) => { const pieceElement = this.createPieceElement(piece); @@ -63,9 +63,9 @@ export class ChessBoard implements ChessBoardType { } createSquare(position: [number, number]) { - const squareElement = document.createElement("div"); - squareElement.classList.add("square"); - squareElement.setAttribute("square-id", position.join(",")); + const squareElement = document.createElement('div'); + squareElement.classList.add('square'); + squareElement.setAttribute('square-id', position.join(',')); const backgroundColor = this.getBackgroundColor(position); squareElement.classList.add(backgroundColor); @@ -74,20 +74,20 @@ export class ChessBoard implements ChessBoardType { } createNotation(notation: string) { - const notationElement = document.createElement("p"); - notationElement.classList.add("notation"); + const notationElement = document.createElement('p'); + notationElement.classList.add('notation'); notationElement.innerHTML = notation; if (NOTATIONS_LETTERS.includes(notation)) { - notationElement.classList.add("letter"); + notationElement.classList.add('letter'); const bottomBoardContainer = this.boardElement.querySelector( - "#bottom-notations-container", + '#bottom-notations-container', ); bottomBoardContainer!.appendChild(notationElement); } else { - notationElement.classList.add("number"); + notationElement.classList.add('number'); const leftBoardContainer = this.boardElement.querySelector( - "#left-notations-container", + '#left-notations-container', ); leftBoardContainer!.appendChild(notationElement); } @@ -101,15 +101,15 @@ export class ChessBoard implements ChessBoardType { ? this.lightSquareColor : this.darkSquareColor : isEvenColumn - ? this.darkSquareColor - : this.lightSquareColor; + ? this.darkSquareColor + : this.lightSquareColor; } createPieceElement(piece: Piece): HTMLElement { - const pieceElement = document.createElement("div"); - pieceElement.classList.add("piece"); - pieceElement.setAttribute("draggable", "true"); - pieceElement.setAttribute("id", piece.name); + const pieceElement = document.createElement('div'); + pieceElement.classList.add('piece'); + pieceElement.setAttribute('draggable', 'true'); + pieceElement.setAttribute('id', piece.name); pieceElement.classList.add(piece.player.color.toLowerCase()); @@ -119,9 +119,9 @@ export class ChessBoard implements ChessBoardType { } createItemElement(item: Item): HTMLElement { - const itemElement = document.createElement("div"); - itemElement.classList.add("item"); - itemElement.setAttribute("id", item.name); + const itemElement = document.createElement('div'); + itemElement.classList.add('item'); + itemElement.setAttribute('id', item.name); itemElement.classList.add(item.player.color.toLowerCase()); @@ -132,13 +132,13 @@ export class ChessBoard implements ChessBoardType { movePieceOnBoard(draggedPiece: Piece, targetSquare: Square) { const draggedPieceSquareElement = this.boardElement.querySelector( - `[square-id="${draggedPiece.position.coordinates.join(",")}"]`, + `[square-id="${draggedPiece.position.coordinates.join(',')}"]`, ) as HTMLElement; const draggedPieceElement = draggedPieceSquareElement?.firstElementChild as HTMLElement; const targetSquareElement = this.boardElement.querySelector( - `[square-id="${targetSquare.position.coordinates.join(",")}"]`, + `[square-id="${targetSquare.position.coordinates.join(',')}"]`, ) as HTMLElement; targetSquareElement.appendChild(draggedPieceElement); @@ -146,7 +146,7 @@ export class ChessBoard implements ChessBoardType { destroyPieceOnBoard(targetPiece: Piece) { const targetPieceSquareElement = this.boardElement.querySelector( - `[square-id="${targetPiece.position.coordinates.join(",")}"]`, + `[square-id="${targetPiece.position.coordinates.join(',')}"]`, ); const targetPieceElement = targetPieceSquareElement?.firstElementChild as HTMLElement; @@ -156,7 +156,7 @@ export class ChessBoard implements ChessBoardType { destroyItemOnBoard(targetItem: Item) { const targetItemSquareElement = this.boardElement.querySelector( - `[square-id="${targetItem.position.coordinates!.join(",")}"]`, + `[square-id="${targetItem.position.coordinates!.join(',')}"]`, ); const targetItemElement = targetItemSquareElement?.firstElementChild as HTMLElement; diff --git a/development/src/boards.ts b/development/src/boards.ts index ae57f1f0..4325f3f9 100644 --- a/development/src/boards.ts +++ b/development/src/boards.ts @@ -1,14 +1,14 @@ -import { ChessBoard } from "./board"; -import { Item } from "./items"; -import { Piece, Square } from "./pieces"; +import { ChessBoard } from './board'; +import { Item } from './items'; +import { Piece, Square } from './pieces'; let overworld: ChessBoard; let hell: ChessBoard; let heaven: ChessBoard; -export const OVERWORLD_BOARD_ID = "board-overworld"; -export const HELL_BOARD_ID = "board-hell"; -export const HEAVEN_BOARD_ID = "board-heaven"; +export const OVERWORLD_BOARD_ID = 'board-overworld'; +export const HELL_BOARD_ID = 'board-hell'; +export const HEAVEN_BOARD_ID = 'board-heaven'; export const OVERWORLD_BOARD = document.getElementById( OVERWORLD_BOARD_ID, @@ -19,18 +19,18 @@ export const HEAVEN_BOARD = document.getElementById( ) as HTMLElement; const HELL_BOARD_BUTTON = document.getElementById( - "board-hell-button", + 'board-hell-button', ) as HTMLElement; const HEAVEN_BOARD_BUTTON = document.getElementById( - "board-heaven-button", + 'board-heaven-button', ) as HTMLElement; -const lightOverworldSquareColor = "beige-background"; -const darkOverworldSquareColor = "brown-background"; -const lightHellSquareColor = "dark-orange-background"; -const darkHellSquareColor = "dark-red-background"; -const lightHeavenSquareColor = "water-background"; -const darkHeavenSquareColor = "blue-background"; +const lightOverworldSquareColor = 'beige-background'; +const darkOverworldSquareColor = 'brown-background'; +const lightHellSquareColor = 'dark-orange-background'; +const darkHellSquareColor = 'dark-red-background'; +const lightHeavenSquareColor = 'water-background'; +const darkHeavenSquareColor = 'blue-background'; export function initializeBoards() { overworld = new ChessBoard( @@ -91,11 +91,11 @@ export function spawnPieceOnBoard(piece: Piece) { switch (piece.position.board) { case HELL_BOARD_ID: hell.spawnPieceOnBoard(piece); - HELL_BOARD_BUTTON.classList.remove("collapsed"); + HELL_BOARD_BUTTON.classList.remove('collapsed'); break; case HEAVEN_BOARD_ID: heaven.spawnPieceOnBoard(piece); - HEAVEN_BOARD_BUTTON.classList.remove("collapsed"); + HEAVEN_BOARD_BUTTON.classList.remove('collapsed'); break; default: return; @@ -119,14 +119,14 @@ export function spawnItemOnBoard(item: Item) { } export function highlightSquare(target: HTMLElement, shouldHighlight: boolean) { - while (!target.classList.contains("square")) { + while (!target.classList.contains('square')) { target = target.parentNode as HTMLElement; } - if (target.classList.contains("square")) { + if (target.classList.contains('square')) { if (shouldHighlight) { - target.classList.add("light-gray-background"); + target.classList.add('light-gray-background'); } else { - target.classList.remove("light-gray-background"); + target.classList.remove('light-gray-background'); } } } diff --git a/development/src/events.ts b/development/src/events.ts index 2d4e1da0..8a90c142 100644 --- a/development/src/events.ts +++ b/development/src/events.ts @@ -1,4 +1,4 @@ -import { HEAVEN_BOARD, HELL_BOARD, OVERWORLD_BOARD } from "./boards"; +import { HEAVEN_BOARD, HELL_BOARD, OVERWORLD_BOARD } from './boards'; let draggedElement: HTMLElement; @@ -13,37 +13,37 @@ let triggerOnFallOffTheBoard: ( ) => void; const OVERWORLD_BOARD_BUTTON = document.getElementById( - "board-overworld-button", + 'board-overworld-button', )!; -const HELL_BOARD_BUTTON = document.getElementById("board-hell-button")!; -const HEAVEN_BOARD_BUTTON = document.getElementById("board-heaven-button")!; +const HELL_BOARD_BUTTON = document.getElementById('board-hell-button')!; +const HEAVEN_BOARD_BUTTON = document.getElementById('board-heaven-button')!; let triggerOnHighlight: (target: HTMLElement, shouldHighlight: boolean) => void; export function initializeEventListeners() { - const squares = document.querySelectorAll(".square"); + const squares = document.querySelectorAll('.square'); // Listen for mouse events squares.forEach((square) => { - square.addEventListener("dragstart", onDragStart); - square.addEventListener("dragover", onDragOver); - square.addEventListener("drop", onDragDrop); - square.addEventListener("mouseover", onMouseOver); - square.addEventListener("mouseout", onMouseOut); + square.addEventListener('dragstart', onDragStart); + square.addEventListener('dragover', onDragOver); + square.addEventListener('drop', onDragDrop); + square.addEventListener('mouseover', onMouseOver); + square.addEventListener('mouseout', onMouseOut); }); // Support pieces falling off the board - document.body.addEventListener("dragover", onDragOver); - document.body.addEventListener("drop", onDragOffTheBoard); + document.body.addEventListener('dragover', onDragOver); + document.body.addEventListener('drop', onDragOffTheBoard); // Listen for boards' buttons clicks - OVERWORLD_BOARD_BUTTON.addEventListener("click", handleButtonPress); - HELL_BOARD_BUTTON.addEventListener("click", handleButtonPress); - HEAVEN_BOARD_BUTTON.addEventListener("click", handleButtonPress); + OVERWORLD_BOARD_BUTTON.addEventListener('click', handleButtonPress); + HELL_BOARD_BUTTON.addEventListener('click', handleButtonPress); + HEAVEN_BOARD_BUTTON.addEventListener('click', handleButtonPress); } function onDragStart(event: Event) { const targetElement = event.target as HTMLElement; - if (targetElement.classList.contains("piece")) { + if (targetElement.classList.contains('piece')) { draggedElement = event.target as HTMLElement; } } @@ -52,12 +52,12 @@ function onDragDrop(event: Event) { event.stopPropagation(); let targetElement = event.target as HTMLElement; // Make sure target is not a resource - while (targetElement.classList.contains("untargetable")) { + while (targetElement.classList.contains('untargetable')) { targetElement = targetElement.parentNode as HTMLElement; } let board = targetElement as HTMLElement; - while (!board.classList.contains("board")) { + while (!board.classList.contains('board')) { board = board.parentNode as HTMLElement; } @@ -70,7 +70,7 @@ function onDragOver(event: Event) { function onDragOffTheBoard(_: Event) { let board = draggedElement; - while (!board.classList.contains("board")) { + while (!board.classList.contains('board')) { board = board.parentNode as HTMLElement; } @@ -118,11 +118,11 @@ export function setOnHighlight( function showBoard(boardId: string) { const boardElement = document.getElementById(boardId) as HTMLElement; - OVERWORLD_BOARD.classList.add("collapsed"); - HELL_BOARD.classList.add("collapsed"); - HEAVEN_BOARD.classList.add("collapsed"); + OVERWORLD_BOARD.classList.add('collapsed'); + HELL_BOARD.classList.add('collapsed'); + HEAVEN_BOARD.classList.add('collapsed'); - boardElement.classList.remove("collapsed"); + boardElement.classList.remove('collapsed'); } export function handleButtonPress(event: Event) { diff --git a/development/src/game.ts b/development/src/game.ts index 7b386055..36dcafcc 100644 --- a/development/src/game.ts +++ b/development/src/game.ts @@ -1,39 +1,39 @@ -import { Logger } from "./logger"; +import { Logger } from './logger'; import { initializeEventListeners, setOnAction, setOnFallOffTheBoard, setOnHighlight, -} from "./events"; -import { highlightSquare, initializeBoards } from "./boards"; +} from './events'; +import { highlightSquare, initializeBoards } from './boards'; import { onAction, onFallOffTheBoard, getCurrentPlayer, players, roundCounter, -} from "./logic"; -import { Rule } from "./rules"; +} from './logic'; +import { Rule } from './rules'; -const infoDisplay = document.getElementById("info-display")!; -const rulesContainer = document.getElementById("rules-container")!; +const infoDisplay = document.getElementById('info-display')!; +const rulesContainer = document.getElementById('rules-container')!; export function updatePlayersInformation() { - infoDisplay.textContent = ""; + infoDisplay.textContent = ''; - const roundElement = document.createElement("p"); + const roundElement = document.createElement('p'); roundElement.innerHTML = `Round: ${roundCounter}`; infoDisplay.appendChild(roundElement); - const playersElement = document.createElement("p"); - playersElement.innerHTML = "Players:"; + const playersElement = document.createElement('p'); + playersElement.innerHTML = 'Players:'; players.forEach((player) => { - const playerInformationElement = document.createElement("div"); + const playerInformationElement = document.createElement('div'); - const statusElement = document.createElement("p"); + const statusElement = document.createElement('p'); const isCurrentPlayer = getCurrentPlayer() === player; - const title = `${isCurrentPlayer ? "> " : ""} ${player.color} Player:`; + const title = `${isCurrentPlayer ? '> ' : ''} ${player.color} Player:`; const status = `${title} ${player.xp} XP; ${player.gold} Gold.`; statusElement.innerHTML = status; @@ -49,13 +49,13 @@ export function updatePlayersInformation() { } export function updateRules(rule: Rule) { - const ruleElement = document.createElement("p"); + const ruleElement = document.createElement('p'); ruleElement.innerHTML = `${rule.id + 1}) ${rule.description}`; rulesContainer.appendChild(ruleElement); } function initializeGame() { - Logger.log("Game started!"); + Logger.log('Game started!'); initializeBoards(); initializeEventListeners(); updatePlayersInformation(); diff --git a/development/src/items.ts b/development/src/items.ts index a34616e0..3941170b 100644 --- a/development/src/items.ts +++ b/development/src/items.ts @@ -1,9 +1,9 @@ -import { spawnItemOnBoard } from "./boards"; -import { Logger } from "./logger"; -import { items } from "./logic"; -import { Piece, Position } from "./pieces"; -import { Player } from "./players"; -import { trapResource } from "./resources"; +import { spawnItemOnBoard } from './boards'; +import { Logger } from './logger'; +import { items } from './logic'; +import { Piece, Position } from './pieces'; +import { Player } from './players'; +import { trapResource } from './resources'; export class Inventory { items: Array = []; @@ -21,9 +21,9 @@ export class Inventory { } toHTMLElement(): HTMLElement { - const inventoryElement = document.createElement("ul"); + const inventoryElement = document.createElement('ul'); this.items.forEach((item) => { - const inventoryItemElement = document.createElement("li"); + const inventoryItemElement = document.createElement('li'); inventoryItemElement.innerHTML = item.name; inventoryElement.appendChild(inventoryItemElement); @@ -66,7 +66,7 @@ export class Item implements ItemType { export class Trap extends Item { constructor(player: Player, position: Position) { - super("trap", trapResource, player, position); + super('trap', trapResource, player, position); } apply(piece: Piece) { diff --git a/development/src/logger.ts b/development/src/logger.ts index 78d394ec..ef506dd9 100644 --- a/development/src/logger.ts +++ b/development/src/logger.ts @@ -1,17 +1,17 @@ -import { NOTATIONS_LETTERS, NOTATIONS_NUMBERS } from "./board"; -import { Piece, Square } from "./pieces"; +import { NOTATIONS_LETTERS, NOTATIONS_NUMBERS } from './board'; +import { Piece, Square } from './pieces'; -const defaultColor = "gray"; -const killColor = "red"; -const ruleColor = "purple"; -const itemColor = "green"; +const defaultColor = 'gray'; +const killColor = 'red'; +const ruleColor = 'purple'; +const itemColor = 'green'; export class Logger { static log(message: string, color?: string) { - if (!color || color == "") color = defaultColor; + if (!color || color == '') color = defaultColor; - const logsContainer = document.getElementById("logs-container")!; - logsContainer.innerHTML += `

> ${message}

`; + const logsContainer = document.getElementById('logs-container')!; + logsContainer.innerHTML += `

> ${message}

`; logsContainer.scrollTop = logsContainer.scrollHeight; // Scroll to the last log } diff --git a/development/src/logic.ts b/development/src/logic.ts index 615911a2..1091bcd8 100644 --- a/development/src/logic.ts +++ b/development/src/logic.ts @@ -1,4 +1,4 @@ -import { Player } from "./players"; +import { Player } from './players'; import { Piece, Pawn, @@ -9,8 +9,8 @@ import { King, Square, Position, -} from "./pieces"; -import { Logger } from "./logger"; +} from './pieces'; +import { Logger } from './logger'; import { movePieceOnBoard, destroyPieceOnBoard, @@ -19,14 +19,14 @@ import { HELL_BOARD_ID, HEAVEN_BOARD_ID, destroyItemOnBoard, -} from "./boards"; -import { activeRules } from "./rules"; -import { updatePlayersInformation } from "./game"; -import { Item } from "./items"; +} from './boards'; +import { activeRules } from './rules'; +import { updatePlayersInformation } from './game'; +import { Item } from './items'; export enum PlayerColors { - WHITE = "White", - BLACK = "Black", + WHITE = 'White', + BLACK = 'Black', } const whitePlayer = new Player(PlayerColors.WHITE); @@ -113,7 +113,7 @@ export function getPieceByPositionAndBoard( } function convertSquareIdToPosition(squareId: string): [number, number] { - return squareId.split(",").map((str) => parseInt(str)) as [number, number]; + return squareId.split(',').map((str) => parseInt(str)) as [number, number]; } export function onAction( @@ -126,7 +126,7 @@ export function onAction( const draggedElementPosition: Position = { coordinates: convertSquareIdToPosition( - draggedElementParentElement.getAttribute("square-id")!, + draggedElementParentElement.getAttribute('square-id')!, ), board: board, }; @@ -135,11 +135,11 @@ export function onAction( comparePositions(piece.position, draggedElementPosition), ); - if (targetElement.classList.contains("piece")) { + if (targetElement.classList.contains('piece')) { const squareElement = targetElement.parentElement!; const targetElementPosition: Position = { coordinates: convertSquareIdToPosition( - squareElement.getAttribute("square-id")!, + squareElement.getAttribute('square-id')!, ), board: board, }; @@ -149,15 +149,15 @@ export function onAction( }); actOnTurn(draggedPiece, targetPiece); - } else if (targetElement.classList.contains("item")) { + } else if (targetElement.classList.contains('item')) { let squareElement = targetElement as HTMLElement; - while (!squareElement.getAttribute("square-id")) { + while (!squareElement.getAttribute('square-id')) { squareElement = squareElement.parentElement as HTMLElement; } const itemPosition: Position = { coordinates: convertSquareIdToPosition( - squareElement.getAttribute("square-id")!, + squareElement.getAttribute('square-id')!, ), board: board, }; @@ -171,7 +171,7 @@ export function onAction( const targetSquare: Square = { position: { coordinates: convertSquareIdToPosition( - targetElement.getAttribute("square-id")!, + targetElement.getAttribute('square-id')!, ), board: board, }, @@ -185,7 +185,7 @@ export function onFallOffTheBoard(draggedElement: HTMLElement, board: string) { const squareElement = draggedElement.parentElement!; const draggedElementPosition: Position = { coordinates: convertSquareIdToPosition( - squareElement.getAttribute("square-id")!, + squareElement.getAttribute('square-id')!, ), board: board, }; @@ -327,7 +327,7 @@ function castle(kingPiece: Piece, targetSquare: Square) { return ( piece.player === getCurrentPlayer() && !piece.hasMoved && - piece.name === "Rook" + piece.name === 'Rook' ); }); @@ -386,7 +386,7 @@ function endTurn() { currentPlayerIndex + 1 < players.length ? currentPlayerIndex + 1 : 0; turnCounter++; - console.log("dsadsa"); + console.log('dsadsa'); if (turnCounter % players.length === 0) { turnCounter = 0; diff --git a/development/src/pieces.ts b/development/src/pieces.ts index 678e63bc..802086ca 100644 --- a/development/src/pieces.ts +++ b/development/src/pieces.ts @@ -5,8 +5,8 @@ import { rookResource, queenResource, kingResource, -} from "./resources"; -import { Player } from "./players"; +} from './resources'; +import { Player } from './players'; import { getCurrentPlayer, switchIsCastling, @@ -14,9 +14,9 @@ import { items, comparePositions, PlayerColors, -} from "./logic"; -import { OVERWORLD_BOARD_ID } from "./boards"; -import { Item } from "./items"; +} from './logic'; +import { OVERWORLD_BOARD_ID } from './boards'; +import { Item } from './items'; export type Position = { coordinates: [number, number]; @@ -80,7 +80,7 @@ export type Square = { export class Pawn extends Piece { constructor(position: Position, player: Player) { - super(position, player, pawnResource, "Pawn"); + super(position, player, pawnResource, 'Pawn'); } validateMove(target: Piece | Square) { @@ -96,8 +96,8 @@ export class Pawn extends Piece { target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; // Make sure pawn does not move backwards. const currentPlayer = getCurrentPlayer(); @@ -129,7 +129,7 @@ export class Pawn extends Piece { export class Bishop extends Piece { constructor(position: Position, player: Player) { - super(position, player, bishopResource, "Bishop"); + super(position, player, bishopResource, 'Bishop'); } validateMove(target: Piece | Square) { @@ -162,7 +162,7 @@ export class Bishop extends Piece { export class Knight extends Piece { constructor(position: Position, player: Player) { - super(position, player, knightResource, "Knight"); + super(position, player, knightResource, 'Knight'); } validateMove(target: Piece | Square) { @@ -182,7 +182,7 @@ export class Knight extends Piece { export class Rook extends Piece { constructor(position: Position, player: Player) { - super(position, player, rookResource, "Rook"); + super(position, player, rookResource, 'Rook'); } validateMove(target: Piece | Square) { @@ -190,14 +190,14 @@ export class Rook extends Piece { target.position.coordinates[0] > this.position.coordinates[0] ? 1 : target.position.coordinates[0] < this.position.coordinates[0] - ? -1 - : 0; + ? -1 + : 0; const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; // Rooks can move either vertically or horizontally but not both at the same. if ( @@ -219,7 +219,7 @@ export class Rook extends Piece { export class Queen extends Piece { constructor(position: Position, player: Player) { - super(position, player, queenResource, "Queen"); + super(position, player, queenResource, 'Queen'); } validateMove(target: Piece | Square) { @@ -227,14 +227,14 @@ export class Queen extends Piece { target.position.coordinates[0] > this.position.coordinates[0] ? 1 : target.position.coordinates[0] < this.position.coordinates[0] - ? -1 - : 0; + ? -1 + : 0; const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; const absoluteDeltaX = Math.abs( target.position.coordinates[0] - this.position.coordinates[0], @@ -264,7 +264,7 @@ export class Queen extends Piece { export class King extends Piece { constructor(position: Position, player: Player) { - super(position, player, kingResource, "King"); + super(position, player, kingResource, 'King'); } validateMove(target: Piece | Square) { @@ -272,14 +272,14 @@ export class King extends Piece { target.position.coordinates[0] > this.position.coordinates[0] ? 1 : target.position.coordinates[0] < this.position.coordinates[0] - ? -1 - : 0; + ? -1 + : 0; const stepY = target.position.coordinates[1] > this.position.coordinates[1] ? 1 : target.position.coordinates[1] < this.position.coordinates[1] - ? -1 - : 0; + ? -1 + : 0; const deltaX = target.position.coordinates[0] - this.position.coordinates[0]; @@ -395,7 +395,7 @@ function checkIfPositionContainsTrap(position: Position): boolean { const item = items.find((item) => comparePositions(position, item.position)); if (item) { switch (item.name) { - case "trap": { + case 'trap': { return true; } } diff --git a/development/src/players.ts b/development/src/players.ts index 0f69ae71..394e6560 100644 --- a/development/src/players.ts +++ b/development/src/players.ts @@ -1,4 +1,4 @@ -import { Inventory } from "./items"; +import { Inventory } from './items'; type PlayerType = { color: string; diff --git a/development/src/rules.ts b/development/src/rules.ts index a03007d5..738dd3b5 100644 --- a/development/src/rules.ts +++ b/development/src/rules.ts @@ -6,9 +6,9 @@ import { isFriendlyFire, roundCounter, players, -} from "./logic"; -import { Logger } from "./logger"; -import { updateRules } from "./game"; +} from './logic'; +import { Logger } from './logger'; +import { updateRules } from './game'; export class Rule { id: number; @@ -53,7 +53,7 @@ const inactiveRules = []; export const activeRules = [ new Rule( 0, - "Pieces can fall off the board.", + 'Pieces can fall off the board.', false, () => { return !!fellOffTheBoardPiece; @@ -68,7 +68,7 @@ export const activeRules = [ ), new Rule( 1, - "First Blood Bonus: The first to kill gets an extra XP.", + 'First Blood Bonus: The first to kill gets an extra XP.', false, () => { return deathCounter == 1; @@ -83,7 +83,7 @@ export const activeRules = [ ), new Rule( 2, - "Players gain XP on a kill.", + 'Players gain XP on a kill.', false, () => { return isPieceKilled; @@ -96,7 +96,7 @@ export const activeRules = [ ), new Rule( 3, - "Friendly Fire! Players can attack their own pieces (for a price).", + 'Friendly Fire! Players can attack their own pieces (for a price).', false, () => { return isFriendlyFire; @@ -111,14 +111,14 @@ export const activeRules = [ ), new Rule( 4, - "With age comes wisdom.", + 'With age comes wisdom.', false, () => { return roundCounter === 20; }, () => { Logger.logRule( - "Children of war, you have grown old. Each player gains five XP.", + 'Children of war, you have grown old. Each player gains five XP.', ); players.forEach((player) => { Logger.logRule(`${player.color} gained XP.`); @@ -128,7 +128,7 @@ export const activeRules = [ ), new Rule( 5, - "Empty pockets.", + 'Empty pockets.', false, () => { players.forEach((player) => { From a828f0de7f00cf97ad31cb94d3c17bb2da290611 Mon Sep 17 00:00:00 2001 From: Omoor Date: Sun, 29 Oct 2023 20:08:06 +0200 Subject: [PATCH 4/9] [#65] Changed fell off the board color --- development/src/rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/src/rules.ts b/development/src/rules.ts index 738dd3b5..05ee2c6f 100644 --- a/development/src/rules.ts +++ b/development/src/rules.ts @@ -59,7 +59,7 @@ export const activeRules = [ return !!fellOffTheBoardPiece; }, () => { - Logger.logRule( + Logger.logKill( `A ${fellOffTheBoardPiece!.player.color} ${ fellOffTheBoardPiece!.name } fell off the board.`, From f0a123226b86fb45eed6272f466d9da07565f650 Mon Sep 17 00:00:00 2001 From: Omoor Date: Mon, 30 Oct 2023 16:11:39 +0200 Subject: [PATCH 5/9] [#65] fixed indentation on .github files --- .github/workflows/checkin.yml | 4 ++-- .github/workflows/commit-message-checker.yml | 10 +++++----- .github/workflows/style-checker.yml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/checkin.yml b/.github/workflows/checkin.yml index e03ae678..7563e179 100644 --- a/.github/workflows/checkin.yml +++ b/.github/workflows/checkin.yml @@ -1,5 +1,5 @@ -name: "[🔨] Checkin" -run-name: "[🔨] Checkin: ${{ github.ref }}" +name: '[🔨] Checkin' +run-name: '[🔨] Checkin: ${{ github.ref }}' on: workflow_dispatch: pull_request: diff --git a/.github/workflows/commit-message-checker.yml b/.github/workflows/commit-message-checker.yml index 68f2a887..6342656c 100644 --- a/.github/workflows/commit-message-checker.yml +++ b/.github/workflows/commit-message-checker.yml @@ -1,5 +1,5 @@ -name: "[📒] Commit Message Checker" -run-name: "[📒] Commit Message Checker: ${{ github.ref }}" +name: '[📒] Commit Message Checker' +run-name: '[📒] Commit Message Checker: ${{ github.ref }}' on: pull_request: types: @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Get PR Commits - id: "get-pr-commits" + id: 'get-pr-commits' uses: tim-actions/get-pr-commits@master with: token: ${{ secrets.GITHUB_TOKEN }} @@ -23,11 +23,11 @@ jobs: with: commits: ${{ steps.get-pr-commits.outputs.commits }} pattern: '^.{0,75}(\n.*)*$' - error: "Subject too long (max 75)" + error: 'Subject too long (max 75)' - name: Check Syntax uses: tim-actions/commit-message-checker-with-regex@v0.3.1 with: commits: ${{ steps.get-pr-commits.outputs.commits }} pattern: '\[#\d+\] [a-zA-Z]+|\[trivial\] [a-zA-Z]+|Merge [a-zA-Z]+' error: 'Commit messages must start with an issue number. For example "[#21] MESSAGE" or "[trivial] MESSAGE" or "Merge MESSAGE".' - one_pass_all_pass: "false" + one_pass_all_pass: 'false' diff --git a/.github/workflows/style-checker.yml b/.github/workflows/style-checker.yml index 2cdbac7b..5548cdae 100644 --- a/.github/workflows/style-checker.yml +++ b/.github/workflows/style-checker.yml @@ -1,5 +1,5 @@ -name: "[🎨] Style Checker" -run-name: "[🎨] Style Checker: ${{ github.ref }}" +name: '[🎨] Style Checker' +run-name: '[🎨] Style Checker: ${{ github.ref }}' on: workflow_dispatch: pull_request: From b10a48826d49dc11329f35c3102ca144bbb5b4e7 Mon Sep 17 00:00:00 2001 From: Omoor Date: Tue, 31 Oct 2023 17:08:01 +0200 Subject: [PATCH 6/9] [#65] Reset License & Readme, changed color variables in logger to enum. --- LICENSE.md | 366 +++++++++++++++++++------------------- README.md | 18 +- development/src/logger.ts | 18 +- 3 files changed, 196 insertions(+), 206 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index c61b6639..261eeb9e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,180 +2,180 @@ Version 2.0, January 2004 http://www.apache.org/licenses/ -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" @@ -186,16 +186,16 @@ APPENDIX: How to apply the Apache License to your work. same "printed page" as the copyright notice for easier identification within third-party archives. -Copyright [yyyy] [name of copyright owner] + Copyright [yyyy] [name of copyright owner] -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 9b1c8687..07b1b8e3 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@
- # :notebook_with_decorative_cover: Table of Contents - [About the Project](#star2-about-the-project) @@ -46,15 +45,11 @@ - [License](#warning-license) - ## :star2: About the Project - Chess But Better acts as multiple additional layers on top of your average chess game. This innovative project aims to take the timeless game of chess and infuse it with a touch of excitement, complexity, and creativity. By incorporating a set of unique features, Chess But Better offers anyone the opportunity to explore a chess experience unlike any other. - ### :dart: Features - - **Secret Rules:** The game introduces random additional rules, which remain hidden until triggered. - **Extra Pieces:** Discover unique and powerful new pieces, each with its own advantages and drawbacks. - **Items:** Make strategic use of various items on the chessboard to gain temporary advantages. @@ -63,12 +58,11 @@ Chess But Better acts as multiple additional layers on top of your average chess - **Upgrades System:** Utilize Experience Points to enhance and evolve your chess pieces into more powerful variants. - **And a lot more!** - -## :toolbox: Getting Started + +## :toolbox: Getting Started - ### :running: Run Locally Clone the project @@ -96,7 +90,6 @@ npm run start ``` - ## :wave: Contributing
@@ -106,30 +99,25 @@ npm run start Contributions are always welcome! - ## :grey_question: FAQ - What is Chess But Better? - + Chess But Better is an innovative chess project that enhances the traditional game by introducing multiple extra layers of complexity on top of the rules of chess. - How can I play Chess But Better? - + You can access Chess But Better by cloning this repository and following the [setup instructions](#running-run-locally). - Is Chess But Better suitable for all skill levels? - + Yes, Chess But Better is designed to cater to players of all skill levels. Whether you're a novice or a seasoned chess enthusiast, there's something for everyone to enjoy. - Can I contribute to Chess But Better? - + Absolutely! Chess But Better is an open-source project, and we welcome contributions from developers and chess enthusiasts. - How often is Chess But Better updated with new features or content? + The frequency of updates may vary, but we are committed to regularly enhancing and expanding the project based on community feedback and contributions. - + ## :warning: License Distributed under the Apache-2.0 license. See LICENSE.txt for more information. diff --git a/development/src/logger.ts b/development/src/logger.ts index ef506dd9..2c614aa2 100644 --- a/development/src/logger.ts +++ b/development/src/logger.ts @@ -1,14 +1,16 @@ import { NOTATIONS_LETTERS, NOTATIONS_NUMBERS } from './board'; import { Piece, Square } from './pieces'; -const defaultColor = 'gray'; -const killColor = 'red'; -const ruleColor = 'purple'; -const itemColor = 'green'; +const ColorEnum = { + DEFAULT: 'gray', + KILL: 'red', + RULE: 'purple', + ITEM: 'green', +}; export class Logger { static log(message: string, color?: string) { - if (!color || color == '') color = defaultColor; + if (!color || color == '') color = ColorEnum.DEFAULT; const logsContainer = document.getElementById('logs-container')!; logsContainer.innerHTML += `

> ${message}

`; @@ -17,15 +19,15 @@ export class Logger { } static logKill(message: string) { - this.log(message, killColor); + this.log(message, ColorEnum.KILL); } static logRule(message: string) { - this.log(message, ruleColor); + this.log(message, ColorEnum.RULE); } static logItem(message: string) { - this.log(message, itemColor); + this.log(message, ColorEnum.ITEM); } static logMovement(draggedPiece: Piece, targetSquare: Square) { From 4d330b7cd95d81073a0dfeec1900cf58ad9ba5d7 Mon Sep 17 00:00:00 2001 From: Omoor Date: Tue, 31 Oct 2023 19:27:56 +0200 Subject: [PATCH 7/9] [#65] Reset config and index.html --- index.html | 34 ++++++++++++++++++++++++++++++++++ jest.config.ts | 8 ++++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 00000000..f344aa29 --- /dev/null +++ b/index.html @@ -0,0 +1,34 @@ + + + + + Chess But Better + + + +
+
+ + +
+

+
+ + + +
+
+

Rules

+
+ +
+ + + + diff --git a/jest.config.ts b/jest.config.ts index 5f589f5c..9ec1189d 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,9 +1,9 @@ /* eslint-disable */ export default { - displayName: "chess-but-better", - coverageDirectory: "./coverage/chess-but-better", + displayName: 'chess-but-better', + coverageDirectory: './coverage/chess-but-better', testMatch: [ - "/src/**/__tests__/**/*.[jt]s?(x)", - "/src/**/*(*.)@(spec|test).[jt]s?(x)", + '/src/**/__tests__/**/*.[jt]s?(x)', + '/src/**/*(*.)@(spec|test).[jt]s?(x)', ], }; From 30533d9f7e0e379786916c6b7a680b6bcc452013 Mon Sep 17 00:00:00 2001 From: Omoor Date: Tue, 31 Oct 2023 20:58:57 +0200 Subject: [PATCH 8/9] [#65] fixed index.html duplicate --- development/views/index.html | 2 +- index.html | 34 ---------------------------------- 2 files changed, 1 insertion(+), 35 deletions(-) delete mode 100644 index.html diff --git a/development/views/index.html b/development/views/index.html index f5465c0c..f344aa29 100644 --- a/development/views/index.html +++ b/development/views/index.html @@ -1,4 +1,4 @@ - + diff --git a/index.html b/index.html deleted file mode 100644 index f344aa29..00000000 --- a/index.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - Chess But Better - - - -
-
- - -
-

-
- - - -
-
-

Rules

-
- -
- - - - From 9ed42edf692431cf4f0827a31349dc7080211ff4 Mon Sep 17 00:00:00 2001 From: Omoor Date: Wed, 1 Nov 2023 09:27:23 +0200 Subject: [PATCH 9/9] [#65] Updated logger.ts code --- development/src/logger.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/development/src/logger.ts b/development/src/logger.ts index 2c614aa2..b821dedc 100644 --- a/development/src/logger.ts +++ b/development/src/logger.ts @@ -9,9 +9,7 @@ const ColorEnum = { }; export class Logger { - static log(message: string, color?: string) { - if (!color || color == '') color = ColorEnum.DEFAULT; - + static log(message: string, color: string = ColorEnum.DEFAULT) { const logsContainer = document.getElementById('logs-container')!; logsContainer.innerHTML += `

> ${message}

`;