diff --git a/Pendu.xcodeproj/project.pbxproj b/Pendu.xcodeproj/project.pbxproj index 51ea773b43a21e6afec9e8b74734bb02fe348433..70516820f94d27fa2997bb2586a33484de886836 100644 --- a/Pendu.xcodeproj/project.pbxproj +++ b/Pendu.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ BF1D4A112A1CF23B002F97CB /* GameEngineMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF5A7EC82A13BF8A00168B16 /* GameEngineMock.swift */; }; BF1D4A122A1CF36D002F97CB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C480D2A0A1FCA00CE128F /* AppDelegate.swift */; }; + BF204BD52A385F000043A16C /* WorldScoreboardController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF204BD42A385F000043A16C /* WorldScoreboardController.swift */; }; BF3C480E2A0A1FCA00CE128F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C480D2A0A1FCA00CE128F /* AppDelegate.swift */; }; BF3C48102A0A1FCA00CE128F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C480F2A0A1FCA00CE128F /* SceneDelegate.swift */; }; BF3C48122A0A1FCA00CE128F /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3C48112A0A1FCA00CE128F /* GameViewController.swift */; }; @@ -49,6 +50,7 @@ /* Begin PBXFileReference section */ 157E41DA2A1D136300E6DE57 /* zadi.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = zadi.jpeg; path = ../../zadi.jpeg; sourceTree = "<group>"; }; + BF204BD42A385F000043A16C /* WorldScoreboardController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorldScoreboardController.swift; sourceTree = "<group>"; }; BF3C480A2A0A1FCA00CE128F /* Pendu.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Pendu.app; sourceTree = BUILT_PRODUCTS_DIR; }; BF3C480D2A0A1FCA00CE128F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; BF3C480F2A0A1FCA00CE128F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; }; @@ -135,6 +137,7 @@ D082CCC82A0A33D600D97981 /* GameEngine.swift */, BF3C48422A0A3CFF00CE128F /* GameEngineTests.swift */, BF5A7EC82A13BF8A00168B16 /* GameEngineMock.swift */, + BF204BD42A385F000043A16C /* WorldScoreboardController.swift */, ); path = Pendu; sourceTree = "<group>"; @@ -306,6 +309,7 @@ BF3C48182A0A1FCA00CE128F /* Pendu.xcdatamodeld in Sources */, D0D074F82A25F3EB00526851 /* ViewController.swift in Sources */, BF3C48102A0A1FCA00CE128F /* SceneDelegate.swift in Sources */, + BF204BD52A385F000043A16C /* WorldScoreboardController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Pendu/Base.lproj/Main.storyboard b/Pendu/Base.lproj/Main.storyboard index 64c3697e501ca11d32dccaf607161e545725894c..1cbb0df79c8f5ec81a34ba31f962a8a2095d58ef 100644 --- a/Pendu/Base.lproj/Main.storyboard +++ b/Pendu/Base.lproj/Main.storyboard @@ -16,7 +16,7 @@ <rect key="frame" x="0.0" y="0.0" width="390" height="844"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> - <textField opaque="NO" alpha="0.84999999999999998" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Player name" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="iRK-mL-RC3"> + <textField opaque="NO" alpha="0.84999999999999998" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Pseudonyme" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="iRK-mL-RC3"> <rect key="frame" x="28" y="267" width="335" height="34"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> @@ -28,8 +28,8 @@ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <segments> - <segment title="Easy"/> - <segment title="Hard"/> + <segment title="Facile"/> + <segment title="Difficile"/> </segments> </segmentedControl> <button contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lae-hh-psQ"> @@ -39,7 +39,7 @@ <state key="normal" title="Button"/> <buttonConfiguration key="configuration" style="gray"> <attributedString key="attributedTitle"> - <fragment content="My score"> + <fragment content="Mes scores"> <attributes> <font key="NSFont" size="18" name="Helvetica"/> <paragraphStyle key="NSParagraphStyle" alignment="natural" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/> @@ -56,7 +56,7 @@ <rect key="frame" x="28" y="621" width="335" height="39"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <state key="normal" title="Button"/> - <buttonConfiguration key="configuration" style="filled" title="Start game"> + <buttonConfiguration key="configuration" style="filled" title="Commencer la partie"> <fontDescription key="titleFontDescription" style="UICTFontTextStyleTitle3"/> <color key="baseBackgroundColor" red="0.16242280080033861" green="0.61513349139014162" blue="0.69163225280749385" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> </buttonConfiguration> @@ -70,13 +70,13 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> </pickerView> <button contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4Oq-OS-e2C"> - <rect key="frame" x="233" y="102" width="130" height="39"/> + <rect key="frame" x="175" y="102" width="188" height="39"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="tintColor" systemColor="labelColor"/> <state key="normal" title="Button"/> <buttonConfiguration key="configuration" style="gray"> <attributedString key="attributedTitle"> - <fragment content="Ranking"> + <fragment content="Classement mondial"> <attributes> <font key="NSFont" size="18" name="Helvetica"/> <paragraphStyle key="NSParagraphStyle" alignment="natural" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/> @@ -104,28 +104,41 @@ </objects> <point key="canvasLocation" x="275.38461538461536" y="72.511848341232223"/> </scene> - <!--View Controller--> + <!--Classement mondial--> <scene sceneID="l4M-7k-UUe"> <objects> - <viewController id="aQz-4m-G2v" sceneMemberID="viewController"> + <viewController title="Classement mondial" id="aQz-4m-G2v" customClass="WorldScoreboardController" customModule="Pendu" customModuleProvider="target" sceneMemberID="viewController"> <view key="view" contentMode="scaleToFill" id="jFk-yG-B96"> <rect key="frame" x="0.0" y="0.0" width="390" height="844"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="reH-wE-BOx"> - <rect key="frame" x="37" y="138" width="312" height="561"/> + <rect key="frame" x="0.0" y="88" width="390" height="756"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> + <prototypes> + <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="ScoreCell" id="Xmg-1B-9nu"> + <rect key="frame" x="0.0" y="44.666666030883789" width="390" height="43.666667938232422"/> + <autoresizingMask key="autoresizingMask"/> + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Xmg-1B-9nu" id="yPd-X2-yjD"> + <rect key="frame" x="0.0" y="0.0" width="390" height="43.666667938232422"/> + <autoresizingMask key="autoresizingMask"/> + </tableViewCellContentView> + </tableViewCell> + </prototypes> </tableView> </subviews> <viewLayoutGuide key="safeArea" id="N0d-E2-OLY"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> </view> - <navigationItem key="navigationItem" id="MWc-6A-tgg"/> + <navigationItem key="navigationItem" title="Classement mondial" id="MWc-6A-tgg" userLabel="Classement mondial"/> + <connections> + <outlet property="scoreTable" destination="reH-wE-BOx" id="kz4-nl-YVY"/> + </connections> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="zoG-p9-fvl" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="1112" y="-680"/> + <point key="canvasLocation" x="1110.7692307692307" y="-680.33175355450237"/> </scene> <!--Partie--> <scene sceneID="LqT-Za-AMF"> @@ -523,7 +536,7 @@ <nil key="highlightedColor"/> </label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6lc-Ks-xyB"> - <rect key="frame" x="272" y="88" width="100" height="21"/> + <rect key="frame" x="272" y="88" width="100" height="20.333333333333329"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <nil key="textColor"/> <nil key="highlightedColor"/> @@ -583,7 +596,7 @@ </objects> <point key="canvasLocation" x="1112.3076923076924" y="72.511848341232223"/> </scene> - <!--View Controller--> + <!--Mes scores--> <scene sceneID="DOp-cS-lmI"> <objects> <viewController id="NpT-5q-8iC" sceneMemberID="viewController"> @@ -592,7 +605,7 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="6qe-0q-g54"> - <rect key="frame" x="43" y="197" width="308" height="491"/> + <rect key="frame" x="0.0" y="88" width="390" height="756"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> </tableView> @@ -600,7 +613,7 @@ <viewLayoutGuide key="safeArea" id="5W1-ma-4ti"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> </view> - <navigationItem key="navigationItem" id="oJn-Ow-Ppk"/> + <navigationItem key="navigationItem" title="Mes scores" id="oJn-Ow-Ppk"/> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="lSg-hU-biK" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> </objects> diff --git a/Pendu/WorldScoreboardController.swift b/Pendu/WorldScoreboardController.swift new file mode 100644 index 0000000000000000000000000000000000000000..fed6ab7901ab100552b10bdbb6b9fe9921789e58 --- /dev/null +++ b/Pendu/WorldScoreboardController.swift @@ -0,0 +1,81 @@ +// +// WorldScoreboardController.swift +// Pendu +// +// Created by Sofiane Lasri-Trienpont on 13/06/2023. +// + +import UIKit + +class WorldScoreboardController: UIViewController, UITableViewDataSource { + + @IBOutlet weak var scoreTable: UITableView! + // Structure pour représenter les données JSON + struct ScoreData: Codable { + let categoryName: String + let difficulty: String + let playerName: String + let score: Int + } + + // Tableau pour stocker les données JSON + var scores: [ScoreData] = [] + + override func viewDidLoad() { + super.viewDidLoad() + scoreTable.register(UITableViewCell.self, forCellReuseIdentifier: "ScoreCell") + // Appeler la fonction pour récupérer les données JSON + fetchJSONData() + + // Définir le contrôleur en tant que dataSource du TableView + scoreTable.dataSource = self + } + + func fetchJSONData() { + // URL de la liste JSON + guard let url = URL(string: "https://miscs.sl-projects.com/IUT-ORSAY/LP-PRISM/TP-iOS/") else { + print("URL invalide") + return + } + + URLSession.shared.dataTask(with: url) { [weak self] (data, _, error) in + guard let data = data else { + if let error = error { + print("Erreur lors de la récupération des données : \(error.localizedDescription)") + } + return + } + + do { + // Décoder les données JSON + let decoder = JSONDecoder() + self?.scores = try decoder.decode([ScoreData].self, from: data) + + // Mettre à jour le TableView sur le thread principal + DispatchQueue.main.async { + self?.scoreTable.reloadData() + } + } catch { + print("Erreur lors du décodage des données JSON : \(error.localizedDescription)") + } + }.resume() + } + + // Méthodes requises pour le UITableViewDataSource + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return scores.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "ScoreCell", for: indexPath) + + let score = scores[indexPath.row] + + // Afficher les données dans les cellules du TableView + cell.textLabel?.text = "\(score.playerName) | \(score.categoryName) - \(score.difficulty) - \(score.score) pts" + + return cell + } + +}