commit
aa2fc70d96
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)")
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
//
|
||||
// MainMenuView.swift
|
||||
// DouShouQi_App
|
||||
//
|
||||
// Created by Rémi REGNAULT on 16/05/2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MainMenuView: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
TitlePageFrame(Text: "DOU SHOU QI", ImageWidth: 200, ImageHeight: 200)
|
||||
Spacer()
|
||||
|
||||
VStack {
|
||||
HStack{
|
||||
VStack(spacing: 25) {
|
||||
MainMenuButton(text: "Play", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
MainMenuButton(text: "Historique", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
MainMenuButton(text: "Best Scores", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
MainMenuButton(text: "Players", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
}
|
||||
Image(AppImages.SemiLion)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 200, height: 500)
|
||||
}
|
||||
|
||||
}
|
||||
Spacer()
|
||||
HStack {
|
||||
Text("Copyright @")
|
||||
.font(.headline)
|
||||
.frame(alignment: .trailing)
|
||||
|
||||
Text("Dou Shou Qi Team")
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("2024")
|
||||
.frame(alignment: .trailing)
|
||||
}
|
||||
.padding() // Ajout de padding pour éviter que le contenu ne touche la bordure
|
||||
.background(Color.white) // Couleur de fond pour le HStack
|
||||
.overlay(
|
||||
Rectangle()
|
||||
.stroke(Color.black, lineWidth: 1) // Couleur et épaisseur de la bordure
|
||||
)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MainMenuView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainMenuView()
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
//
|
||||
// MainMenuView.swift
|
||||
// DouShouQi_App
|
||||
//
|
||||
// Created by Rémi REGNAULT on 16/05/2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MainMenuView: View {
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
|
||||
TitlePageFrame(Text: "DOU SHOU QI", ImageWidth: 200, ImageHeight: 200)
|
||||
|
||||
Spacer()
|
||||
|
||||
VStack {
|
||||
HStack{
|
||||
VStack(spacing: 25) {
|
||||
MainMenuButton(text: "Play", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10)
|
||||
}
|
||||
Image(AppImages.SemiLion)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 200, height: 500)
|
||||
}
|
||||
|
||||
}
|
||||
Spacer()
|
||||
HStack {
|
||||
Text("Copyright @")
|
||||
.font(.headline)
|
||||
.frame(alignment: .trailing)
|
||||
|
||||
Text("Dou Shou Qi Team")
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("2024")
|
||||
.frame(alignment: .trailing)
|
||||
}
|
||||
.padding() // Ajout de padding pour éviter que le contenu ne touche la bordure
|
||||
.background(Color.white) // Couleur de fond pour le HStack
|
||||
.overlay(
|
||||
Rectangle()
|
||||
.stroke(Color.black, lineWidth: 1) // Couleur et épaisseur de la bordure
|
||||
)
|
||||
|
||||
Spacer()
|
||||
.onAppear {
|
||||
MusicPlayer.shared.playBackgroundMusic(music: "TitleScreenMusic")
|
||||
}
|
||||
.onDisappear {
|
||||
MusicPlayer.shared.stopBackgroundMusic()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MainMenuView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainMenuView()
|
||||
}
|
||||
}
|
@ -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