parent
95efe097dd
commit
272612da24
@ -0,0 +1,105 @@
|
|||||||
|
//
|
||||||
|
// GameView.swift
|
||||||
|
// DouShouQiIOS
|
||||||
|
//
|
||||||
|
// Created by Pierre FERREIRA on 22/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GameView: View {
|
||||||
|
@State private var turnNumber = 1
|
||||||
|
@State private var gameTime = 0.0 // Temps en secondes
|
||||||
|
@State private var statusMessage = "C'est votre tour"
|
||||||
|
@State private var player1Pieces = 8
|
||||||
|
@State private var player2Pieces = 8
|
||||||
|
|
||||||
|
var timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
||||||
|
|
||||||
|
let gridItems = Array(repeating: GridItem(.flexible()), count: 8)
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
VStack {
|
||||||
|
Text(statusMessage)
|
||||||
|
.font(.title)
|
||||||
|
.padding(.top, 20)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Text("Tour: \(turnNumber)")
|
||||||
|
.font(.headline)
|
||||||
|
.frame(height: 50, alignment: .center)
|
||||||
|
.padding([.leading, .trailing], 20)
|
||||||
|
.background(Color.yellow)
|
||||||
|
.foregroundColor(Color.white)
|
||||||
|
.bold()
|
||||||
|
.cornerRadius(15)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text("Temps: \(Int(gameTime))s")
|
||||||
|
.font(.headline)
|
||||||
|
.frame(height: 50, alignment: .center)
|
||||||
|
.padding([.leading, .trailing], 20)
|
||||||
|
.background(Color.yellow)
|
||||||
|
.foregroundColor(Color.white)
|
||||||
|
.bold()
|
||||||
|
.cornerRadius(15) .onReceive(timer) { _ in
|
||||||
|
gameTime += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding([.leading, .trailing], 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyVGrid(columns: gridItems, spacing: 5) {
|
||||||
|
ForEach(0..<64) { index in
|
||||||
|
Rectangle()
|
||||||
|
.foregroundColor((index / 8 + index % 8) % 2 == 0 ? .orange : .gray.opacity(0.2))
|
||||||
|
.frame(height: 35)
|
||||||
|
.cornerRadius(10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(10)
|
||||||
|
.background(Color.yellow)
|
||||||
|
.cornerRadius(15)
|
||||||
|
.padding(20)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
VStack {
|
||||||
|
Text("Pièces Joueur 1")
|
||||||
|
.font(.headline)
|
||||||
|
.padding(.bottom, 5)
|
||||||
|
|
||||||
|
Text("\(player1Pieces)")
|
||||||
|
.font(.largeTitle)
|
||||||
|
.padding()
|
||||||
|
.background(Color.yellow.opacity(0.2))
|
||||||
|
.cornerRadius(10)
|
||||||
|
}
|
||||||
|
.padding(20)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
VStack {
|
||||||
|
Text("Pièces Joueur 2")
|
||||||
|
.font(.headline)
|
||||||
|
.padding(.bottom, 5)
|
||||||
|
|
||||||
|
Text("\(player2Pieces)")
|
||||||
|
.font(.largeTitle)
|
||||||
|
.padding()
|
||||||
|
.background(Color.red.opacity(0.2))
|
||||||
|
.cornerRadius(10)
|
||||||
|
}
|
||||||
|
.padding(20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationBarTitle("DouShouQi", displayMode: .inline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GameView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
GameView()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue