Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/game/game-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hex } from './Hex';

export const MAX_PLAYERS = 4;
export const START_GRID_RADIUS = 3;
export const MOVE_DURATION_IN_SECONDS = 15;
export const MOVE_DURATION_IN_SECONDS = 10;

export function isNeighbor(hex: Hex, other: Hex) {
return hex.neighbors().some((n) => n.equals(other));
Expand Down
13 changes: 2 additions & 11 deletions apps/web/src/components/Game/GameStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { useGame } from '../../providers/GameProvider';
import { useLocation } from 'wouter';
import DarkContainer from '../DarkContainer';
import PlayerTagContainer from '../PlayerTag';

const getColor = (time: number) => {
if (time > 5000) return 'lightgreen';
if (time > 2000) return 'orange';
return 'red';
};
import ProgressBarTimer from '../ProgressBarTimer';

export const GameStatus = () => {
const queryClient = useQueryClient();
Expand Down Expand Up @@ -38,11 +33,7 @@ export const GameStatus = () => {
return (
<div className={c.statusWrapper}>
{gameState?.started && !gameState.draw && !gameContainsWinner && (
<span
className={c.timerText}
style={{ color: getColor(timeRemaining) }}>
{Math.round(timeRemaining / 1000)}
</span>
<ProgressBarTimer timeRemaining={timeRemaining} />
)}
{!gameState?.started && (
<DarkContainer className={c.fixedTop}>
Expand Down
20 changes: 20 additions & 0 deletions apps/web/src/components/ProgressBarTimer/ProgressBarTimer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MOVE_DURATION_IN_SECONDS } from '../../utils/calculation-utils';
import c from './style.module.css';

type Props = {
timeRemaining: number;
};

const ProgressBarTimer: React.FC<Props> = ({ timeRemaining }) => {
return (
<div className={c.wrapper}>
<div
style={{
width: `${timeRemaining / ((MOVE_DURATION_IN_SECONDS * 1000) / 100)}%`,
}}
className={c.bar}></div>
</div>
);
};

export default ProgressBarTimer;
3 changes: 3 additions & 0 deletions apps/web/src/components/ProgressBarTimer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ProgressBarTimer from './ProgressBarTimer';

export default ProgressBarTimer;
16 changes: 16 additions & 0 deletions apps/web/src/components/ProgressBarTimer/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.wrapper {
position: fixed;
top: 100px;
left: 50%;
transform: translateX(-50%);
max-width: 400px;
width: 100%;
height: 20px;
background: #1b1f2d;
border: 4px solid #1b1f2d;
}

.bar {
background: #f2e2b7;
height: 100%;
}
7 changes: 1 addition & 6 deletions apps/web/src/hooks/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ export const useInitializeSockets = (
});
socketRef.current.on('gameState', (data: GameData) => {
const events: EventType[] = [];

// if ((data.moves + 1) % 6 === 0) {
// toast.success('Zone contracting on next move!');
// }

if ((data.moves + 1) % 6 === 0) {
events.push(EventType.ZoneContraction);
}
Expand Down Expand Up @@ -227,7 +222,7 @@ export const useTimer = (
setCountdownStarted(false);
}
setTimeRemaining(remainingTime);
}, 1000);
}, 10);

return () => clearInterval(countdownInterval);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/utils/calculation-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Player } from './Player';

export const PI = 3.14159;
export const GRID_RADIUS = 3;
export const MOVE_DURATION_IN_SECONDS = 15;
export const MOVE_DURATION_IN_SECONDS = 10;
export const MOVE_ANIMATION_DURATION_IN_MS = 600;

export function generateGrid(currentRadius: number) {
Expand Down