Skip to content

Commit

Permalink
Add confirm end game dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Oct 25, 2024
1 parent 7bc250b commit 8c9b0d6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,21 @@ Join our community of developers.

## Changelog

### Thu Oct 25 22:24:59 2024
### Fri Oct 25 00:40:30 2024

- **Feature**: Added GameClock component to display the game time and time since the most recent action.
- The GameClock component shows the total game time and the time since the most recent action.
- Add confirm end game dialog

### Thu Oct 24 22:24:59 2024

- **Feature**: Added GameClock component to display the game time, current turn time, average turn time, and the average turn time for the current player
- The GameClock component shows the total game time, current turn time, average turn time, and the average turn time for the current player
- Updated the GameLogEntry component to format date and time correctly.
- Adjusted the position of the GameClock component to ensure both lines are visible.
- Added tests for the new getTimeSpanFromLastAction function.
- Adjusted the position of the GameClock component to ensure all lines are visible.
- Added tests for the new functions.
- Fixed bug in computation of game time
- Fixed bugs in NEXT_TURN properties

### Thur Oct 24 17:10:15 2024
### Thu Oct 24 17:10:15 2024

- **Improvement**: Improve about/disclaimer/readme

Expand Down
43 changes: 41 additions & 2 deletions src/components/GameScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import React, { useEffect, useState } from 'react';
import { Box, Button, Dialog, DialogContent, Fab, styled, Tooltip } from '@mui/material';
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
Fab,
styled,
Tooltip,
} from '@mui/material';
import UndoIcon from '@mui/icons-material/Undo';
import InventoryIcon from '@mui/icons-material/Inventory';
import Scoreboard from '@/components/Scoreboard';
Expand Down Expand Up @@ -45,6 +56,7 @@ const GameScreen: React.FC<GameScreenProps> = ({ nextTurn, endGame, undoLastActi
const { gameState } = useGameContext();
const [canUndo, setCanUndo] = useState(false);
const [supplyDialogOpen, setSupplyDialogOpen] = useState(false);
const [confirmEndGameDialogOpen, setConfirmEndGameDialogOpen] = useState(false);

useEffect(() => {
setCanUndo(canUndoAction(gameState, gameState.log.length - 1));
Expand All @@ -58,6 +70,19 @@ const GameScreen: React.FC<GameScreenProps> = ({ nextTurn, endGame, undoLastActi
setSupplyDialogOpen(false);
};

const handleOpenConfirmEndGameDialog = () => {
setConfirmEndGameDialogOpen(true);
};

const handleCloseConfirmEndGameDialog = () => {
setConfirmEndGameDialogOpen(false);
};

const handleConfirmEndGame = () => {
setConfirmEndGameDialogOpen(false);
endGame();
};

return (
<>
<Container>
Expand All @@ -67,7 +92,7 @@ const GameScreen: React.FC<GameScreenProps> = ({ nextTurn, endGame, undoLastActi
<Button variant="contained" color="primary" onClick={nextTurn}>
Next Turn
</Button>
<Button variant="contained" color="secondary" onClick={endGame}>
<Button variant="contained" color="secondary" onClick={handleOpenConfirmEndGameDialog}>
End Game
</Button>
</ButtonContainer>
Expand All @@ -90,6 +115,20 @@ const GameScreen: React.FC<GameScreenProps> = ({ nextTurn, endGame, undoLastActi
<SupplyCounts />
</DialogContent>
</Dialog>
<Dialog open={confirmEndGameDialogOpen} onClose={handleCloseConfirmEndGameDialog}>
<DialogTitle>Confirm End Game</DialogTitle>
<DialogContent>
<DialogContentText>Are you sure you want to end the game?</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseConfirmEndGameDialog} color="primary">
Cancel
</Button>
<Button onClick={handleConfirmEndGame} color="secondary">
Confirm
</Button>
</DialogActions>
</Dialog>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/game/dominion-lib-undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function applyLogAction(game: IGame, logEntry: ILogEntry): IGame {
// Reset all players' turn counters to their newTurn values
updatedGame.players = updatedGame.players.map((player) => ({
...player,
turn: player.newTurn,
turn: { ...player.newTurn },
}));
} else if (logEntry.action === GameLogActionWithCount.SELECT_PLAYER) {
updatedGame.selectedPlayerIndex = logEntry.playerIndex ?? updatedGame.selectedPlayerIndex;
Expand Down

0 comments on commit 8c9b0d6

Please sign in to comment.