@@ -7,7 +7,14 @@ import chor from "../assets/chor.png";
7
7
import dakat from "../assets/dakat.png" ;
8
8
import { Button } from "antd" ;
9
9
10
- const GutiButton = ( { playerName, shufArray, restart, scores, addScore, setScore } ) => {
10
+ const GutiButton = ( {
11
+ playerName,
12
+ shufArray,
13
+ restart,
14
+ scores,
15
+ addScore,
16
+ setScore,
17
+ } ) => {
11
18
const [ showButton , setShowButton ] = useState ( true ) ;
12
19
const [ showImage , setShowImage ] = useState ( false ) ;
13
20
const [ selectedButton , setSelectedButton ] = useState ( null ) ;
@@ -17,7 +24,7 @@ const GutiButton = ({ playerName, shufArray, restart, scores, addScore, setScore
17
24
const [ policeGuess , setPoliceGuess ] = useState ( - 1 ) ;
18
25
const [ isChor , setIsChor ] = useState ( true ) ;
19
26
const gotImage = [ chor , dakat , police , babu ] ;
20
- const bangla = [ "চোর" , "ডাকাত" , "পুলিশ" , "বাবু" ] ;
27
+ const bangla = [ "চোর" , "ডাকাত" , "পুলিশ" , "বাবু" ] ;
21
28
var curscore = [ 0 , 0 , 0 , 0 ] ;
22
29
23
30
var selectedIndex ;
@@ -36,7 +43,7 @@ const GutiButton = ({ playerName, shufArray, restart, scores, addScore, setScore
36
43
const tmp = shufArray [ index ] ;
37
44
shufArray [ index ] = shufArray [ 0 ] ;
38
45
shufArray [ 0 ] = tmp ;
39
- // console.log("after" + shufArray);
46
+ console . log ( "after" + shufArray ) ;
40
47
setSelectedImage ( shufArray [ 0 ] ) ;
41
48
42
49
// TODO : DISTRIBUTE 3 to ai
@@ -60,32 +67,28 @@ const GutiButton = ({ playerName, shufArray, restart, scores, addScore, setScore
60
67
}
61
68
}
62
69
63
- function getChorDakat ( ) {
70
+ function getChorDakat ( ) {
64
71
var ans = [ ] ;
65
- for ( var i = 0 ; i < 4 ; i ++ ) {
66
- if ( shufArray [ i ] < 2 ) ans . push ( i ) ;
72
+ for ( var i = 0 ; i < 4 ; i ++ ) {
73
+ if ( shufArray [ i ] < 2 ) ans . push ( playerName [ i ] ) ;
67
74
}
68
75
return ans ;
69
76
}
70
77
71
- function isPoliceCorrect ( ) {
72
- if ( isChor && shufArray [ policeGuess ] == 0 ) return true ;
73
- else if ( ! isChor && shufArray [ policeGuess ] == 1 ) return true ;
74
- else {
78
+ function isPoliceCorrect ( ) {
79
+ if ( policeGuess === - 1 ) {
75
80
const currentTimestamp = new Date ( ) . getTime ( ) ;
76
- const randomValue = currentTimestamp % 2 ;
77
-
78
- if ( randomValue == 0 ) {
79
- return true ;
80
- }
81
- else return false ;
81
+ const randomValue = currentTimestamp % 2 ;
82
+ setPoliceGuess ( getChorDakat ( ) [ randomValue ] ) ;
82
83
}
84
+ if ( isChor && policeGuess === getPolice ( 0 ) ) return true ;
85
+ else if ( ! isChor && policeGuess === getPolice ( 1 ) ) return true ;
83
86
return false ;
84
87
}
85
88
86
89
function getScore ( ) {
87
90
const newScores = [ 0 , 0 , 0 , 0 ] ; // Create a new array to store the updated scores
88
-
91
+
89
92
for ( let i = 0 ; i < 4 ; i ++ ) {
90
93
if ( shufArray [ i ] === 3 ) newScores [ i ] = 100 ;
91
94
else if ( shufArray [ i ] === 2 && isPoliceCorrect ( ) ) newScores [ i ] = 80 ;
@@ -99,27 +102,32 @@ else if(!isChor && shufArray[policeGuess] == 1) return true;
99
102
} else newScores [ i ] = 40 ;
100
103
}
101
104
}
102
-
105
+
103
106
return newScores ;
104
107
}
105
-
106
108
107
109
return (
108
110
< Wrapper >
109
111
< div className = "guti-buttons" >
110
112
< div className = "gutis" >
111
113
{ lastState && (
112
114
< div className = "last-card" >
113
- { isPoliceCorrect ( ) ? "পুলিশ সঠিক ধরেছেন" : "পুলিশ ভূল ধরেছেন" } < br />
114
- চোর < span > { isChor && isPoliceCorrect ( ) ? "+০" : "+৪০" } </ span > < br />
115
- ডাকাত < span > { ! isChor && isPoliceCorrect ( ) ? "+০" : "+৬০" } </ span > < br />
115
+ { isPoliceCorrect ( ) ? "পুলিশ সঠিক ধরেছেন" : "পুলিশ ভূল ধরেছেন" } { " " }
116
+ < br />
117
+ চোর < span > { isChor && isPoliceCorrect ( ) ? "+০" : "+৪০" } </ span > { " " }
118
+ < br />
119
+ ডাকাত < span >
120
+ { ! isChor && isPoliceCorrect ( ) ? "+০" : "+৬০" }
121
+ </ span > { " " }
122
+ < br />
116
123
বাবু < span > +১০০</ span > < br />
117
124
পুলিশ < span > { isPoliceCorrect ( ) ? "+৮০" : "+০" } </ span > < br />
118
125
< Button
119
126
onClick = { ( ) => {
120
127
setLastState ( false ) ;
121
- curscore = getScore ( ) ;
122
- setScore ( addScore ( curscore , scores ) ) ;
128
+ curscore = getScore ( ) ;
129
+ setScore ( addScore ( curscore , scores ) ) ;
130
+ setPoliceGuess ( - 1 ) ;
123
131
restart ( ) ;
124
132
} }
125
133
>
@@ -152,29 +160,35 @@ else if(!isChor && shufArray[policeGuess] == 1) return true;
152
160
</ div >
153
161
</ div >
154
162
</ div >
155
- < div > < center > { isChor == true ? "চোর কে ধরুন" : "ডাকাত কে ধরুন" } </ center > </ div >
163
+ < div >
164
+ { " " }
165
+ < center >
166
+ { " " }
167
+ { isChor == true ? "চোর কে ধরুন" : "ডাকাত কে ধরুন" } { " " }
168
+ </ center > { " " }
169
+ </ div >
156
170
< div className = "police-state-btm" >
157
171
{ selectedImage == 2 && (
158
172
< div classsName = "police-state-btm" >
159
173
< Button
160
174
className = "jayga"
161
175
onClick = { ( ) => {
162
176
setLastState ( true ) ;
163
- setPoliceState ( false ) ;
164
- setPoliceGuess ( ( getChorDakat ( ) ) [ 0 ] ) ;
177
+ setPoliceState ( false ) ;
178
+ setPoliceGuess ( getChorDakat ( ) [ 0 ] ) ;
165
179
} }
166
180
>
167
- { ( getChorDakat ( ) ) [ 0 ] }
181
+ { getChorDakat ( ) [ 0 ] }
168
182
</ Button >
169
183
< Button
170
184
className = "jayga"
171
185
onClick = { ( ) => {
172
186
setLastState ( true ) ;
173
187
setPoliceState ( false ) ;
174
- setPoliceGuess ( ( getChorDakat ( ) ) [ 1 ] ) ;
188
+ setPoliceGuess ( getChorDakat ( ) [ 1 ] ) ;
175
189
} }
176
190
>
177
- { ( getChorDakat ( ) ) [ 1 ] }
191
+ { getChorDakat ( ) [ 1 ] }
178
192
</ Button >
179
193
</ div >
180
194
) }
0 commit comments