Skip to content

Commit

Permalink
fix: fixed the bug of knowledge game
Browse files Browse the repository at this point in the history
  • Loading branch information
dearDreamWeb committed Feb 26, 2024
1 parent 61014dc commit 833f637
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/gameRender/gameRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const GameRender = () => {
if (rate > 0.92 && roleStore.coins >= 20) {
randomIndex = 3;
} else {
randomIndex = Math.floor(random() * gameList.length);
randomIndex = Math.floor(random() * (gameList.length - 1));
}
// randomIndex = 3;
// randomIndex = 2;
console.log('random game', randomIndex, gameList.length);
setStartGame(true);
setGameIndex(randomIndex);
Expand Down
7 changes: 6 additions & 1 deletion src/components/knowledgeGame/knowledgeGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const KnowledgeGame = (props: KnowledgeGameProps) => {
const [showDetails, setShowDetails] = useState(false);
const timer = useRef<NodeJS.Timer | null>(null);
const [seconds, setSeconds] = useState(QUESTTIME);
const isGameSettlement = useRef(false);

const getRandomIndex = (selectedList: number[], size: number): number => {
const random = Math.floor(Math.random() * size);
Expand Down Expand Up @@ -77,19 +78,23 @@ const KnowledgeGame = (props: KnowledgeGameProps) => {
questionsList
);
if (currentIndex === questionsList.length - 1) {
timer.current && clearInterval(timer.current);
timer.current = null;
setGameOver(true);
return;
}
setCurrentIndex(currentIndex + 1);
};

const isWin = useMemo(() => {
if (!gameOver) {
if (!gameOver || isGameSettlement.current) {
return false;
}
console.log('----', gameOver, resultList, questionsList);
const result =
resultList.filter((item) => item.right).length >=
questionsList.length / 2;
isGameSettlement.current = true;
globalStore.gameSettlement(
result ? GameResultStatus.win : GameResultStatus.loss
);
Expand Down

0 comments on commit 833f637

Please sign in to comment.