From 581e73b2219fa4347661d247423612bb3993e3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Wed, 15 May 2024 16:53:06 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Usage=20d'op=C3=A9rateurs=20ter?= =?UTF-8?q?naires=20(et=20traduction=20de=20variables)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Game/Game.cs | 46 +++++++++++------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index fe00778..6f0e93e 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -10,10 +10,10 @@ namespace Models.Game { public Player CurentPlayer { get; set; } - public Map NameMap { get; set; } + public Map UsedMap { get; set; } - public De De1 { get; set; } - public De De2 { get; set; } + public De Dice1 { get; set; } + public De Dice2 { get; set; } public int Turn { get; set; } @@ -22,18 +22,18 @@ namespace Models.Game public Game(Player player,Map map) { - NameMap = map; + UsedMap = map; CurentPlayer = player; - De1 = new De(); - De2 = new De(1); + Dice1 = new De(); + Dice2 = new De(1); Turn = 0; rules = new Rules.Rules(); } public void ThrowDice() { - De1.Lancer(); - De2.Lancer(); + Dice1.Lancer(); + Dice2.Lancer(); } public int ResultOperation(Operation o) @@ -41,31 +41,19 @@ namespace Models.Game switch (o) { case Operation.LOWER: - if (De1.IsLower(De2)) - { - return De1.Nb; - } - return De2.Nb; + return Dice1.IsLower(Dice2) ? Dice1.Nb : Dice2.Nb; case Operation.HIGHER: - if (De1.IsLower(De2)) - { - return De2.Nb; - } - return De1.Nb; + return Dice1.IsLower(Dice2) ? Dice2.Nb : Dice1.Nb; case Operation.SUBTRACTION: - if (De1.IsLower(De2)) - { - return De2.Nb - De1.Nb; - } - return De1.Nb - De2.Nb; + return Dice1.IsLower(Dice2) ? Dice2.Nb - Dice1.Nb : Dice1.Nb - Dice2.Nb; case Operation.ADDITION: - return De2.Nb + De1.Nb; + return Dice2.Nb + Dice1.Nb; case Operation.MULTIPLICATION: - return De2.Nb * De1.Nb; + return Dice2.Nb * Dice1.Nb; default: return 0; } @@ -77,12 +65,12 @@ namespace Models.Game { playerChoice.Value = result; } - else - { - if(rules.NearCell(playerChoice,NameMap.Cells)) + else + { + if(rules.NearCell(playerChoice,UsedMap.Cells)) { playerChoice.Value = result; - } + } } return; } From 86eb33c89bc6bf3a86e52540e7e08bfe8753a20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Wed, 15 May 2024 17:05:08 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Correction=20syntaxe=20et=20visibilit=C3=A9?= =?UTF-8?q?=20des=20propri=C3=A9t=C3=A9s=20de=20Game.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Game/Game.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index 6f0e93e..9ca0e8c 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -8,26 +8,26 @@ namespace Models.Game { public class Game { - public Player CurentPlayer { get; set; } + public Player CurrentPlayer { get; set; } - public Map UsedMap { get; set; } + private Map UsedMap { get; set; } - public De Dice1 { get; set; } - public De Dice2 { get; set; } + private De Dice1 { get; set; } + private De Dice2 { get; set; } - public int Turn { get; set; } + private int Turn { get; set; } - public Rules.Rules rules { get; set; } + private Rules.Rules Rules { get; set; } public Game(Player player,Map map) { UsedMap = map; - CurentPlayer = player; + CurrentPlayer = player; Dice1 = new De(); Dice2 = new De(1); Turn = 0; - rules = new Rules.Rules(); + Rules = new Rules.Rules(); } public void ThrowDice() @@ -67,17 +67,15 @@ namespace Models.Game } else { - if(rules.NearCell(playerChoice,UsedMap.Cells)) + if(Rules.NearCell(playerChoice,UsedMap.Cells)) { playerChoice.Value = result; } } - return; } public void AddRopeZone(Cell playerChoice,RopesZones list) { - } } From 96dee898adc63759d2c9d8fe40d230011403025a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Wed, 15 May 2024 17:09:16 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9E=96=20Rassemblement=20des=20m=C3=A9th?= =?UTF-8?q?odes=20de=20r=C3=A8gles=20dans=20la=20m=C3=AAme=20classe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Rules/Rules.cs | 71 ++++++++++++++++++++++++++ source/Trek-12/Models/Rules/Zones.cs | 43 ---------------- source/Trek-12/Models/Rules/ruleBox.cs | 45 ---------------- 3 files changed, 71 insertions(+), 88 deletions(-) delete mode 100644 source/Trek-12/Models/Rules/Zones.cs delete mode 100644 source/Trek-12/Models/Rules/ruleBox.cs diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 90f91c4..5a375da 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -40,5 +40,76 @@ namespace Models.Rules return false; } + + public bool IsZone(Cell playerChoice, List cells) + { + foreach (var item in cells) + { + if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 + || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1) + { + if (playerChoice.Value == item.Value) + { + return true; + } + } + } + return false; + } + + public bool IsCheminDeCorde(Cell playerChoice, List cells, List cheminsDeCorde) + { + foreach (var item in cells) + { + if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 + || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1) + { + if (playerChoice.Value == item.Value+1 || playerChoice.Value == item.Value-1) + { + foreach (var chemin in cheminsDeCorde) + { + if (chemin.Equals(playerChoice)) + { + return true; + } + } + return IsCheminDeCorde(item, cells, cheminsDeCorde); + } + } + } + return false; + } + + public int HowMany(Cell playerChoice, List cells) + { + foreach(var pos in cells) + { + if (pos.Equals(playerChoice)) + { + if (pos.GetCellType()) + { + return 6; + } + return 12; + } + } + return 0; + } + + public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells) + { + int val = HowMany(playerChoice, cells); + foreach (var pos in cells) + { + if (pos.Equals(playerChoice)) + { + if (valueChoice > val) + { + playerChoice.Background = "notcontent"; + } + playerChoice.Value = valueChoice; + } + } + } } } diff --git a/source/Trek-12/Models/Rules/Zones.cs b/source/Trek-12/Models/Rules/Zones.cs deleted file mode 100644 index bc99d7d..0000000 --- a/source/Trek-12/Models/Rules/Zones.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Models.Rules; - -public class Zones -{ - public bool IsZone(Cell playerChoice, List cells) - { - foreach (var item in cells) - { - if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 - || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1) - { - if (playerChoice.Value == item.Value) - { - return true; - } - } - } - return false; - } - - public bool IsCheminDeCorde(Cell playerChoice, List cells, List cheminsDeCorde) - { - foreach (var item in cells) - { - if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 - || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1) - { - if (playerChoice.Value == item.Value+1 || playerChoice.Value == item.Value-1) - { - foreach (var chemin in cheminsDeCorde) - { - if (chemin.Equals(playerChoice)) - { - return true; - } - } - return IsCheminDeCorde(item, cells, cheminsDeCorde); - } - } - } - return false; - } -} \ No newline at end of file diff --git a/source/Trek-12/Models/Rules/ruleBox.cs b/source/Trek-12/Models/Rules/ruleBox.cs deleted file mode 100644 index 4f338d1..0000000 --- a/source/Trek-12/Models/Rules/ruleBox.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Models; - -namespace Models.Rules -{ - public class ruleBox - { - public int HowMany(Cell playerChoice, List cells) - { - foreach(var pos in cells) - { - if (pos.Equals(playerChoice)) - { - if (pos.GetCellType()) - { - return 6; - } - return 12; - } - } - return 0; - } - - public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells) - { - int val = HowMany(playerChoice, cells); - foreach (var pos in cells) - { - if (pos.Equals(playerChoice)) - { - if (valueChoice > val) - { - playerChoice.Background = "notcontent"; - } - playerChoice.Value = valueChoice; - } - } - } - - } -} From 619cdaf3cc60d3b8805fb11f3dc5adb09022020f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Wed, 15 May 2024 17:23:42 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=A8=20Utilisation=20de=20LINQ.=20Am?= =?UTF-8?q?=C3=A9lioration=20de=20la=20s=C3=A9curit=C3=A9=20(visibilit?= =?UTF-8?q?=C3=A9=20et=20static).=20Factorisation=20et=20r=C3=A9duction=20?= =?UTF-8?q?d'imbrication=20du=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Rules/Rules.cs | 88 ++++++++++------------------ 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 5a375da..a2d99bb 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -8,107 +8,83 @@ namespace Models.Rules { public class Rules { - public bool NearCell(Cell playerChoice, List cells) + public static bool NearCell(Cell playerChoice, List cells) { - foreach (var item in cells) - { - if(playerChoice.Pos.X == item.Pos.X +1 || playerChoice.Pos.X == item.Pos.X - 1 - || playerChoice.Pos.Y == item.Pos.Y +1 || playerChoice.Pos.Y == item.Pos.Y -1 ) - { - return true; - } - } - return false; + return cells.Any(item => playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1); } - public bool IsCellEmpty(Cell playerChoice) + public static bool IsCellEmpty(Cell playerChoice) { - if (playerChoice.Value == null) - { - return true; - } - - return false; + return playerChoice.Value == null; } - public bool IsCellValid(Cell playerChoice, List cells) + public static bool IsCellValid(Cell playerChoice, List cells) { - if (NearCell(playerChoice, cells) && IsCellEmpty(playerChoice)) - { - return true; - } - - return false; + return NearCell(playerChoice, cells) && IsCellEmpty(playerChoice); } - public bool IsZone(Cell playerChoice, List cells) + public static bool IsZone(Cell playerChoice, List cells) { foreach (var item in cells) { - if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 - || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1) + if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1 + && playerChoice.Pos.Y != item.Pos.Y + 1 && + playerChoice.Pos.Y != item.Pos.Y - 1) continue; + if (playerChoice.Value == item.Value) { - if (playerChoice.Value == item.Value) - { - return true; - } + return true; } } return false; } - public bool IsCheminDeCorde(Cell playerChoice, List cells, List cheminsDeCorde) + public static bool IsRopePath(Cell playerChoice, List cells, List ropePaths) { foreach (var item in cells) { - if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 - || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1) + if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1 + && playerChoice.Pos.Y != item.Pos.Y + 1 && + playerChoice.Pos.Y != item.Pos.Y - 1) continue; + + if (playerChoice.Value != item.Value + 1 && playerChoice.Value != item.Value - 1) continue; + + foreach (var path in ropePaths) { - if (playerChoice.Value == item.Value+1 || playerChoice.Value == item.Value-1) + if (path.Equals(playerChoice)) { - foreach (var chemin in cheminsDeCorde) - { - if (chemin.Equals(playerChoice)) - { - return true; - } - } - return IsCheminDeCorde(item, cells, cheminsDeCorde); + return true; } } + return IsRopePath(item, cells, ropePaths); } return false; } - public int HowMany(Cell playerChoice, List cells) + public static int HowMany(Cell playerChoice, List cells) { foreach(var pos in cells) { if (pos.Equals(playerChoice)) { - if (pos.GetCellType()) - { - return 6; - } - return 12; + return pos.GetCellType() ? 6 : 12; } } return 0; } - public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells) + public static void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells) { int val = HowMany(playerChoice, cells); + foreach (var pos in cells) { - if (pos.Equals(playerChoice)) + if (!pos.Equals(playerChoice)) continue; + + if (valueChoice > val) { - if (valueChoice > val) - { - playerChoice.Background = "notcontent"; - } - playerChoice.Value = valueChoice; + playerChoice.Background = "penalty"; } + playerChoice.Value = valueChoice; } } }