Skip to content

Commit 95aa120

Browse files
committed
fixed ai score issue and other UI releted issues
1 parent 467ace5 commit 95aa120

File tree

6 files changed

+64
-51
lines changed

6 files changed

+64
-51
lines changed

FrontendTemplate/src/components/GutiButton.jsx

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import chor from "../assets/chor.png";
77
import dakat from "../assets/dakat.png";
88
import { Button } from "antd";
99

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+
}) => {
1118
const [showButton, setShowButton] = useState(true);
1219
const [showImage, setShowImage] = useState(false);
1320
const [selectedButton, setSelectedButton] = useState(null);
@@ -17,7 +24,7 @@ const GutiButton = ({ playerName, shufArray, restart, scores, addScore, setScore
1724
const [policeGuess, setPoliceGuess] = useState(-1);
1825
const [isChor, setIsChor] = useState(true);
1926
const gotImage = [chor, dakat, police, babu];
20-
const bangla = ["চোর", "ডাকাত", "পুলিশ", "বাবু"];
27+
const bangla = ["চোর", "ডাকাত", "পুলিশ", "বাবু"];
2128
var curscore = [0, 0, 0, 0];
2229

2330
var selectedIndex;
@@ -36,7 +43,7 @@ const GutiButton = ({ playerName, shufArray, restart, scores, addScore, setScore
3643
const tmp = shufArray[index];
3744
shufArray[index] = shufArray[0];
3845
shufArray[0] = tmp;
39-
//console.log("after" + shufArray);
46+
console.log("after" + shufArray);
4047
setSelectedImage(shufArray[0]);
4148

4249
// TODO : DISTRIBUTE 3 to ai
@@ -60,32 +67,28 @@ const GutiButton = ({ playerName, shufArray, restart, scores, addScore, setScore
6067
}
6168
}
6269

63-
function getChorDakat(){
70+
function getChorDakat() {
6471
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]);
6774
}
6875
return ans;
6976
}
7077

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) {
7580
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]);
8283
}
84+
if (isChor && policeGuess === getPolice(0)) return true;
85+
else if (!isChor && policeGuess === getPolice(1)) return true;
8386
return false;
8487
}
8588

8689
function getScore() {
8790
const newScores = [0, 0, 0, 0]; // Create a new array to store the updated scores
88-
91+
8992
for (let i = 0; i < 4; i++) {
9093
if (shufArray[i] === 3) newScores[i] = 100;
9194
else if (shufArray[i] === 2 && isPoliceCorrect()) newScores[i] = 80;
@@ -99,27 +102,32 @@ else if(!isChor && shufArray[policeGuess] == 1) return true;
99102
} else newScores[i] = 40;
100103
}
101104
}
102-
105+
103106
return newScores;
104107
}
105-
106108

