mirror of
https://github.com/neon443/MineSwift.git
synced 2026-03-11 07:09:12 +00:00
some ui changes
This commit is contained in:
@@ -432,7 +432,7 @@
|
|||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"MineSwift/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"MineSwift/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = P6PV2R9443;
|
DEVELOPMENT_TEAM = 8626DL2GW3;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
@@ -470,7 +470,7 @@
|
|||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"MineSwift/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"MineSwift/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = P6PV2R9443;
|
DEVELOPMENT_TEAM = 8626DL2GW3;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
|
|||||||
@@ -26,36 +26,63 @@ struct MinesweeperView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
VStack(spacing: 0) {
|
ZStack {
|
||||||
ForEach(0..<rows, id: \..self) { row in
|
VStack(spacing: 0) {
|
||||||
HStack(spacing: 0) {
|
ForEach(0..<rows, id: \..self) { row in
|
||||||
ForEach(0..<cols, id: \..self) { col in
|
HStack(spacing: 0) {
|
||||||
Button(action: {
|
ForEach(0..<cols, id: \..self) { col in
|
||||||
if flag {
|
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)
|
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 {
|
List {
|
||||||
Toggle(isOn: $flag, label: {
|
Toggle(isOn: $flag, label: {
|
||||||
@@ -67,16 +94,6 @@ struct MinesweeperView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
.frame(alignment: .center)
|
.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()
|
.padding()
|
||||||
}
|
}
|
||||||
@@ -94,14 +111,17 @@ struct CellView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
if isHighlighted {
|
if cell.state == .revealed {
|
||||||
Color.gray.opacity(0.1)
|
Color.black.opacity(isHighlighted ? 0.5 : 1)
|
||||||
.animation(.easeInOut(duration: 0.3), value: isHighlighted)
|
|
||||||
} else if cell.state == .revealed {
|
|
||||||
Color.black
|
|
||||||
} else {
|
} 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.state == .revealed {
|
||||||
if cell.isMine {
|
if cell.isMine {
|
||||||
@@ -130,5 +150,5 @@ struct CellView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
MinesweeperView(rows: 10, cols: 10, bombs: 5)
|
MinesweeperView(rows: 10, cols: 10, bombs: 10)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user