Compare commits
2 Commits
875e9c8795
...
6a25c18153
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a25c18153 | ||
|
|
a71c65852d |
@@ -69,22 +69,42 @@ const App = () => {
|
||||
const handleCreateGame = useCallback(({ player1, player2, player3, gameType, raceTo }) => {
|
||||
const newGame = {
|
||||
id: Date.now(),
|
||||
player1,
|
||||
player2,
|
||||
player3,
|
||||
score1: 0,
|
||||
score2: 0,
|
||||
score3: 0,
|
||||
gameType,
|
||||
raceTo,
|
||||
raceTo: parseInt(raceTo, 10),
|
||||
status: 'active',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
updatedAt: new Date().toISOString(),
|
||||
history: [],
|
||||
};
|
||||
|
||||
if (gameType === '14/1 endlos') {
|
||||
const players = [{ name: player1, score: 0, consecutiveFouls: 0 }, { name: player2, score: 0, consecutiveFouls: 0 }];
|
||||
if (player3) {
|
||||
players.push({ name: player3, score: 0, consecutiveFouls: 0 });
|
||||
}
|
||||
newGame.players = players;
|
||||
newGame.currentPlayer = null; // Set to null, will be chosen in GameDetail141
|
||||
newGame.ballsOnTable = 15;
|
||||
} else {
|
||||
newGame.player1 = player1;
|
||||
newGame.player2 = player2;
|
||||
newGame.score1 = 0;
|
||||
newGame.score2 = 0;
|
||||
if (player3) {
|
||||
newGame.player3 = player3;
|
||||
newGame.score3 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
setGames(g => [newGame, ...g]);
|
||||
return newGame.id;
|
||||
}, []);
|
||||
|
||||
// Game update for 14.1
|
||||
const handleUpdateGame = useCallback((updatedGame) => {
|
||||
setGames(games => games.map(game => (game.id === currentGameId ? updatedGame : game)));
|
||||
}, [currentGameId]);
|
||||
|
||||
// Score update
|
||||
const handleUpdateScore = useCallback((player, change) => {
|
||||
setGames(games => games.map(game => {
|
||||
@@ -168,7 +188,7 @@ const App = () => {
|
||||
setNewGameStep('gameType');
|
||||
};
|
||||
const handleGameTypeNext = (type) => {
|
||||
setNewGameData(data => ({ ...data, gameType: type }));
|
||||
setNewGameData(data => ({ ...data, gameType: type, raceTo: type === '14/1 endlos' ? '150' : '50' }));
|
||||
setNewGameStep('raceTo');
|
||||
};
|
||||
const handleRaceToNext = (raceTo) => {
|
||||
@@ -250,8 +270,9 @@ const App = () => {
|
||||
<div className="screen-content">
|
||||
<GameDetail
|
||||
game={games.find(g => g.id === currentGameId)}
|
||||
onFinishGame={handleFinishGame}
|
||||
onUpdateScore={handleUpdateScore}
|
||||
onUpdate={handleUpdateGame}
|
||||
onFinishGame={handleFinishGame}
|
||||
onBack={showGameList}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { h } from 'preact';
|
||||
import styles from './GameDetail.module.css';
|
||||
import GameDetail141 from './GameDetail141.jsx';
|
||||
|
||||
/**
|
||||
* Game detail view for a single game.
|
||||
@@ -7,11 +8,17 @@ import styles from './GameDetail.module.css';
|
||||
* @param {object} props.game
|
||||
* @param {Function} props.onFinishGame
|
||||
* @param {Function} props.onUpdateScore
|
||||
* @param {Function} props.onUpdate
|
||||
* @param {Function} props.onBack
|
||||
* @returns {import('preact').VNode|null}
|
||||
*/
|
||||
const GameDetail = ({ game, onFinishGame, onUpdateScore, onBack }) => {
|
||||
const GameDetail = ({ game, onFinishGame, onUpdateScore, onUpdate, onBack }) => {
|
||||
if (!game) return null;
|
||||
|
||||
if (game.gameType === '14/1 endlos') {
|
||||
return <GameDetail141 game={game} onUpdate={onUpdate} onBack={onBack} />;
|
||||
}
|
||||
|
||||
const isCompleted = game.status === 'completed';
|
||||
const playerNames = [game.player1, game.player2, game.player3].filter(Boolean);
|
||||
const scores = [game.score1, game.score2, game.score3].filter((_, i) => playerNames[i]);
|
||||
|
||||
@@ -122,4 +122,74 @@
|
||||
margin: 40px 0 0 0;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
.franky .player-name {
|
||||
font-weight: bold;
|
||||
color: #ff8c00; /* Example color */
|
||||
}
|
||||
.active-player {
|
||||
border: 2px solid #4caf50;
|
||||
box-shadow: 0 0 10px #4caf50;
|
||||
}
|
||||
.turn-indicator {
|
||||
margin: 20px 0;
|
||||
font-size: 1.2rem;
|
||||
text-align: center;
|
||||
}
|
||||
.potted-balls-container {
|
||||
margin-top: 2rem;
|
||||
padding: 1rem;
|
||||
background: #2a2a2a;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.potted-balls-header {
|
||||
text-align: center;
|
||||
font-size: 1.1rem;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.potted-balls-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.potted-ball-btn {
|
||||
padding: 1rem;
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #444;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s, transform 0.2s;
|
||||
}
|
||||
.potted-ball-btn:hover:not(:disabled) {
|
||||
background-color: #45a049;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
.potted-ball-btn:disabled {
|
||||
background-color: #222;
|
||||
color: #555;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.rerack-controls {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
.rerack-btn {
|
||||
padding: 0.8rem 1.5rem;
|
||||
font-size: 1rem;
|
||||
font-weight: bold;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #444;
|
||||
background-color: #3a539b;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
.rerack-btn:hover {
|
||||
background-color: #4a6fbf;
|
||||
}
|
||||
127
src/components/GameDetail141.jsx
Normal file
127
src/components/GameDetail141.jsx
Normal file
@@ -0,0 +1,127 @@
|
||||
import { h } from 'preact';
|
||||
import { useState } from 'preact/hooks';
|
||||
import styles from './GameDetail.module.css';
|
||||
import modalStyles from './PlayerSelectModal.module.css';
|
||||
|
||||
const StartingPlayerModal = ({ players, onSelect, onCancel }) => (
|
||||
<div className={modalStyles.modalOverlay}>
|
||||
<div className={modalStyles.modalContent} onClick={e => e.stopPropagation()}>
|
||||
<div className={modalStyles.modalHeader}>
|
||||
<h3>Welcher Spieler fängt an?</h3>
|
||||
{/* A cancel button isn't strictly needed if a choice is mandatory */}
|
||||
</div>
|
||||
<div className={modalStyles.playerList}>
|
||||
{players.map((player, index) => (
|
||||
<button key={player.name} className={modalStyles.playerItem} onClick={() => onSelect(index)}>
|
||||
{player.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const GameDetail141 = ({ game, onUpdate, onBack }) => {
|
||||
const handleSelectStartingPlayer = (playerIndex) => {
|
||||
onUpdate({
|
||||
...game,
|
||||
currentPlayer: playerIndex,
|
||||
});
|
||||
};
|
||||
|
||||
// If no player is selected yet, show the modal
|
||||
if (game.currentPlayer === null || game.currentPlayer === undefined) {
|
||||
return <StartingPlayerModal players={game.players} onSelect={handleSelectStartingPlayer} />;
|
||||
}
|
||||
|
||||
const currentPlayer = game.players[game.currentPlayer];
|
||||
|
||||
const handleTurnEnd = (remainingBalls, foulPoints = 0) => {
|
||||
if (remainingBalls > game.ballsOnTable) {
|
||||
console.error("Cannot leave more balls than are on the table.");
|
||||
return;
|
||||
}
|
||||
|
||||
const ballsPotted = game.ballsOnTable - remainingBalls;
|
||||
const newScore = currentPlayer.score + ballsPotted - foulPoints;
|
||||
|
||||
const updatedPlayers = game.players.map((p, index) =>
|
||||
index === game.currentPlayer ? { ...p, score: newScore } : p
|
||||
);
|
||||
|
||||
const nextPlayer = (game.currentPlayer + 1) % game.players.length;
|
||||
|
||||
onUpdate({
|
||||
...game,
|
||||
players: updatedPlayers,
|
||||
ballsOnTable: remainingBalls,
|
||||
currentPlayer: nextPlayer,
|
||||
history: [...game.history, { player: currentPlayer.name, ballsPotted, foulPoints, newScore, ballsOnTable: remainingBalls }],
|
||||
});
|
||||
};
|
||||
|
||||
const handleReRack = (ballsToAdd) => {
|
||||
const newBallsOnTable = game.ballsOnTable + ballsToAdd;
|
||||
onUpdate({
|
||||
...game,
|
||||
ballsOnTable: newBallsOnTable,
|
||||
history: [...game.history, { type: 'rerack', player: currentPlayer.name, ballsAdded: ballsToAdd, ballsOnTable: newBallsOnTable }],
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles['game-detail']}>
|
||||
<div className={styles['game-title']}>
|
||||
14/1 endlos | Race to {game.raceTo}
|
||||
</div>
|
||||
|
||||
<div className={styles['scores-container']}>
|
||||
{game.players.map((p, idx) => (
|
||||
<div
|
||||
className={`${styles['player-score']} ${idx === game.currentPlayer ? styles['active-player'] : ''}`}
|
||||
key={p.name}
|
||||
>
|
||||
<span className={styles['player-name']}>{p.name}</span>
|
||||
<span className={styles['score']}>{p.score}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className={styles['turn-indicator']}>
|
||||
Aktueller Spieler: <strong>{currentPlayer.name}</strong> ({game.ballsOnTable} Bälle auf dem Tisch)
|
||||
</div>
|
||||
|
||||
<div className={styles['potted-balls-container']}>
|
||||
<p className={styles['potted-balls-header']}>Bälle am Ende der Aufnahme:</p>
|
||||
<div className={styles['potted-balls-grid']}>
|
||||
{Array.from({ length: 16 }, (_, i) => i).map(num => (
|
||||
<button
|
||||
key={num}
|
||||
onClick={() => handleTurnEnd(num)}
|
||||
disabled={num > game.ballsOnTable}
|
||||
className={styles['potted-ball-btn']}
|
||||
>
|
||||
{num}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles['rerack-controls']}>
|
||||
<button onClick={() => handleReRack(14)} className={styles['rerack-btn']}>+14 Re-Rack</button>
|
||||
<button onClick={() => handleReRack(15)} className={styles['rerack-btn']}>+15 Re-Rack</button>
|
||||
</div>
|
||||
|
||||
{/* Placeholder for future buttons */}
|
||||
<div className={styles['foul-controls']}>
|
||||
<p>Fouls & Re-Racks (nächste Phase)</p>
|
||||
</div>
|
||||
|
||||
<div className={styles['game-detail-controls']}>
|
||||
<button className="btn" onClick={onBack}>Zurück zur Liste</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default GameDetail141;
|
||||
Reference in New Issue
Block a user