107109
return (
108110
<Wrapper>
109111
<div className="guti-buttons">
110112
<div className="gutis">
111113
{lastState && (
112114
<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 />
116123
বাবু <span>+১০০</span> <br />
117124
পুলিশ <span>{isPoliceCorrect() ? "+৮০" : "+০"}</span> <br />
118125
<Button
119126
onClick={() => {
120127
setLastState(false);
121-
curscore = getScore();
122-
setScore(addScore(curscore, scores));
128+
curscore = getScore();
129+
setScore(addScore(curscore, scores));
130+
setPoliceGuess(-1);
123131
restart();
124132
}}
125133
>
@@ -152,29 +160,35 @@ else if(!isChor && shufArray[policeGuess] == 1) return true;
152160
</div>
153161
</div>
154162
</div>
155-
<div> <center> {isChor == true ? "চোর কে ধরুন" : "ডাকাত কে ধরুন" } </center> </div>
163+
<div>
164+
{" "}
165+
<center>
166+
{" "}
167+
{isChor == true ? "চোর কে ধরুন" : "ডাকাত কে ধরুন"}{" "}
168+
</center>{" "}
169+
</div>
156170
<div className="police-state-btm">
157171
{selectedImage == 2 && (
158172
<div classsName="police-state-btm">
159173
<Button
160174
className="jayga"
161175
onClick={() => {
162176
setLastState(true);
163-
setPoliceState(false);
164-
setPoliceGuess((getChorDakat())[0]);
177+
setPoliceState(false);
178+
setPoliceGuess(getChorDakat()[0]);
165179
}}
166180
>
167-
{(getChorDakat())[0]}
181+
{getChorDakat()[0]}
168182
</Button>
169183
<Button
170184
className="jayga"
171185
onClick={() => {
172186
setLastState(true);
173187
setPoliceState(false);
174-
setPoliceGuess((getChorDakat())[1]);
188+
setPoliceGuess(getChorDakat()[1]);
175189
}}
176190
>
177-
{(getChorDakat())[1]}
191+
{getChorDakat()[1]}
178192
</Button>
179193
</div>
180194
)}

FrontendTemplate/src/components/ShakeHand.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ const Wrapper = styled.section `
7979
font-size: 20px;
8080
height: 40px;
8181
width: 200px;
82-
display: inline-block;
82+
display: flex;
83+
justify-content: center;
84+
align-items: center;
8385
padding: 10px 20px;
8486
border: none;
8587
border-radius: 20px;

FrontendTemplate/src/components/gameControllers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export function updateScore(scores, move, guess) {
2929
var police;
3030

3131
for (let i = 0; i < 4; i++) {
32-
if (move[i] == 0) score[i] = 40;
33-
else if (move[i] == 1) score[i] = 60;
34-
else if (move[i] == 3) score[i] = 100;
35-
else if (move[i] == 2) {
32+
if (move[i] === 0) score[i] = 40;
33+
else if (move[i] === 1) score[i] = 60;
34+
else if (move[i] === 3) score[i] = 100;
35+
else if (move[i] === 2) {
3636
score[i] = 80;
3737
police = i;
3838
}

FrontendTemplate/src/pages/ai_page/AIPage.jsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "./AIPage.css";
22
import { FloatButton } from "antd";
33
import { CommentOutlined } from "@ant-design/icons";
4-
import ChatModal from "../../components/ChatModal";
54
import { useEffect, useState } from "react";
65
import GameBoard from "../../components/GameBoard";
76

@@ -58,7 +57,7 @@ export default function AIPage() {
5857
console.log("Scoreee isss: ");
5958
// console.log(scores[0][scores[0].length - 1]);
6059
var maxScore = Math.max(...totalScore);
61-
if (maxScore >= 140) {
60+
if (maxScore >= 1500) {
6261
setIsGameOver(true);
6362
console.log(isGameOver);
6463
console.log("yes i am true");
@@ -105,11 +104,13 @@ export default function AIPage() {
105104
const randomValue = currentTimestamp % 19;
106105
const a = peopleNames[randomValue];
107106
const b = peopleNames[randomValue + 1];
108-
const c = peopleNames[randomValue + 2];
107+
const c = peopleNames[randomValue + 2];
109108

110109
setSelectedNames([userData.username, a, b, c]);
110+
const tmpScore = [[userData.username], [a], [b], [c]];
111+
console.log(tmpScore);
111112

112-
setScore([[userData.username], [a], [b], [c]]);
113+
setScore(tmpScore);
113114

114115
initiated = true;
115116
}
@@ -120,24 +121,15 @@ export default function AIPage() {
120121

121122
return (
122123
<>
123-
{isGameOver ? (
124+
{isGameOver && (
124125
<ScoreModal
125126
isGameOver={isGameOver}
126127
setIsGameOver={setIsGameOver}
127128
scores={scores}
128129
finalScore={finalScore}
129130
rank={rank}
130131
/>
131-
) : (
132-
<ChatModal isModalOpen={isModalOpen} setIsModalOpen={setIsModalOpen} />
133132
)}
134-
135-
<FloatButton
136-
icon={<CommentOutlined />}
137-
onClick={() => {
138-
setIsModalOpen(true);
139-
}}
140-
/>
141133
<div className="ai-canvas">
142134
<div className="ai-left">
143135
<GameBoard

FrontendTemplate/src/pages/landing_page/LandingPage.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* Default styles for larger screens */
2+
body {
3+
background-image: linear-gradient(to right, #d3cce3, #e9e4f0);
4+
}
5+
26
.landing-canvas {
37
display: flex;
48
height: 100vh;
@@ -44,6 +48,7 @@
4448

4549
/* Media query for mobile devices (max-width: 768px) */
4650
@media screen and (max-width: 768px) {
51+
4752
.landing-canvas {
4853
margin-top: 5vh;
4954
flex-direction: column;

FrontendTemplate/src/pages/landing_page/LandingPage.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function LandingPage() {
1616
}
1717

1818
return (
19-
<>
19+
<div className="bg-gradient">
2020
<div className="landing-canvas">
2121
<div className="landing-left">
2222
<img src={appLogo} alt="Chor Dakat Babu Police" />
@@ -41,6 +41,6 @@ export default function LandingPage() {
4141
}}>continue</Button>
4242
</div>
4343
</div>
44-
</>
44+
</div>
4545
);
4646
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy