Skip to content

Commit

Permalink
fix: don't display restart button after game ends
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobTheEldest committed May 27, 2023
1 parent 4ce5df6 commit ccab894
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ const App: React.FC = () => {
const [currentMines, setCurrentMines] = useState(10);

const handleColumnsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setCols(parseInt(e.target.value));
const newCols = parseInt(e.target.value);
setCols(newCols);
setMines(Math.round((newCols * rows) / 10));
};

const handleRowsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setRows(parseInt(e.target.value));
const newRows = parseInt(e.target.value);
setRows(newRows);
setMines(Math.round((newRows * cols) / 10));
};

const handleMinesChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setMines(parseInt(e.target.value));
const newMines = parseInt(e.target.value);
setMines(newMines);
};

const handleNewGameClick = (e: React.FormEvent) => {
Expand Down Expand Up @@ -126,9 +131,6 @@ const App: React.FC = () => {
<button type="submit">New Game</button>
</form>
<span className="game-result">{endMessage}</span>
{gameResult !== '' ? (
<button onClick={handleNewGameClick}>Restart</button>
) : null}
</div>
<Board />
<br />
Expand Down

0 comments on commit ccab894

Please sign in to comment.