hangman-react-game 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -220,4 +220,4 @@ export {
220
220
  Game_default as Game,
221
221
  useGame_default as useGame
222
222
  };
223
- //# sourceMappingURL=index.mjs.map
223
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hangman-react-game",
3
- "version": "1.0.4",
4
- "main": "dist/index.js",
3
+ "version": "1.0.6",
4
+ "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
7
7
  "exports": {
@@ -10,6 +10,9 @@
10
10
  "types": "./dist/types/index.d.ts"
11
11
  }
12
12
  },
13
+ "files": [
14
+ "dist"
15
+ ],
13
16
  "scripts": {
14
17
  "build": "tsup"
15
18
  },
@@ -18,9 +21,6 @@
18
21
  "react-dom": "^19.0.0"
19
22
  },
20
23
  "devDependencies": {
21
- "@rollup/plugin-babel": "^6.0.3",
22
- "@rollup/plugin-commonjs": "^24.0.1",
23
- "@rollup/plugin-node-resolve": "^15.0.1",
24
24
  "@types/react": "^19.1.13",
25
25
  "@types/react-dom": "^19.1.9",
26
26
  "rollup": "^3.29.0",
@@ -1,38 +0,0 @@
1
- import useGame from "../hooks/useGame";
2
- import Hangman from "./Hangman";
3
-
4
- const Game = () => {
5
- const {
6
- newWord,
7
- hasEnded,
8
- hasWon,
9
- failedAttempts,
10
- guessLetter,
11
- guessedLetters,
12
- word
13
- } = useGame();
14
- return (
15
- <div>
16
- <h1>Hangman game</h1>
17
- <div className="word">
18
- <p>{word}</p>
19
- </div>
20
- <div className="hangman-illustrtion">
21
- <Hangman failedAttempts={failedAttempts} />
22
- </div>
23
- <div className="guessButtons">
24
- {"abcdefghijklmnopqrstuvwxyz".split("").map(x => (
25
- <button key={x} onClick={() => guessLetter(x)} disabled={hasEnded || guessedLetters.includes(x)}>{x}</button>
26
- ))}
27
- </div>
28
- {hasEnded && (
29
- <div className="game-over">
30
- {hasWon && (<h1>Yay, you won</h1>)}
31
- {!hasWon && (<h1>Too bad, you lose</h1>)}
32
- </div>
33
- )}
34
- <button onClick={newWord}>New word</button>
35
- </div>
36
- )
37
- };
38
- export default Game;
@@ -1,32 +0,0 @@
1
- import { ReactElement, useEffect } from "react";
2
-
3
- type HangmanProps = {
4
- failedAttempts: number
5
- }
6
-
7
- const Hangman = ({failedAttempts} : HangmanProps) => {
8
- useEffect(() => {}, [failedAttempts]);
9
- const hangmanParts : ReactElement[] = [
10
- // ROD
11
- <line x1="20" y1="230" x2="100" y2="230" stroke="black" />,
12
- <line x1="60" y1="20" x2="60" y2="230" stroke="black" />,
13
- <line x1="60" y1="20" x2="140" y2="20" stroke="black" />,
14
- <line x1="140" y1="20" x2="140" y2="50" stroke="black" />,
15
- // HEAD
16
- <circle cx="140" cy="70" r="20" stroke="black" />,
17
- // BODY
18
- <line x1="140" y1="90" x2="140" y2="150" stroke="black" />,
19
- // ARMS
20
- <line x1="140" y1="120" x2="120" y2="100" stroke="black" />,
21
- <line x1="140" y1="120" x2="160" y2="100" stroke="black" />,
22
- // LEGS
23
- <line x1="140" y1="150" x2="120" y2="180" stroke="black" />,
24
- <line x1="140" y1="150" x2="160" y2="180" stroke="black" />
25
- ];
26
- return (
27
- <svg height="250" width="200">
28
- {hangmanParts.slice(0, failedAttempts)}
29
- </svg>
30
- )
31
- }
32
- export default Hangman;
@@ -1,173 +0,0 @@
1
- import {useEffect, useState} from "react";
2
-
3
- const MAX_FAILED_ATTEMPTS = 10;
4
- const wordDictionary = [
5
- "apple",
6
- "banana",
7
- "cherry",
8
- "date",
9
- "elderberry",
10
- "fig",
11
- "grape",
12
- "honeydew",
13
- "kiwi",
14
- "lemon",
15
- "mango",
16
- "nectarine",
17
- "orange",
18
- "papaya",
19
- "quince",
20
- "raspberry",
21
- "strawberry",
22
- "tangerine",
23
- "ugli",
24
- "vanilla",
25
- "watermelon",
26
- "xigua",
27
- "yellow",
28
- "zucchini",
29
- "abstract",
30
- "breeze",
31
- "cactus",
32
- "dolphin",
33
- "eagle",
34
- "forest",
35
- "giraffe",
36
- "horizon",
37
- "island",
38
- "jungle",
39
- "kaleidoscope",
40
- "lighthouse",
41
- "mountain",
42
- "nebula",
43
- "ocean",
44
- "prairie",
45
- "quasar",
46
- "rainbow",
47
- "sunrise",
48
- "tornado",
49
- "universe",
50
- "volcano",
51
- "whale",
52
- "xerox",
53
- "yacht",
54
- "zephyr",
55
- "albatross",
56
- "butterfly",
57
- "chameleon",
58
- "dinosaur",
59
- "elephant",
60
- "flamingo",
61
- "gazelle",
62
- "hippopotamus",
63
- "iguana",
64
- "jellyfish",
65
- "kangaroo",
66
- "lion",
67
- "monkey",
68
- "narwhal",
69
- "octopus",
70
- "penguin",
71
- "quail",
72
- "rhinoceros",
73
- "squirrel",
74
- "turtle",
75
- "umbrella",
76
- "vulture",
77
- "walrus",
78
- "xylophone",
79
- "yak",
80
- "zebra",
81
- "astronomy",
82
- "biology",
83
- "chemistry",
84
- "democracy",
85
- "ecosystem",
86
- "fossil",
87
- "genetics",
88
- "hypothesis",
89
- "innovation",
90
- "jurisdiction",
91
- "kinetic",
92
- "laboratory",
93
- "meteorology",
94
- "neuroscience",
95
- "observation",
96
- "physics",
97
- "quantum",
98
- "robotics",
99
- "synthesis",
100
- "theorem",
101
- "unicorn",
102
- "velocity",
103
- "wavelength",
104
- "xenon",
105
- "youth",
106
- "zenith",
107
- "bamboozlement",
108
- "flabbergasted",
109
- "hypothetical",
110
- "juxtaposition",
111
- "labyrinthine",
112
- "nebulousness",
113
- "quintessential",
114
- "sesquipedalian",
115
- "transcendental",
116
- "unpredictable",
117
- "verisimilitude",
118
- "whippersnapper",
119
- "xenotransplant",
120
- "yesteryear",
121
- "zigzaggedness"
122
- ];
123
-
124
- const useGame = () => {
125
- // Should fetch random word from a dictionary (maybe vary by language)
126
- const [word, setWord] = useState("");
127
- const [guessedLetters, setGuessedLetters] = useState<string[]>([]);
128
- const [failedAttempts, setFailedAttempts] = useState<number>(0);
129
- const [hasEnded, setHasEnded] = useState(false);
130
- const [hasWon, setHasWon] = useState(false);
131
-
132
- const censorWord = (w: string) => w.split("").map(x => (guessedLetters.includes(x) || x === " " ? x : "_") + " ").join("");
133
- const newWord = () => setWord( wordDictionary[Math.floor( Math.random() * wordDictionary.length )]);
134
-
135
- const guessLetter = async (letter : string) => {
136
- if(!hasEnded && letter.length === 1){
137
- if(!word.includes(letter))
138
- setFailedAttempts(failedAttempts+1);
139
- setGuessedLetters([...guessedLetters, letter]);
140
- }
141
- }
142
-
143
- useEffect(()=> newWord(), [])
144
- useEffect(()=> {
145
- setGuessedLetters([]);
146
- setFailedAttempts(0);
147
- setHasEnded(false);
148
- setHasWon(false);
149
- }, [word]);
150
-
151
- useEffect(()=> {
152
- if(failedAttempts >= MAX_FAILED_ATTEMPTS)
153
- setHasEnded(true);
154
- }, [failedAttempts]);
155
-
156
- useEffect(()=> {
157
- if(word && !censorWord(word).includes("_")) {
158
- setHasWon(true);
159
- setHasEnded(true);
160
- }
161
- }, [guessedLetters]);
162
-
163
- return {
164
- newWord,
165
- hasEnded,
166
- hasWon,
167
- failedAttempts,
168
- guessLetter,
169
- guessedLetters,
170
- word : hasEnded ? word : censorWord(word)
171
- };
172
- }
173
- export default useGame;
package/src/index.tsx DELETED
@@ -1,4 +0,0 @@
1
- import Game from "./components/Game";
2
- import useGame from "./hooks/useGame";
3
-
4
- export {Game, useGame};
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "jsx": "react-jsx",
6
- "declaration": true,
7
- "declarationDir": "dist/types",
8
- "outDir": "dist",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "moduleResolution": "node"
13
- },
14
- "include": ["src"]
15
- }
package/tsup.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: ['src/index.tsx'],
5
- format: ['esm'],
6
- dts: true,
7
- sourcemap: true,
8
- clean: true,
9
- external: ['react', 'react-dom'],
10
- });
File without changes
File without changes