From ad534e63dc21ba7f6050390c30f5d1f45633f99a Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Sat, 14 Sep 2024 21:07:35 +0200 Subject: [PATCH] added quickstart and footer --- src/App.tsx | 14 +++++++++++++- src/Button.tsx | 2 +- src/Game.ts | 13 +++++++++++++ src/index.css | 13 +++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 055308d..dc97e3b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { Button } from "./Button"; -import { useGame } from "./GameContext"; +import { updateGame, useGame } from "./GameContext"; import Timer from "./Timer"; import Options from "./Options"; @@ -10,6 +10,9 @@ function App() {

Minesweeper

+
@@ -28,6 +31,15 @@ function App() {
+
+
Version: 1.0.1
+
+          Made by MasterGordon -{" "}
+          
+            Source Code
+          
+        
+
); } diff --git a/src/Button.tsx b/src/Button.tsx index 6d43a95..6dd8ffe 100644 --- a/src/Button.tsx +++ b/src/Button.tsx @@ -53,7 +53,7 @@ export const Button = ({ x, y }: ButtonProps) => { } if (e.button === 0) { // Left click - if (!game?.isRevealed[x][y]) { + if (!game?.isRevealed[x][y] && !game?.isFlagged[x][y]) { updateGame((game) => game?.reveal(x, y)); } else { const neighborFlagCount = game diff --git a/src/Game.ts b/src/Game.ts index a5ccfb4..32043d1 100644 --- a/src/Game.ts +++ b/src/Game.ts @@ -128,4 +128,17 @@ export class Game { const mines = neighbors.filter((n) => n).length; return mines; } + + quickStart() { + for (let i = 0; i < this.getWidth(); i++) { + for (let j = 0; j < this.getHeight(); j++) { + const value = this.getValue(i, j); + const isMine = this.isMine(i, j); + if (value === 0 && !isMine) { + this.reveal(i, j); + return; + } + } + } + } } diff --git a/src/index.css b/src/index.css index f29c0c2..3b2dd8b 100644 --- a/src/index.css +++ b/src/index.css @@ -44,3 +44,16 @@ body { font-size: 2rem; font-family: monospace; } + +.footer { + display: flex; + flex-direction: column; + /* justify-content: space-between; */ + align-items: center; + font-size: 1rem; + font-family: monospace; +} + +pre { + margin: 0; +}