diff --git a/source/Trek-12/Models/BestScore.cs b/source/Trek-12/Models/Game/BestScore.cs similarity index 84% rename from source/Trek-12/Models/BestScore.cs rename to source/Trek-12/Models/Game/BestScore.cs index 96718ca..f320e1a 100644 --- a/source/Trek-12/Models/BestScore.cs +++ b/source/Trek-12/Models/Game/BestScore.cs @@ -35,10 +35,6 @@ namespace Models _score = value; } } - public override string ToString() - { - return $"Ce joueur a joué {GamesPlayed} parties et à pour meilleur score {Score}"; - } public void IncrGamesPlayed() { diff --git a/source/Trek-12/Models/Cell.cs b/source/Trek-12/Models/Game/Cell.cs similarity index 88% rename from source/Trek-12/Models/Cell.cs rename to source/Trek-12/Models/Game/Cell.cs index e8f4bf4..0b63cfa 100644 --- a/source/Trek-12/Models/Cell.cs +++ b/source/Trek-12/Models/Game/Cell.cs @@ -17,11 +17,12 @@ public class Cell private bool IsDangerous { get; set; } - public string? Background { get; set; } + private bool Penalty { get; set; } public Cell(bool isDangerous = false) { IsDangerous = isDangerous; + Penalty = false; } public bool GetCellType() => IsDangerous; diff --git a/source/Trek-12/Models/Game/Dice.cs b/source/Trek-12/Models/Game/Dice.cs index ec61dcc..5df6c9a 100644 --- a/source/Trek-12/Models/Game/Dice.cs +++ b/source/Trek-12/Models/Game/Dice.cs @@ -33,7 +33,7 @@ namespace Models.Game return $"Ce dé a pour valeur {Value} et est entre {NbMin} et {NbMax}"; } - public void Lancer() + public void Roll() { Value = new Random().Next(NbMin, NbMax + 1); } diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index c19bfaa..61e4687 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Models.Events; namespace Models.Game { @@ -17,12 +18,13 @@ namespace Models.Game private int Turn { get; set; } - private Rules.Rules GameRules { get; } + private IRules GameRules { get; } - private HashSet ropePaths { get; } + // == Events == + public event GameStartedEventArgs OnGameStarted; - - public Game(Player player, Map map) + + public event GameStartedEventArgs GameStarted; public Game(Player player, Map map) { UsedMap = map; CurrentPlayer = player; @@ -35,8 +37,8 @@ namespace Models.Game public void RollAllDice() { - Dice1.Lancer(); - Dice2.Lancer(); + Dice1.Roll(); + Dice2.Roll(); } public int ResultOperation(Operation o) @@ -63,7 +65,7 @@ namespace Models.Game } } - public void PlaceResult (Cell playerChoice,int result) + public void PlaceResult (Cell playerChoice, int result) { if (Turn == 1 || GameRules.NearCell(playerChoice, UsedMap.Cells)) { diff --git a/source/Trek-12/Models/Game/Map.cs b/source/Trek-12/Models/Game/Map.cs index 6d634cd..b190892 100644 --- a/source/Trek-12/Models/Game/Map.cs +++ b/source/Trek-12/Models/Game/Map.cs @@ -2,12 +2,22 @@ public class Map { - public SortedDictionary Cells { get; private set; } + public List Boards { get; private set; }; + public string Background { get; private set; } - + + public List OperationGrid { get; private set; } + + public List> RopePaths { get; private set; } + + public List> Zones { get; private set; } + public Map(string background) { - Cells = new SortedDictionary(); + Boards = new List(); Background = background; + OperationGrid = new List(); + RopePaths = new List>(); + Zones = new List>(); } } \ No newline at end of file diff --git a/source/Trek-12/Models/Operation.cs b/source/Trek-12/Models/Game/Operation.cs similarity index 100% rename from source/Trek-12/Models/Operation.cs rename to source/Trek-12/Models/Game/Operation.cs diff --git a/source/Trek-12/Models/Game/OperationCell.cs b/source/Trek-12/Models/Game/OperationCell.cs new file mode 100644 index 0000000..641b7ab --- /dev/null +++ b/source/Trek-12/Models/Game/OperationCell.cs @@ -0,0 +1,6 @@ +namespace Models; + +public class OperationCell : Position +{ + public bool IsChecked { get ; private set} +} \ No newline at end of file diff --git a/source/Trek-12/Models/Game/Player.cs b/source/Trek-12/Models/Game/Player.cs index cbc4035..0695f4c 100644 --- a/source/Trek-12/Models/Game/Player.cs +++ b/source/Trek-12/Models/Game/Player.cs @@ -6,6 +6,10 @@ public class Player public string ProfilePicture { get; private set; } + public string CreationDate { get; private set; } + + public string LastPlayed { get; private set; } + public Player() { Pseudo = "Player"; diff --git a/source/Trek-12/Models/Position.cs b/source/Trek-12/Models/Game/Position.cs similarity index 100% rename from source/Trek-12/Models/Position.cs rename to source/Trek-12/Models/Game/Position.cs diff --git a/source/Trek-12/Models/Game/RopePath.cs b/source/Trek-12/Models/Game/RopePath.cs deleted file mode 100644 index 15fd51c..0000000 --- a/source/Trek-12/Models/Game/RopePath.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Models.Game; - -public class RopePath -{ - public HashSet Cells { get; } = new HashSet(); -} \ No newline at end of file diff --git a/source/Trek-12/Models/Game/RopesZones.cs b/source/Trek-12/Models/Game/RopesZones.cs deleted file mode 100644 index 1174b0b..0000000 --- a/source/Trek-12/Models/Game/RopesZones.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Models.Game -{ - public class RopesZones - { - public List>? RopeZone { get; set; } - - } -} diff --git a/source/Trek-12/Models/Interfaces/ICell.cs b/source/Trek-12/Models/Interfaces/ICell.cs deleted file mode 100644 index fd548ac..0000000 --- a/source/Trek-12/Models/Interfaces/ICell.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Models.Interfaces; - -public interface ICell -{ - string GetCellType(); -} \ No newline at end of file diff --git a/source/Trek-12/Models/Interfaces/IRules.cs b/source/Trek-12/Models/Interfaces/IRules.cs new file mode 100644 index 0000000..5c0fa5c --- /dev/null +++ b/source/Trek-12/Models/Interfaces/IRules.cs @@ -0,0 +1,20 @@ +namespace Models.Interfaces; + +public interface IRules +{ + public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary cells); + + public bool IsCellEmpty(Cell playerChoice); + + public bool IsCellValid(Position playerChoicePosition, List cells); + + public bool IsZone(Cell playerChoice, List cells); + + public bool IsRopePath(Cell playerChoice, HashSet ropePaths); + + public bool IsAdjacent(Cell cell1, Cell cell2, List cells); + + public int HowMany(Cell playerChoice, List cells); + + public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells); +} \ No newline at end of file diff --git a/source/Trek-12/Models/OperationsGrid.cs b/source/Trek-12/Models/OperationsGrid.cs deleted file mode 100644 index f5b4672..0000000 --- a/source/Trek-12/Models/OperationsGrid.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Models -{ - public class OperationsGrid - { - public bool[,] Tiles; - - public OperationsGrid() - { - Tiles = new bool[5,4]; - - } - - public void ResultGrid(Operation p) - { - switch (p) - { - case Operation.LOWER: - for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[0, i] == false) { Tiles[0, i] = true; return; } } - break; - - case Operation.HIGHER: - for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[1, i] == false) { Tiles[1, i] = true; return; } } - break; - - case Operation.SUBTRACTION: - for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[2, i] == false) { Tiles[2, i] = true; return; } } - break; - - case Operation.ADDITION: - for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[3, i] == false) { Tiles[3, i] = true; return; } } - break; - - case Operation.MULTIPLICATION: - for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[4, i] == false) { Tiles[4, i] = true; return; } } - break; - - default: - return; - } - } - - } -} diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index da33ee7..4b9c0b6 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -7,105 +7,40 @@ using Models.Game; namespace Models.Rules { - public class Rules + public class Rules : IRules { - public bool IsCellExist(Position playerChoicePosition, SortedDictionary cells) + public bool IsCellAdjacent(Cell choosenCell, Cell targetCell) { - return cells.ContainsKey(playerChoicePosition); - } - - public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary cells) - { - if (!IsCellExist(playerChoicePosition, cells)) return false; - - foreach (var cell in cells) - { - if (Math.Abs(playerChoicePosition.X - cell.Key.X) > 1 || Math.Abs(playerChoicePosition.Y - cell.Key.Y) > 1) continue; + if (Math.Abs(choosenCell.Pos.X - targetCell.Cell.X) > 1 || Math.Abs(choosenCell.Pos.Y - targetCell.Cell.Y) > 1) + return false; - if (!IsCellEmpty(cell.Value)) - { - return true; - } - } - return false; + return true; } - public bool IsCellEmpty(Cell playerChoice) + public bool NearCellIsValid(Cell choosenCell, List> cells) { - return !playerChoice.Value.HasValue; - } + if (choosenCell == null) return false; + + IEnumerable PlayedCellsQuery = + from cell in cells + where cell.Value != null + select cell; - public bool IsCellValid(Position playerChoicePosition, SortedDictionary cells) - { - return NearCellIsValid(playerChoicePosition, cells) && IsCellEmpty(cells. - } - - public bool IsZone(Cell playerChoice, SortedDictionary cells) - { - foreach (var k,v in cells) + foreach (var cell in PlayedCellsQuery) { - if (playerChoice.X != item.X + 1 && playerChoice.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; - } - - /// - /// Determines if a given cell is part of any rope path. - /// - /// The cell to check. - /// A collection of rope paths to check against. - /// True if the cell is part of any rope path, false otherwise. - public bool IsRopePath(Cell playerChoice, HashSet ropePaths) - { - foreach (var path in ropePaths) - { - if (path.Cells.Contains(playerChoice)) - { - return true; - } - } - return false; - } - - public bool IsAdjacent(Cell cell1, Cell cell2, SortedDictionary cells) - { - bool isSequence = cell1.Value.HasValue && cell2.Value.HasValue && Math.Abs(cell1.Value.Value - cell2.Value.Value) == 1; + if(!IsCellAdjacent(choosenCell, cell)) continue; - return IsCellValid(cell1, cells) && isSequence; - } - - public int HowMany(Cell playerChoice, SortedDictionary cells) - { - foreach(var pos in cells) - { - if (pos.Equals(playerChoice)) - { - return pos.GetCellType() ? 6 : 12; - } + return true; } - return 0; } - public void SetValueAndPenalty(int valueChoice, Cell playerChoice, SortedDictionary cells) + public bool IsZone(Cell choosen, List> cells) { - int val = HowMany(playerChoice, cells); - - foreach (var pos in cells) - { - if (!pos.Equals(playerChoice)) continue; - - if (valueChoice > val) - { - playerChoice.Background = "penalty"; - } - playerChoice.Value = valueChoice; - } + IEnumerable PlayedCellsQuery = + from cell in cells + where cell.Value != null + select cell; } + } -} +} \ No newline at end of file