diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index fe00778..9ca0e8c 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -8,32 +8,32 @@ namespace Models.Game { public class Game { - public Player CurentPlayer { get; set; } + public Player CurrentPlayer { get; set; } - public Map NameMap { get; set; } + private Map UsedMap { get; set; } - public De De1 { get; set; } - public De De2 { 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) { - NameMap = map; - CurentPlayer = player; - De1 = new De(); - De2 = new De(1); + UsedMap = map; + CurrentPlayer = player; + Dice1 = new De(); + Dice2 = new De(1); Turn = 0; - rules = new Rules.Rules(); + 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,19 +65,17 @@ namespace Models.Game { playerChoice.Value = result; } - else - { - if(rules.NearCell(playerChoice,NameMap.Cells)) + else + { + if(Rules.NearCell(playerChoice,UsedMap.Cells)) { playerChoice.Value = result; - } + } } - return; } public void AddRopeZone(Cell playerChoice,RopesZones list) { - } } diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 90f91c4..a2d99bb 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -8,37 +8,84 @@ namespace Models.Rules { public class Rules { - public bool NearCell(Cell playerChoice, List cells) + public static bool NearCell(Cell playerChoice, List cells) + { + 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 static bool IsCellEmpty(Cell playerChoice) + { + return playerChoice.Value == null; + } + + public static bool IsCellValid(Cell playerChoice, List cells) + { + return NearCell(playerChoice, cells) && IsCellEmpty(playerChoice); + } + + 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) { return true; } } return false; } - - public bool IsCellEmpty(Cell playerChoice) + + public static bool IsRopePath(Cell playerChoice, List cells, List ropePaths) { - if (playerChoice.Value == null) + foreach (var item in cells) { - return true; + 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 (path.Equals(playerChoice)) + { + return true; + } + } + return IsRopePath(item, cells, ropePaths); } - return false; } + + public static int HowMany(Cell playerChoice, List cells) + { + foreach(var pos in cells) + { + if (pos.Equals(playerChoice)) + { + return pos.GetCellType() ? 6 : 12; + } + } + return 0; + } - public bool IsCellValid(Cell playerChoice, List cells) + public static void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells) { - if (NearCell(playerChoice, cells) && IsCellEmpty(playerChoice)) + int val = HowMany(playerChoice, cells); + + foreach (var pos in cells) { - return true; + if (!pos.Equals(playerChoice)) continue; + + if (valueChoice > val) + { + playerChoice.Background = "penalty"; + } + playerChoice.Value = valueChoice; } - - return false; } } } 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; - } - } - } - - } -}