Skip to content

Commit

Permalink
Fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MycroftKang committed Jan 10, 2024
1 parent 0514351 commit 0a9920e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/lib/suikaGame/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ interface HeaderProps {
bombItemCount: number;
nextItem: null | Fruit | SpecialItem;
onClick: () => void;
isStart: boolean;
}

const Header = ({ score, bestScore, bombItemCount, nextItem, onClick }: HeaderProps) => {
const Header = ({ score, bestScore, bombItemCount, nextItem, onClick, isStart }: HeaderProps) => {
const [isAnimating, setIsAnimating] = useState(false);

const getBestScore = () => {
Expand All @@ -28,14 +29,16 @@ const Header = ({ score, bestScore, bombItemCount, nextItem, onClick }: HeaderPr
if (bombItemCount > 0) {
bombItemClass = 'bg-danger';
}

if (lastBombItemCount != undefined && bombItemCount > lastBombItemCount) {
setIsAnimating(true);
setTimeout(() => setIsAnimating(false), 1000);

if (isStart) {
if ((lastBombItemCount != undefined && bombItemCount > lastBombItemCount)) {
setIsAnimating(true);
setTimeout(() => setIsAnimating(false), 1000);
}

lastBombItemCount = bombItemCount;
}

lastBombItemCount = bombItemCount;

return (
<div className={cx('headerArea')} style={{ maxWidth: getRenderWidth() + 4 }}>
<div className={cx('bestScoreArea')}>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/suikaGame/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SuikaGame = () => {

const handleTryAgain = () => {
setScore(0);
setBombItemCount(0);
// setBombItemCount(0);
setNextItem(getRandomFruitFeature()?.label as Fruit);
setIsGameOver(false);
clear();
Expand All @@ -68,7 +68,7 @@ const SuikaGame = () => {
<div className={cx('gameArea')}>
<div className={cx('gameWrap')} style={{ visibility: isStart ? 'visible' : 'hidden'}}>
<div className={cx('canvasArea')}>
<Header bestScore={bestScore} score={score} bombItemCount={bombItemCount} nextItem={nextItem} onClick={handleBombItem}/>
<Header bestScore={bestScore} score={score} bombItemCount={bombItemCount} nextItem={nextItem} onClick={handleBombItem} isStart={isStart} />
<div id={'canvasWrap'} className={cx('canvasWrap')}/>
</div>
</div>
Expand Down

0 comments on commit 0a9920e

Please sign in to comment.