@@ -3,6 +3,7 @@ import "./App.css";
33import { pick_random_word } from "./main.ts" ;
44import { get_definition } from "./main.ts" ;
55import { is_valid } from "./main.ts" ;
6+ import "animate.css" ;
67
78
89function Square ( { letter, colors, onSquareClick } ) {
@@ -13,18 +14,39 @@ function Square( { letter, colors, onSquareClick } ) {
1314
1415function Word ( { current_attempt, success} ) {
1516 let color = "" ;
16- if ( success ) color = "square-attempted-present" ;
17+ let success_animation = "" ;
18+ if ( success ) {
19+ color = "square-attempted-present" ;
20+ success_animation = "animate__animated animate__flip" ;
21+ }
1722 return < >
18- < button key = "0" className = { `square word ${ color } ` } > { current_attempt . length > 0 ? current_attempt [ 0 ] : '' } </ button >
19- < button key = "1" className = { `square word ${ color } ` } > { current_attempt . length > 1 ? current_attempt [ 1 ] : '' } </ button >
20- < button key = "2" className = { `square word ${ color } ` } > { current_attempt . length > 2 ? current_attempt [ 2 ] : '' } </ button >
21- < button key = "3" className = { `square word ${ color } ` } > { current_attempt . length > 3 ? current_attempt [ 3 ] : '' } </ button >
22- < button key = "4" className = { `square word ${ color } ` } > { current_attempt . length > 4 ? current_attempt [ 4 ] : '' } </ button >
23+ < button key = "0" className = { `square word ${ color } ${ success_animation } ` } > { current_attempt . length > 0 ? current_attempt [ 0 ] : '' } </ button >
24+ < button key = "1" className = { `square word ${ color } ${ success_animation } ` } > { current_attempt . length > 1 ? current_attempt [ 1 ] : '' } </ button >
25+ < button key = "2" className = { `square word ${ color } ${ success_animation } ` } > { current_attempt . length > 2 ? current_attempt [ 2 ] : '' } </ button >
26+ < button key = "3" className = { `square word ${ color } ${ success_animation } ` } > { current_attempt . length > 3 ? current_attempt [ 3 ] : '' } </ button >
27+ < button key = "4" className = { `square word ${ color } ${ success_animation } ` } > { current_attempt . length > 4 ? current_attempt [ 4 ] : '' } </ button >
28+ </ >
29+ }
30+
31+ function Logo ( ) {
32+ return < >
33+ < div id = "logo" className = "animate__animated animate__slideInDown" >
34+ < h1 > ERUDITE</ h1 >
35+ </ div >
36+ </ >
37+ }
38+
39+ function Definition ( { word, definition } ) {
40+ return < >
41+ < div id = "definition" key = { word } >
42+ < p className = "animate__animated animate__fadeInDown" > { definition } </ p >
43+ </ div >
2344 </ >
2445}
2546
2647function App ( ) {
2748 const [ current_word , setCurrentWord ] = useState ( pick_random_word ( 5 ) . toUpperCase ( ) ) ;
49+ const [ current_definition , setCurrentDefinition ] = useState ( get_definition ( current_word . toLowerCase ( ) ) ) ;
2850 const [ score , setScore ] = useState ( 0 ) ;
2951 const [ success , setSuccess ] = useState ( false ) ;
3052 const [ current_attempt , setCurrentAttempt ] = useState ( '' ) ;
@@ -63,7 +85,10 @@ function App() {
6385
6486 if ( current_attempt != current_word ) {
6587 setMessage ( "Incorrect" ) ;
66- setTimeout ( ( ) => { setMessage ( "" ) ; } , 3000 ) ;
88+
89+ setTimeout ( ( ) => {
90+ setMessage ( "" ) ;
91+ } , 3000 ) ;
6792
6893 setAttempts ( [
6994 ...attempts ,
@@ -96,7 +121,9 @@ function App() {
96121 setSuccess ( false ) ;
97122 setMessage ( "" ) ;
98123 setTimeout ( ( ) => { setMessage ( "" ) ; } , 3000 ) ;
99- setCurrentWord ( pick_random_word ( 5 ) . toUpperCase ( ) ) ;
124+ const new_word = pick_random_word ( 5 ) . toUpperCase ( ) ;
125+ setCurrentWord ( new_word ) ;
126+ setCurrentDefinition ( get_definition ( new_word . toLowerCase ( ) ) ) ;
100127 setCurrentAttempt ( "" ) ;
101128 setKeyboardColors ( Array ( 26 ) . fill ( "square-unattempted" ) ) ;
102129 }
@@ -111,13 +138,8 @@ function App() {
111138 < span > version: 0.1 - Game developed by < a href = "https://github.com/cathoderay" > Ronald Kaiser</ a > </ span >
112139 </ div >
113140
114- < div id = "logo" >
115- < h1 > ERUDITE</ h1 >
116- </ div >
117-
118- < div id = "definition" >
119- < p > { get_definition ( current_word . toLowerCase ( ) ) } </ p >
120- </ div >
141+ < Logo />
142+ < Definition word = { current_word } definition = { current_definition } />
121143
122144 < div id = "word-container" >
123145 < Word current_attempt = { current_attempt } current_word = { current_word } success = { success } />
0 commit comments