Skip to content
Snippets Groups Projects
Commit a5f499d5 authored by Louis Canova's avatar Louis Canova
Browse files

initial commit

parent d2814713
No related branches found
No related tags found
No related merge requests found
Showing
with 1059 additions and 13 deletions
Podfile 0 → 100644
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'projet' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for projet
pod 'Alamofire', '~> 5.4'
target 'projetTests' do
inherit! :search_paths
# Pods for testing
end
target 'projetUITests' do
# Pods for testing
end
end
......@@ -14,6 +14,11 @@
9E5E54E82BF7898A0036CA97 /* projetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E5E54E72BF7898A0036CA97 /* projetTests.swift */; };
9E5E54F22BF7898A0036CA97 /* projetUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E5E54F12BF7898A0036CA97 /* projetUITests.swift */; };
9E5E54F42BF7898A0036CA97 /* projetUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E5E54F32BF7898A0036CA97 /* projetUITestsLaunchTests.swift */; };
9E5E55042BF7A1930036CA97 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 9E5E55032BF7A1930036CA97 /* Alamofire */; };
C7C39FEB2C00779700169C6E /* QuizView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7C39FEA2C00779700169C6E /* QuizView.swift */; };
C7C39FED2C0077C100169C6E /* QuizModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7C39FEC2C0077C100169C6E /* QuizModel.swift */; };
C7C39FEF2C0077F000169C6E /* QuizViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7C39FEE2C0077F000169C6E /* QuizViewModel.swift */; };
C7C39FF12C00D53100169C6E /* Film.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7C39FF02C00D53100169C6E /* Film.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -44,6 +49,10 @@
9E5E54ED2BF7898A0036CA97 /* projetUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = projetUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9E5E54F12BF7898A0036CA97 /* projetUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = projetUITests.swift; sourceTree = "<group>"; };
9E5E54F32BF7898A0036CA97 /* projetUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = projetUITestsLaunchTests.swift; sourceTree = "<group>"; };
C7C39FEA2C00779700169C6E /* QuizView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizView.swift; sourceTree = "<group>"; };
C7C39FEC2C0077C100169C6E /* QuizModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizModel.swift; sourceTree = "<group>"; };
C7C39FEE2C0077F000169C6E /* QuizViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizViewModel.swift; sourceTree = "<group>"; };
C7C39FF02C00D53100169C6E /* Film.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Film.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -51,6 +60,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9E5E55042BF7A1930036CA97 /* Alamofire in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -96,6 +106,10 @@
children = (
9E5E54D62BF789890036CA97 /* projetApp.swift */,
9E5E54D82BF789890036CA97 /* ContentView.swift */,
C7C39FEA2C00779700169C6E /* QuizView.swift */,
C7C39FEC2C0077C100169C6E /* QuizModel.swift */,
C7C39FF02C00D53100169C6E /* Film.swift */,
C7C39FEE2C0077F000169C6E /* QuizViewModel.swift */,
9E5E54DA2BF7898A0036CA97 /* Assets.xcassets */,
9E5E54DC2BF7898A0036CA97 /* Preview Content */,
);
......@@ -143,6 +157,9 @@
dependencies = (
);
name = projet;
packageProductDependencies = (
9E5E55032BF7A1930036CA97 /* Alamofire */,
);
productName = projet;
productReference = 9E5E54D32BF789890036CA97 /* projet.app */;
productType = "com.apple.product-type.application";
......@@ -215,6 +232,9 @@
Base,
);
mainGroup = 9E5E54CA2BF789890036CA97;
packageReferences = (
9E5E55022BF7A1930036CA97 /* XCRemoteSwiftPackageReference "Alamofire" */,
);
productRefGroup = 9E5E54D42BF789890036CA97 /* Products */;
projectDirPath = "";
projectRoot = "";
......@@ -257,8 +277,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C7C39FED2C0077C100169C6E /* QuizModel.swift in Sources */,
C7C39FF12C00D53100169C6E /* Film.swift in Sources */,
9E5E54D92BF789890036CA97 /* ContentView.swift in Sources */,
9E5E54D72BF789890036CA97 /* projetApp.swift in Sources */,
C7C39FEF2C0077F000169C6E /* QuizViewModel.swift in Sources */,
C7C39FEB2C00779700169C6E /* QuizView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -577,6 +601,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
9E5E55022BF7A1930036CA97 /* XCRemoteSwiftPackageReference "Alamofire" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Alamofire/Alamofire.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
9E5E55032BF7A1930036CA97 /* Alamofire */ = {
isa = XCSwiftPackageProductDependency;
package = 9E5E55022BF7A1930036CA97 /* XCRemoteSwiftPackageReference "Alamofire" */;
productName = Alamofire;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 9E5E54CB2BF789890036CA97 /* Project object */;
}
{
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
}
}
],
"version" : 2
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>projet.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
{
"images" : [
{
"filename" : "OIG3.wRIRGmxerTymeh.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
projet/Assets.xcassets/background1.imageset/OIG3.wRIRGmxerTymeh.jpg

157 KiB

{
"images" : [
{
"filename" : "lettrage-cinema-vue-dessus-fond-jaune_23-2148425105.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "360_F_54055975_XWuJeVgL7wiaGDD6DF0osiJSQmwJ1dJP.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "wallpaper-iphone-haut-couleur-flou-eau-abstract-5.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "27124106-minimaliste-naturel-fond-d-ecran-pour-mobile-telephone-gratuit-photo.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
//
// ContentView.swift
// projet
//
// Created by Emile Haas on 5/17/24.
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
NavigationView {
VStack {
Section() {
Text("CultX")
.font(.system(size: 40, weight: .bold))
.foregroundColor(.white)
.padding()
}
ButtonWithBackgroundImage(destination: QuizView(), imageName: "background1")
ButtonWithBackgroundImage(destination: ThirdView(), imageName: "background2")
ButtonWithBackgroundImage2(destination: Text("Work in progress"), imageName: "background3")
Spacer()
}
.background(Color.red.opacity(0.8))
}
.padding()
}
}
struct ButtonWithBackgroundImage<Destination: View>: View {
var destination: Destination
var imageName: String
var body: some View {
NavigationLink(destination: destination) {
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 200)
.clipped()
.cornerRadius(10)
.padding()
.shadow(radius: 10)
}
.buttonStyle(PlainButtonStyle())
}
}
struct ButtonWithBackgroundImage2<Destination: View>: View {
var destination: Destination
var imageName: String
var body: some View {
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 200)
.clipped()
.cornerRadius(10)
.padding()
.shadow(radius: 10)
.buttonStyle(PlainButtonStyle())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
......
This diff is collapsed.
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
import Foundation
struct Quiz: Codable {
let id: String
let question: String
let answer: String
let badAnswers: [String]
let category: String
let difficulty: String
enum CodingKeys: String, CodingKey {
case id = "_id"
case question, answer, badAnswers, category, difficulty
}
}
struct QuizResponse: Codable {
let count: Int
let quizzes: [Quiz]
}
import SwiftUI
struct QuizView: View {
@StateObject private var viewModel = QuizViewModel()
@State private var hasObtainedQuiz = false // État pour contrôler la visibilité du bouton "Obtenir un quiz"
var body: some View {
ZStack {
// Image de fond
Image("backgroundQuizz")
.resizable()
.scaledToFill()
.edgesIgnoringSafeArea(.all)
VStack {
Picker("Difficulté", selection: $viewModel.selectedDifficulty) {
Text("Facile").tag("facile")
Text("Normal").tag("normal")
Text("Difficile").tag("difficile")
}
.pickerStyle(SegmentedPickerStyle())
.padding()
.background(Color.blue.opacity(0.1))
.cornerRadius(10)
.padding(.horizontal)
Picker("Catégorie", selection: $viewModel.selectedCategory) {
Text("TV & Cinéma").tag("tv_cinema")
Text("Art & Littérature").tag("art_litterature")
Text("Musique").tag("musique")
Text("Actu & Politique").tag("actu_politique")
Text("Culture Générale").tag("culture_generale")
Text("Sport").tag("sport")
Text("Jeux Vidéos").tag("jeux_videos")
}
.pickerStyle(MenuPickerStyle())
.padding()
.background(Color.blue.opacity(0.1))
.cornerRadius(10)
.padding(.horizontal)
if !hasObtainedQuiz { // Afficher le bouton "Obtenir un quiz" seulement au début
Button(action: {
viewModel.fetchQuizzes()
hasObtainedQuiz = true
}) {
Text("Obtenir un quizz")
.fontWeight(.bold)
.padding()
.frame(maxWidth: .infinity)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
.padding(.horizontal)
.padding(.top)
}
if let quiz = viewModel.quizzes.first {
VStack {
Text(quiz.question)
.font(.headline)
.padding()
.multilineTextAlignment(.center)
.background(Color.blue.opacity(0.1))
.cornerRadius(10)
.padding(.horizontal)
ForEach(viewModel.currentAnswers, id: \.self) { answer in
Button(action: {
viewModel.checkAnswer(answer, for: quiz)
}) {
Text(answer)
.padding()
.frame(maxWidth: .infinity)
.background(self.backgroundColor(for: answer, quiz: quiz))
.foregroundColor(.white)
.cornerRadius(10)
}
.disabled(viewModel.selectedAnswer != nil)
.padding(.horizontal)
.padding(.top, 5)
}
if viewModel.selectedAnswer != nil {
Button(action: {
viewModel.fetchQuizzes()
}) {
Text("Suivant")
.fontWeight(.bold)
.padding()
.frame(maxWidth: .infinity)
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(10)
}
.padding(.horizontal)
.padding(.top, 20)
}
}
.padding(.top)
}
Text("Points: \(viewModel.points)")
.font(.title)
.padding()
.background(Color.orange.opacity(0.7))
.cornerRadius(10)
.padding(.top, 20)
}
.padding()
}
.navigationTitle("Quizz")
}
private func backgroundColor(for answer: String, quiz: Quiz) -> Color {
if let selectedAnswer = viewModel.selectedAnswer {
if answer == selectedAnswer {
return viewModel.isAnswerCorrect == true ? .green : .red
} else if answer == quiz.answer {
return .green
} else {
return .blue
}
} else {
return .blue
}
}
}
import SwiftUI
import Combine
class QuizViewModel: ObservableObject {
@Published var quizzes: [Quiz] = []
@Published var points: Int = 0
@Published var selectedDifficulty: String = "facile"
@Published var selectedCategory: String = "tv_cinema"
@Published var currentAnswers: [String] = []
@Published var selectedAnswer: String? = nil
@Published var isAnswerCorrect: Bool? = nil
private var cancellable: AnyCancellable?
func fetchQuizzes() {
let urlString = "https://quizzapi.jomoreschi.fr/api/v1/quiz?limit=1&category=\(selectedCategory)&difficulty=\(selectedDifficulty)"
guard let url = URL(string: urlString) else { return }
cancellable = URLSession.shared.dataTaskPublisher(for: url)
.map { $0.data }
.decode(type: QuizResponse.self, decoder: JSONDecoder())
.replaceError(with: QuizResponse(count: 0, quizzes: []))
.receive(on: DispatchQueue.main)
.sink { [weak self] response in
guard let self = self else { return }
self.quizzes = response.quizzes
self.shuffleAnswers()
self.selectedAnswer = nil
self.isAnswerCorrect = nil
}
}
func shuffleAnswers() {
if let quiz = quizzes.first {
currentAnswers = (quiz.badAnswers + [quiz.answer]).shuffled()
}
}
func checkAnswer(_ selectedAnswer: String, for quiz: Quiz) {
self.selectedAnswer = selectedAnswer
self.isAnswerCorrect = (selectedAnswer == quiz.answer)
if isAnswerCorrect == true {
points += 1
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment