parent
9147f0ae39
commit
537f8527e6
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// PlayerRow.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by étudiant on 26/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct PlayerRow: View {
|
||||||
|
var player: Player
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text(player.name)
|
||||||
|
.font(.headline)
|
||||||
|
Text("Victoires : \(player.wins) Défaites : \(player.losses)")
|
||||||
|
.font(.subheadline)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Button(action: {
|
||||||
|
// Action pour éditer le joueur
|
||||||
|
}) {
|
||||||
|
Image(systemName: "pencil")
|
||||||
|
.foregroundColor(.red)
|
||||||
|
}
|
||||||
|
Button(action: {
|
||||||
|
// Action pour supprimer le joueur
|
||||||
|
}) {
|
||||||
|
Image(systemName: "trash")
|
||||||
|
.foregroundColor(.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.background(Color.white)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.shadow(radius: 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
//
|
|
||||||
// MusicPlayer.swift
|
|
||||||
// DouShouQi_App
|
|
||||||
//
|
|
||||||
// Created by étudiant on 26/05/2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// MusicPlayer.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by étudiant on 26/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import AVFoundation
|
||||||
|
|
||||||
|
class MusicPlayer {
|
||||||
|
static let shared = MusicPlayer()
|
||||||
|
var audioPlayer: AVAudioPlayer?
|
||||||
|
|
||||||
|
func playBackgroundMusic(music: String) {
|
||||||
|
if let bundle = Bundle.main.path(forResource: music, ofType: "mp3") {
|
||||||
|
let backgroundMusic = NSURL(fileURLWithPath: bundle)
|
||||||
|
do {
|
||||||
|
audioPlayer = try AVAudioPlayer(contentsOf: backgroundMusic as URL)
|
||||||
|
guard let audioPlayer = audioPlayer else { return }
|
||||||
|
audioPlayer.numberOfLoops = -1 // Loop indefinitely
|
||||||
|
audioPlayer.prepareToPlay()
|
||||||
|
audioPlayer.play()
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopBackgroundMusic() {
|
||||||
|
audioPlayer?.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// SoundPlayer.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by étudiant on 27/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import AVFoundation
|
||||||
|
|
||||||
|
var audioPlayer: AVAudioPlayer?
|
||||||
|
|
||||||
|
func playSound(named soundName: String) {
|
||||||
|
guard let url = Bundle.main.url(forResource: soundName, withExtension: "mp3") else { return }
|
||||||
|
|
||||||
|
do {
|
||||||
|
audioPlayer = try AVAudioPlayer(contentsOf: url)
|
||||||
|
audioPlayer?.play()
|
||||||
|
} catch let error {
|
||||||
|
print("Error playing sound. \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
//
|
||||||
|
// PlayersView.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by étudiant on 26/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// Modèle de données pour un joueur
|
||||||
|
struct Player: Identifiable {
|
||||||
|
var id = UUID()
|
||||||
|
var name: String
|
||||||
|
var wins: Int
|
||||||
|
var losses: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exemple de vue pour l'interface utilisateur des joueurs
|
||||||
|
struct PlayersView: View {
|
||||||
|
// Liste de joueurs pour l'exemple
|
||||||
|
@State private var players = [
|
||||||
|
Player(name: "Rayhan", wins: 7, losses: 6),
|
||||||
|
Player(name: "Remi", wins: 7, losses: 2),
|
||||||
|
Player(name: "Nathan", wins: 14, losses: 5)
|
||||||
|
]
|
||||||
|
|
||||||
|
@State private var searchText = ""
|
||||||
|
|
||||||
|
var filteredPlayers: [Player] {
|
||||||
|
if searchText.isEmpty {
|
||||||
|
return players
|
||||||
|
} else {
|
||||||
|
return players.filter { $0.name.lowercased().contains(searchText.lowercased()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationView {
|
||||||
|
VStack {
|
||||||
|
// Image en haut
|
||||||
|
TitlePageFrame(Text: "PLAYERS", ImageWidth: 200, ImageHeight: 200)
|
||||||
|
|
||||||
|
// Barre de recherche
|
||||||
|
SearchBar(text: $searchText)
|
||||||
|
.padding(.horizontal)
|
||||||
|
|
||||||
|
// Liste de joueurs
|
||||||
|
List {
|
||||||
|
ForEach(groupedPlayers.keys.sorted(), id: \.self) { key in
|
||||||
|
Section(header: Text(key)) {
|
||||||
|
ForEach(groupedPlayers[key]!) { player in
|
||||||
|
PlayerRow(player: player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
|
||||||
|
}) {
|
||||||
|
Text("Add a player")
|
||||||
|
.font(.headline)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.padding()
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(Color.red)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
|
.padding(.bottom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupedPlayers: [String: [Player]] {
|
||||||
|
Dictionary(grouping: filteredPlayers) { player in
|
||||||
|
String(player.name.prefix(1)).uppercased()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Vue pour la barre de recherche
|
||||||
|
struct SearchBar: UIViewRepresentable {
|
||||||
|
@Binding var text: String
|
||||||
|
|
||||||
|
class Coordinator: NSObject, UISearchBarDelegate {
|
||||||
|
@Binding var text: String
|
||||||
|
|
||||||
|
init(text: Binding<String>) {
|
||||||
|
_text = text
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
||||||
|
text = searchText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCoordinator() -> Coordinator {
|
||||||
|
return Coordinator(text: $text)
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeUIView(context: Context) -> UISearchBar {
|
||||||
|
let searchBar = UISearchBar(frame: .zero)
|
||||||
|
searchBar.delegate = context.coordinator
|
||||||
|
return searchBar
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIView(_ uiView: UISearchBar, context: Context) {
|
||||||
|
uiView.text = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PlayersPageView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
PlayersView()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue