From 941587fe4cae2ae59f20f4c171751f70e7526f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Neveu?= Date: Wed, 5 Jun 2024 17:13:38 +0200 Subject: [PATCH] =?UTF-8?q?Retour=20=C3=A0=20la=20version=20de=20la=20sema?= =?UTF-8?q?ine=20derni=C3=A8re=20pour=20modifier=20les=20joueurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Game/Game.cs | 14 ++++++ source/Trek-12/Models/Game/Player.cs | 8 +++- .../Trek-12/Views/pageProfiles.xaml.cs | 43 +++++++++++-------- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index e311f62..0294cd4 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -131,6 +131,20 @@ namespace Models.Game return true; } + public bool ModifyPlayer(string pseudo, string newpseudo) + { + foreach (var index in Players) + { + if (index.Pseudo == pseudo) + { + index.Pseudo = newpseudo; + return true; + } + } + + return false; + } + public void LoadData() { var data = PersistenceManager.LoadData(); diff --git a/source/Trek-12/Models/Game/Player.cs b/source/Trek-12/Models/Game/Player.cs index 9287ced..cb8f095 100644 --- a/source/Trek-12/Models/Game/Player.cs +++ b/source/Trek-12/Models/Game/Player.cs @@ -10,8 +10,13 @@ namespace Models.Game /// Represents a player in the game. /// [DataContract] - public class Player + public class Player : INotifyPropertyChanged { + public event PropertyChangedEventHandler PropertyChanged; + + void OnPropertyChanged([CallerMemberName] string propertyName = null) + => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + /// /// It is he pseudo of the player. /// @@ -25,6 +30,7 @@ namespace Models.Game if (_pseudo == value) return; _pseudo = value; + OnPropertyChanged(); } } diff --git a/source/Trek-12/Trek-12/Views/pageProfiles.xaml.cs b/source/Trek-12/Trek-12/Views/pageProfiles.xaml.cs index 4ebb2ac..fb68196 100644 --- a/source/Trek-12/Trek-12/Views/pageProfiles.xaml.cs +++ b/source/Trek-12/Trek-12/Views/pageProfiles.xaml.cs @@ -61,28 +61,35 @@ public partial class PageProfiles : ContentPage async void Button_ClickedModify(System.Object sender, System.EventArgs e) { - throw new NotImplementedException(); - /* + if (ProfileManager.Players.Count == 0) + { + await DisplayAlert("Info", "There is no player actually\nPlease add one", "Ok"); + return; + } + string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok"); Debug.WriteLine("Answer: " + result); - if (result != null) + if (result == null) + { + Debug.WriteLine("Did not found"); + return; + } + string tomodify = await DisplayPromptAsync("Info", $"How will you rename it ?: ", "Ok"); + Debug.WriteLine("Answer: " + tomodify); + if (tomodify == null) { - string tomodify = await DisplayPromptAsync("Info", $"How will you rename it ?: ", "Ok"); - Debug.WriteLine("Answer: " + tomodify); - if (tomodify != null) - { - Debug.WriteLine("bam, modified"); - bool ismodified = MyStub.Modify(result, tomodify); - - if (ismodified) - { - Debug.WriteLine("Modified"); - } - else Debug.WriteLine("Player not found"); - } + Debug.WriteLine("Did not found"); + return; } - else Debug.WriteLine("Did not found"); - */ + Debug.WriteLine("bam, modified"); + bool ismodified = ProfileManager.ModifyPlayer(result, tomodify); + + if (ismodified) + { + Debug.WriteLine("Modified"); + ProfileManager.SaveData(); + } + else Debug.WriteLine("Player not found"); } }