some ui changes

This commit is contained in:
neon443
2025-04-08 10:37:05 +05:30
parent fe46be8ee7
commit 137495db26
2 changed files with 62 additions and 42 deletions

View File

@@ -432,7 +432,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MineSwift/Preview Content\"";
DEVELOPMENT_TEAM = P6PV2R9443;
DEVELOPMENT_TEAM = 8626DL2GW3;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
@@ -470,7 +470,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MineSwift/Preview Content\"";
DEVELOPMENT_TEAM = P6PV2R9443;
DEVELOPMENT_TEAM = 8626DL2GW3;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;

View File

@@ -26,36 +26,63 @@ struct MinesweeperView: View {
var body: some View {
VStack {
VStack(spacing: 0) {
ForEach(0..<rows, id: \..self) { row in
HStack(spacing: 0) {
ForEach(0..<cols, id: \..self) { col in
Button(action: {
if flag {
ZStack {
VStack(spacing: 0) {
ForEach(0..<rows, id: \..self) { row in
HStack(spacing: 0) {
ForEach(0..<cols, id: \..self) { col in
Button(action: {
if flag {
game.flagCell(row: row, col: col)
} else {
game.revealCell(row: row, col: col)
}
}) {
CellView(cell: game.board[row][col], isHighlighted: isNeighborHovered(row: row, col: col))
.frame(width: 30, height: 30)
.border(Color.gray.opacity(0.2))
.animation(.easeInOut(duration: 0.3), value: isNeighborHovered(row: row, col: col))
}
.buttonStyle(PlainButtonStyle())
.onHover { isHovering in
withAnimation {
hoveredCell = isHovering ? (row, col) : nil
}
}
.onTapGesture(count: 2) {
game.flagCell(row: row, col: col)
} else {
game.revealCell(row: row, col: col)
}
}) {
CellView(cell: game.board[row][col], isHighlighted: isNeighborHovered(row: row, col: col))
.frame(width: 30, height: 30)
.border(Color.gray.opacity(0.2))
.animation(.easeInOut(duration: 0.3), value: isNeighborHovered(row: row, col: col))
}
.buttonStyle(PlainButtonStyle())
.onHover { isHovering in
withAnimation {
hoveredCell = isHovering ? (row, col) : nil
}
}
.onTapGesture(count: 2) {
game.flagCell(row: row, col: col)
}
}
}
}
.clipShape(RoundedRectangle(cornerRadius: 10))
if game.gameOver {
Text("Game Over")
.font(.largeTitle)
.bold()
.foregroundColor(.red)
.shadow(radius: 10)
.shadow(radius: 10)
.shadow(radius: 10)
} else if game.gameWon {
Text("You Win!")
.font(.largeTitle)
.bold()
.foregroundColor(.green)
.shadow(radius: 10)
.shadow(radius: 10)
.shadow(radius: 10)
}
if game.gameOver || game.gameWon {
Button() {
} label: {
Text("Restart game")
}
}
}
.clipShape(RoundedRectangle(cornerRadius: 10))
List {
Toggle(isOn: $flag, label: {
@@ -67,16 +94,6 @@ struct MinesweeperView: View {
.padding()
.frame(alignment: .center)
}
if game.gameOver {
Text("Game Over")
.font(.largeTitle)
.foregroundColor(.red)
} else if game.gameWon {
Text("You Win!")
.font(.largeTitle)
.foregroundColor(.green)
}
}
.padding()
}
@@ -94,15 +111,18 @@ struct CellView: View {
var body: some View {
ZStack {
if isHighlighted {
Color.gray.opacity(0.1)
.animation(.easeInOut(duration: 0.3), value: isHighlighted)
} else if cell.state == .revealed {
Color.black
if cell.state == .revealed {
Color.black.opacity(isHighlighted ? 0.5 : 1)
} else {
Color.blue
Color.blue.opacity(isHighlighted ? 0.8 : 1)
// .animation(.spring(duration: 0.1), value: isHighlighted)
}
// if isHighlighted {
// Color.gray.opacity(0.05)
// .animation(.spring(duration: 0.1), value: isHighlighted)
// }
if cell.state == .revealed {
if cell.isMine {
Image(systemName: "multiply")
@@ -130,5 +150,5 @@ struct CellView: View {
}
#Preview {
MinesweeperView(rows: 10, cols: 10, bombs: 5)
MinesweeperView(rows: 10, cols: 10, bombs: 10)
}