You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SwiftUiTp/DouShouQiIOS/DouShouQiIOS/View/HistoryView.swift

115 lines
3.7 KiB

//
// HistoryView.swift
// DouShouQiIOS
//
// Created by Pierre FERREIRA on 21/05/2024.
//
import SwiftUI
struct HistoryView: View {
var playerName: String
var matches: [Match] // Modèle des parties du joueur
var body: some View {
VStack{
Text("Historique du joueur").font(.largeTitle)
HStack{
Spacer()
HStack{
Text("Ratio")
.frame(height: 50, alignment: .center)
.padding([.leading, .trailing], 20)
.background(Color.yellow)
.foregroundColor(Color.white)
.bold()
.cornerRadius(15)
Text("0,3")
.foregroundColor(.yellow)
.padding([.leading], 10)
.padding([.trailing], 20)
}.overlay(
RoundedRectangle(cornerRadius: 15)
.stroke(.yellow, lineWidth: 3)
)
Spacer()
HStack{
Text("Total")
.frame(height: 50, alignment: .center)
.padding([.leading, .trailing], 20)
.background(Color.yellow)
.foregroundColor(Color.white)
.bold()
.cornerRadius(15)
Text("\(matches.count)")
.foregroundColor(.yellow)
.padding([.leading], 10)
.padding([.trailing], 20)
}.overlay(
RoundedRectangle(cornerRadius: 15)
.stroke(.yellow, lineWidth: 3)
)
Spacer()
}
List(matches) { match in
HStack {
Image(match.gameEndScreen)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50, height: 50)
.cornerRadius(8)
VStack(alignment: .leading) {
Text(match.opponent)
.font(.headline)
Text("Score: \(match.score)")
.font(.subheadline)
}
.padding(.leading, 10)
Spacer()
Text(match.result)
.foregroundColor(match.result == "Victoire" ? .green : .red)
.padding(.trailing, 10)
}.listRowBackground(Color.yellow.opacity(0.1))
.padding()
.background(match.result == "Victoire" ? Color.green.opacity(0.3) : Color.red.opacity(0.3))
.cornerRadius(10)
}
.padding()
.navigationTitle("Historique de \(playerName)")
}.background(Color.gray.opacity(0.1))
}
}
struct Match: Identifiable {
var id = UUID()
var gameEndScreen: String
var opponent: String
var score: String
var result: String
}
struct HistoryView_Previews: PreviewProvider {
static var previews: some View {
let sampleMatches = [
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 1", score: "3-0", result: "Victoire"),
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 2", score: "0-3", result: "Défaite"),
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 3", score: "2-2", result: "Nul")
]
HistoryView(playerName: "bro", matches: sampleMatches)
}
}