fixed auto reveal

This commit is contained in:
MasterGordon 2024-09-15 19:45:10 +02:00
parent fcbfad55a4
commit ee1fb098af
2 changed files with 19 additions and 10 deletions

View File

@ -62,7 +62,7 @@ function App() {
</button>
{showScores && (
<div>
{scores.map((score) => (
{scores.slice(0, 10).map((score) => (
<p key={score.user}>
{score.user} - {score.stage}
</p>
@ -88,7 +88,7 @@ function App() {
</div>
</div>
<div className="footer">
<pre>Version: 1.1.2</pre>
<pre>Version: 1.1.3</pre>
<pre>
Made by MasterGordon -{" "}
<a target="_blank" href="https://github.com/MasterGordon/minesweeper">

View File

@ -67,14 +67,23 @@ export const Button = ({ x, y }: ButtonProps) => {
.filter((n) => n).length;
const value = game.getValue(x, y);
if (neighborFlagCount === value) {
if (!game.isFlagged[x - 1]?.[y]) game.reveal(x - 1, y);
if (!game.isFlagged[x - 1]?.[y - 1]) game.reveal(x - 1, y - 1);
if (!game.isFlagged[x - 1]?.[y + 1]) game.reveal(x - 1, y + 1);
if (!game.isFlagged[x]?.[y - 1]) game.reveal(x, y - 1);
if (!game.isFlagged[x]?.[y + 1]) game.reveal(x, y + 1);
if (!game.isFlagged[x + 1]?.[y - 1]) game.reveal(x + 1, y - 1);
if (!game.isFlagged[x + 1]?.[y]) game.reveal(x + 1, y);
if (!game.isFlagged[x + 1]?.[y + 1]) game.reveal(x + 1, y + 1);
const currentStage = game.stage;
if (!game.isFlagged[x - 1]?.[y] && currentStage == game.stage)
game.reveal(x - 1, y);
if (!game.isFlagged[x - 1]?.[y - 1] && currentStage == game.stage)
game.reveal(x - 1, y - 1);
if (!game.isFlagged[x - 1]?.[y + 1] && currentStage == game.stage)
game.reveal(x - 1, y + 1);
if (!game.isFlagged[x]?.[y - 1] && currentStage == game.stage)
game.reveal(x, y - 1);
if (!game.isFlagged[x]?.[y + 1] && currentStage == game.stage)
game.reveal(x, y + 1);
if (!game.isFlagged[x + 1]?.[y - 1] && currentStage == game.stage)
game.reveal(x + 1, y - 1);
if (!game.isFlagged[x + 1]?.[y] && currentStage == game.stage)
game.reveal(x + 1, y);
if (!game.isFlagged[x + 1]?.[y + 1] && currentStage == game.stage)
game.reveal(x + 1, y + 1);
}
}
} else if (e.button === 2 && !game.isRevealed[x][y]) {