From 332c36b81b064ad1f86cf28bf4e78d01f2e78c0e Mon Sep 17 00:00:00 2001 From: sigmasternchen Date: Thu, 19 Sep 2024 22:50:21 +0200 Subject: [PATCH] feat: First draft of UI --- html/index.html | 12 + html/static/.gitignore | 1 + html/static/styles.css | 82 ++++++ package-lock.json | 490 ++++++++++++++++++++++++++++++++++++ package.json | 24 ++ src/components/App.jsx | 52 ++++ src/components/Cell.jsx | 5 + src/components/Field.jsx | 20 ++ src/components/Key.jsx | 5 + src/components/Keyboard.jsx | 23 ++ src/data/dictionary.json | 0 src/logic/game-logic.js | 15 ++ src/main.jsx | 7 + src/model/CellState.js | 26 ++ src/utils.js | 28 +++ 15 files changed, 790 insertions(+) create mode 100644 html/index.html create mode 100644 html/static/.gitignore create mode 100644 html/static/styles.css create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/components/App.jsx create mode 100644 src/components/Cell.jsx create mode 100644 src/components/Field.jsx create mode 100644 src/components/Key.jsx create mode 100644 src/components/Keyboard.jsx create mode 100644 src/data/dictionary.json create mode 100644 src/logic/game-logic.js create mode 100644 src/main.jsx create mode 100644 src/model/CellState.js create mode 100644 src/utils.js diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..cd93ace --- /dev/null +++ b/html/index.html @@ -0,0 +1,12 @@ + + + + + + + + +
+ + + \ No newline at end of file diff --git a/html/static/.gitignore b/html/static/.gitignore new file mode 100644 index 0000000..4c43fe6 --- /dev/null +++ b/html/static/.gitignore @@ -0,0 +1 @@ +*.js \ No newline at end of file diff --git a/html/static/styles.css b/html/static/styles.css new file mode 100644 index 0000000..052501c --- /dev/null +++ b/html/static/styles.css @@ -0,0 +1,82 @@ +* { + box-sizing: border-box; + font-family: sans-serif; +} + +body { + background-color: black; +} + +.field { + text-align: center; +} + +.cell { + display: inline-block; + width: 55px; + height: 55px; + margin: 3px; + border: 1px solid #555; + text-align: center; + font-size: 35px; + color: white; + padding-top: 7px; + font-weight: bold; +} + +.cell.Unknown { + background-color: black; +} + +.cell.Wrong { + background-color: #555; + border: none; +} + +.cell.HalfRight { + background-color: #bb0; + border: none; +} + +.cell.Right { + background-color: #090; + border: none; +} + +.keyboard { + text-align: center; +} + +.key { + display: inline-block; + height: 40px; + min-width: 33px; + margin: 3px; + border: 1px solid #555; + text-align: center; + font-size: 18px; + color: white; + padding-top: 8px; + padding-left: 7px; + padding-right: 7px; + font-weight: bold +} + +.key.Unknown {; + background-color: #555; + border: none; +} + +.key.Wrong { + background-color: black; +} + +.cell.HalfRight { + background-color: #bb0; + border: none; +} + +.key.Right { + background-color: #090; + border: none; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..641e257 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,490 @@ +{ + "name": "x86-wordle", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "x86-wordle", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "react": "^18.3.1", + "react-dom": "^18.3.1" + }, + "devDependencies": { + "esbuild": "^0.23.1" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", + "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", + "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", + "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", + "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", + "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", + "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", + "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", + "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", + "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", + "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", + "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", + "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", + "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", + "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", + "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", + "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", + "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", + "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", + "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", + "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", + "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", + "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", + "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", + "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/esbuild": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", + "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.23.1", + "@esbuild/android-arm": "0.23.1", + "@esbuild/android-arm64": "0.23.1", + "@esbuild/android-x64": "0.23.1", + "@esbuild/darwin-arm64": "0.23.1", + "@esbuild/darwin-x64": "0.23.1", + "@esbuild/freebsd-arm64": "0.23.1", + "@esbuild/freebsd-x64": "0.23.1", + "@esbuild/linux-arm": "0.23.1", + "@esbuild/linux-arm64": "0.23.1", + "@esbuild/linux-ia32": "0.23.1", + "@esbuild/linux-loong64": "0.23.1", + "@esbuild/linux-mips64el": "0.23.1", + "@esbuild/linux-ppc64": "0.23.1", + "@esbuild/linux-riscv64": "0.23.1", + "@esbuild/linux-s390x": "0.23.1", + "@esbuild/linux-x64": "0.23.1", + "@esbuild/netbsd-x64": "0.23.1", + "@esbuild/openbsd-arm64": "0.23.1", + "@esbuild/openbsd-x64": "0.23.1", + "@esbuild/sunos-x64": "0.23.1", + "@esbuild/win32-arm64": "0.23.1", + "@esbuild/win32-ia32": "0.23.1", + "@esbuild/win32-x64": "0.23.1" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" + }, + "peerDependencies": { + "react": "^18.3.1" + } + }, + "node_modules/scheduler": { + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "dependencies": { + "loose-envify": "^1.1.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..183279f --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "x86-wordle", + "version": "1.0.0", + "description": "", + "main": "src/main.jsx", + "scripts": { + "build": "esbuild src/main.jsx --bundle --outfile='html/static/bundle.js' --tree-shaking=true --minify", + "watch": "esbuild src/main.jsx --bundle --outfile='html/static/bundle.js' --watch", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "." + }, + "author": "", + "license": "ISC", + "dependencies": { + "react": "^18.3.1", + "react-dom": "^18.3.1" + }, + "devDependencies": { + "esbuild": "^0.23.1" + } +} diff --git a/src/components/App.jsx b/src/components/App.jsx new file mode 100644 index 0000000..6697203 --- /dev/null +++ b/src/components/App.jsx @@ -0,0 +1,52 @@ +import React from "react"; +import {Field} from "./Field"; +import {calculateDifference} from "../logic/game-logic"; +import {id, objectMap, zip} from "../utils"; +import {Keyboard} from "./Keyboard"; +import {sortCellStates} from "../model/CellState"; + +export const App = () => { + const correct = "guess"; + const guesses = [ + "ascii", + "eager", + "faces", + "guess", + ]; + + const fieldData = guesses + .map(guess => guess.toUpperCase()) + .map(guess => [ + guess.split(""), + calculateDifference(correct.toUpperCase(), guess) + ]) + .map(([guess, difference]) => zip(guess, difference)) + .map(guessWithDifference => guessWithDifference + .map(([content, state]) => ({ + state: state, + content: content, + })) + ); + + const used = objectMap( + Object.groupBy( + fieldData + .flatMap(id) + .flatMap(id), + cell => cell.content + ), + states => states + .map(state => state.state) + .toSorted(sortCellStates) + .at(-1) + ); + + + return
+ + +
+}; \ No newline at end of file diff --git a/src/components/Cell.jsx b/src/components/Cell.jsx new file mode 100644 index 0000000..6c14e02 --- /dev/null +++ b/src/components/Cell.jsx @@ -0,0 +1,5 @@ +import React from "react"; + +export const Cell = ({state, content}) => { + return
{content}
+} \ No newline at end of file diff --git a/src/components/Field.jsx b/src/components/Field.jsx new file mode 100644 index 0000000..34da612 --- /dev/null +++ b/src/components/Field.jsx @@ -0,0 +1,20 @@ +import React from "react"; + +import {range} from "../utils"; +import {Cell} from "./Cell"; +import {CellState} from "../model/CellState"; + +export const Field = ({size, fieldData}) => { + return
+ { + range(size[1]).map(y => + range(size[0]).map(x => ( + + )).concat([
]) + ) + } +
+}; \ No newline at end of file diff --git a/src/components/Key.jsx b/src/components/Key.jsx new file mode 100644 index 0000000..33c14a7 --- /dev/null +++ b/src/components/Key.jsx @@ -0,0 +1,5 @@ +import React from "react"; + +export const Key = ({state, content}) => { + return
{content}
+} \ No newline at end of file diff --git a/src/components/Keyboard.jsx b/src/components/Keyboard.jsx new file mode 100644 index 0000000..e8a161b --- /dev/null +++ b/src/components/Keyboard.jsx @@ -0,0 +1,23 @@ +import React from "react"; +import {CellState} from "../model/CellState"; +import {Key} from "./Key"; + +export const Keyboard = ({used}) => { + const keys = [ + "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", null, + "A", "S", "D", "F", "G", "H", "J", "K", "L", null, + "ENTER", "Z", "X", "C", "V", "B", "N", "M", "BACK" + ]; + + return
+ { + keys.map((key) => { + if (key) { + return ; + } else { + return
+ } + }) + } +
+} \ No newline at end of file diff --git a/src/data/dictionary.json b/src/data/dictionary.json new file mode 100644 index 0000000..e69de29 diff --git a/src/logic/game-logic.js b/src/logic/game-logic.js new file mode 100644 index 0000000..dbb2fa4 --- /dev/null +++ b/src/logic/game-logic.js @@ -0,0 +1,15 @@ +import {CellState} from "../model/CellState"; + +export const calculateDifference = (correct, guess) => { + const result = Array(correct.length); + for (let i = 0; i < correct.length; i++) { + if (correct[i] === guess[i]) { + result[i] = CellState.Right; + } else if (correct.indexOf(guess[i]) !== -1) { + result[i] = CellState.HalfRight; + } else { + result[i] = CellState.Wrong; + } + } + return result; +} \ No newline at end of file diff --git a/src/main.jsx b/src/main.jsx new file mode 100644 index 0000000..a322471 --- /dev/null +++ b/src/main.jsx @@ -0,0 +1,7 @@ +import React from "react"; + +import { createRoot } from 'react-dom/client'; +import {App} from "./components/App"; + +const root = createRoot(document.getElementById("app")); +root.render(); \ No newline at end of file diff --git a/src/model/CellState.js b/src/model/CellState.js new file mode 100644 index 0000000..8b19e65 --- /dev/null +++ b/src/model/CellState.js @@ -0,0 +1,26 @@ +import {makeEnum} from "../utils"; + +export const CellState = makeEnum([ + "Unknown", + "Wrong", + "HalfRight", + "Right" +]); + +const cellStateOrder = (cellState) => { + switch (cellState) { + case CellState.Unknown: return 0; + case CellState.Wrong: return 1; + case CellState.HalfRight: return 2; + case CellState.Right: return 3; + default: return 0; + } +} + +export const sortCellStates = (a, b) => { + if (cellStateOrder(a) > cellStateOrder(b)) { + return 1; + } else { + return -1; + } +} \ No newline at end of file diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..8fcb64d --- /dev/null +++ b/src/utils.js @@ -0,0 +1,28 @@ + +export const range = (from, to) => { + if (to === undefined) { + return [...Array(from).keys()]; + } else { + return [...Array(to - from).keys()].map(value => value + from); + } +} + +export const zip = (array1, array2) => array1.map((element, index) => [element, array2[index]]); + +export const id = obj => obj; + +export const objectMap = (obj, func) => { + const result = {}; + for (let key in obj) { + result[key] = func(obj[key], key); + } + return result; +} + +export const makeEnum = values => { + const obj = {}; + for (const value of values) { + obj[value] = value; + } + return Object.freeze(obj); +} \ No newline at end of file