Skip to content

Commit 882e27e

Browse files
authored
Merge pull request #4 from behitek/feature/game-rework
Feature/game rework
2 parents c8f2166 + ebcc36c commit 882e27e

2 files changed

Lines changed: 99 additions & 25 deletions

File tree

src/pages/minesweeper/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,41 @@ const MinesweeperGame = () => {
8787

8888
if (!timerActive) {
8989
setTimerActive(true);
90+
// Ensure first click is safe
91+
if (board[row][col].isMine) {
92+
const newBoard = [...board];
93+
// Remove mine from current cell
94+
newBoard[row][col].isMine = false;
95+
96+
// Find a new spot for the mine
97+
let placed = false;
98+
while (!placed) {
99+
const newRow = Math.floor(Math.random() * board.length);
100+
const newCol = Math.floor(Math.random() * board[0].length);
101+
if (!newBoard[newRow][newCol].isMine && (newRow !== row || newCol !== col)) {
102+
newBoard[newRow][newCol].isMine = true;
103+
placed = true;
104+
}
105+
}
106+
107+
// Recalculate neighbor counts
108+
for (let r = 0; r < board.length; r++) {
109+
for (let c = 0; c < board[0].length; c++) {
110+
if (!newBoard[r][c].isMine) {
111+
let count = 0;
112+
for (let i = -1; i <= 1; i++) {
113+
for (let j = -1; j <= 1; j++) {
114+
if (r + i >= 0 && r + i < board.length && c + j >= 0 && c + j < board[0].length) {
115+
if (newBoard[r + i][c + j].isMine) count++;
116+
}
117+
}
118+
}
119+
newBoard[r][c].neighborMines = count;
120+
}
121+
}
122+
}
123+
setBoard(newBoard);
124+
}
90125
}
91126

92127
const newBoard = [...board];

src/pages/minesweeper/styles.module.css

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@
1414
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
1515
padding: 2rem;
1616
margin-top: 2rem;
17+
position: relative;
18+
}
19+
20+
.controls {
21+
display: flex;
22+
gap: 1rem;
23+
margin-bottom: 2rem;
24+
justify-content: center;
25+
position: sticky;
26+
left: 0;
27+
right: 0;
28+
z-index: 1;
29+
}
30+
31+
.gameStatus {
32+
display: flex;
33+
justify-content: space-between;
34+
align-items: center;
35+
background: rgba(52, 73, 94, 0.8);
36+
backdrop-filter: blur(10px);
37+
padding: 0.5rem 1rem;
38+
border-radius: 12px;
39+
color: #fff;
40+
margin-bottom: 1rem;
41+
font-family: 'Courier New', monospace;
42+
font-size: 0.9rem;
43+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
44+
border: 1px solid rgba(255, 255, 255, 0.1);
45+
position: sticky;
46+
left: 0;
47+
right: 0;
48+
z-index: 1;
1749
}
1850

1951
.header {
@@ -46,6 +78,17 @@
4678
color: #2c3e50;
4779
}
4880

81+
@media (max-width: 480px) {
82+
.button {
83+
padding: 0.4rem 0.6rem;
84+
font-size: 0.9rem;
85+
}
86+
87+
.controls {
88+
gap: 0.5rem;
89+
}
90+
}
91+
4992
.button:hover {
5093
transform: translateY(-2px);
5194
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
@@ -120,8 +163,23 @@
120163
margin: 0 auto;
121164
grid-template-columns: repeat(auto-fill, 30px);
122165
overflow-x: auto;
123-
max-width: 100%;
166+
max-width: none;
124167
-webkit-overflow-scrolling: touch;
168+
scrollbar-width: thin;
169+
scrollbar-color: rgba(52, 73, 94, 0.8) transparent;
170+
}
171+
172+
.grid::-webkit-scrollbar {
173+
height: 8px;
174+
}
175+
176+
.grid::-webkit-scrollbar-track {
177+
background: transparent;
178+
}
179+
180+
.grid::-webkit-scrollbar-thumb {
181+
background-color: rgba(52, 73, 94, 0.8);
182+
border-radius: 4px;
125183
}
126184

127185
.cell {
@@ -189,32 +247,13 @@
189247

190248
.gameContainer {
191249
padding: 1rem;
192-
}
193-
194-
.cell {
195-
width: 25px;
196-
height: 25px;
197-
font-size: 0.9rem;
198-
}
199-
200-
.title {
201-
font-size: 2rem;
202-
}
203-
204-
.mobileWarning {
205-
background: rgba(255, 193, 7, 0.2);
206-
color: #856404;
207-
padding: 0.75rem;
208-
border-radius: 6px;
209-
margin-bottom: 1rem;
210-
text-align: center;
211-
font-size: 0.9rem;
212-
border: 1px solid rgba(255, 193, 7, 0.3);
250+
width: 100%;
251+
overflow-x: auto;
213252
}
214253

215254
.grid {
216-
padding: 0.5px 0.5px 0.5px;
217-
margin: 0 -1rem;
218-
border-radius: 0;
255+
margin: 0 auto;
256+
padding: 1px;
257+
border-radius: 4px;
219258
}
220259
}

0 commit comments

Comments
 (0)