From c377a107c06507fc1280044accfc0bc3cf401a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Fri, 17 May 2024 19:26:48 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20des=20r=C3=A8gles=20des=20zones?= =?UTF-8?q?=F0=9F=91=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Interfaces/IRules.cs | 43 +++++++--- source/Trek-12/Models/Rules/Rules.cs | 92 ++++++++++++++++++++-- 2 files changed, 117 insertions(+), 18 deletions(-) diff --git a/source/Trek-12/Models/Interfaces/IRules.cs b/source/Trek-12/Models/Interfaces/IRules.cs index 5c0fa5c..249bb51 100644 --- a/source/Trek-12/Models/Interfaces/IRules.cs +++ b/source/Trek-12/Models/Interfaces/IRules.cs @@ -1,20 +1,37 @@ -namespace Models.Interfaces; +using Models.Game; + +namespace Models.Interfaces; public interface IRules -{ - public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary cells); +{ + //public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary cells); + + //public bool IsCellEmpty(Cell playerChoice); + + //public bool IsCellValid(Position playerChoicePosition, 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); + + public bool IsCellAdjacent(Cell choosenCell, Cell targetCell); + + public bool NearCellIsValid(Cell choosenCell, List cells); + + public bool IsZoneValidAndAddToZones(Cell chosenCell, Map map); + + public bool IsValueInZones(Cell chosenCell, List> zones); + + public void AddToZone(Cell chosenCell, List> zones); - public bool IsCellEmpty(Cell playerChoice); + public void NewZoneIsCreated(Cell firstCell, Cell secondCell, Map map); - public bool IsCellValid(Position playerChoicePosition, List cells); - - public bool IsZone(Cell playerChoice, List cells); + public List EveryAdjacentCells(Cell choosenCell, 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 int FinalCalculusOfZones(List> zones); - public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List cells); } \ No newline at end of file diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 0daa484..b5ce805 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -35,12 +35,94 @@ namespace Models.Rules } } - public bool IsZone(Cell choosen, List cells,List> zones) + public bool IsZoneValidAndAddToZones(Cell chosenCell, Map map) { - IEnumerable PlayedCellsQuery = - from cell in cells - where cell.Value != null - select cell; + if (chosenCell == null) return false; + + List adjacentCells = new List(); + + adjacentCells = EveryAdjacentCells(chosenCell, map.Boards); + + foreach(var cells in adjacentCells) + { + if (cells.Value == chosenCell.Value) + { + if(IsValueInZones(cells, map.Zones)) + { + AddToZone(chosenCell, map.Zones); + } + else + { + NewZoneIsCreated(chosenCell, cells, map); + } + return true; // Il y a une cellule adjacente avec la même valeur donc une zone est créée si elle n'est pas déjà existante + // Si il return true, tout c'est bien passer + } + } + + return false; + } + + public bool IsValueInZones(Cell chosenCell, List> zones) + { + if (chosenCell == null) return false; + + for (int i = 0; i < zones.Count; i++) + { + if (zones[i][0].Value == chosenCell.Value) + { + return true; + } + } + return false; + } + + public void AddToZone(Cell chosenCell, List> zones) + { + if (chosenCell == null) return; + + for (int i = 0; i < zones.Count; i++) + { + if (zones[i][0].Value == chosenCell.Value) + { + zones[i].Add(chosenCell); + return; + } + } + return; + } + + public void NewZoneIsCreated(Cell firstCell, Cell secondCell, Map map) + { + List newZone = new List(); + newZone.Add(firstCell); + newZone.Add(secondCell); + map.Zones.Add(newZone); + } + + public List EveryAdjacentCells(Cell choosenCell, List cells) + { + List adjacentCells = new List(); + + foreach (var cell in cells) + { + if (IsCellAdjacent(choosenCell, cell)) + { + adjacentCells.Add(cell); + } + } + + return adjacentCells; + } + + public int FinalCalculusOfZones(List> zones) + { + int calculus = 0; + for(int i = 0; i < zones.Count; i++) + { + calculus += zones[i].Count * zones[i][0].Value; + } + return calculus; } } From ebce3d1235b69f1fd02e5152e0171ef19885d21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Sat, 18 May 2024 09:55:07 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Cr=C3=A9ation=20d'un=20jeu=20d'essai=20donc?= =?UTF-8?q?=20j'ai=20tout=20changer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/ConsoleApp/Program.cs | 123 +++++++++++++++------ source/Trek-12/Models/Game/Game.cs | 18 +-- source/Trek-12/Models/Game/Map.cs | 8 +- source/Trek-12/Models/Game/Player.cs | 4 +- source/Trek-12/Models/Interfaces/IRules.cs | 4 +- source/Trek-12/Models/Rules/Rules.cs | 45 +++++++- 6 files changed, 146 insertions(+), 56 deletions(-) diff --git a/source/Trek-12/ConsoleApp/Program.cs b/source/Trek-12/ConsoleApp/Program.cs index a9062a1..5b4bd5f 100644 --- a/source/Trek-12/ConsoleApp/Program.cs +++ b/source/Trek-12/ConsoleApp/Program.cs @@ -4,32 +4,35 @@ using Models; using Models.Game; +using Models.Rules; -Position pos01 = new Position(0,0); -Position pos02 = new Position(1,0); -Position pos03 = new Position(2,0); -Position pos04 = new Position(3,0); -Position pos05 = new Position(4,0); - -Position pos11 = new Position(0, 1); -Position pos12 = new Position(1, 1); -Position pos13 = new Position(2, 1); -Position pos14 = new Position(3, 1); -Position pos15 = new Position(4, 1); - -Position pos21 = new Position(0, 2); -Position pos22 = new Position(1, 2); -Position pos23 = new Position(2, 2); -Position pos24 = new Position(3, 2); -Position pos25 = new Position(4, 2); - -Position pos31 = new Position(0, 3); -Position pos32 = new Position(1, 3); -Position pos33 = new Position(2, 3); -Position pos34 = new Position(3,3); -Position pos35 = new Position(4, 3); - -List list = new List(); + +Cell pos01 = new Cell(0,0); +Cell pos02 = new Cell(1,0); +Cell pos03 = new Cell(2,0); +Cell pos04 = new Cell(3,0); +Cell pos05 = new Cell(4,0); + +Cell pos11 = new Cell(0, 1); +Cell pos12 = new Cell(1, 1); +Cell pos13 = new Cell(2, 1); //8 +Cell pos14 = new Cell(3, 1); +Cell pos15 = new Cell(4, 1); + +Cell pos21 = new Cell(0, 2); //8 +Cell pos22 = new Cell(1, 2); +Cell pos23 = new Cell(2, 2); +Cell pos24 = new Cell(3, 2); +Cell pos25 = new Cell(4, 2); + +Cell pos31 = new Cell(0, 3); //8 +Cell pos32 = new Cell(1, 3); +Cell pos33 = new Cell(2, 3); +Cell pos34 = new Cell(3,3); +Cell pos35 = new Cell(4, 3); + + +List list = new List(); list.Add(pos01); list.Add(pos02); list.Add(pos03); @@ -107,34 +110,82 @@ foreach (var item in list) if (i % 4 == 0) Console.Write(" |\n"); }*/ +Player p2 = new Player("Luka"); + +Game game = new Game(p2, new Map("background")); -OperationsGrid grille = new OperationsGrid(); +//game.ResultOperation(Operation.ADDITION); +//game.ResultOperation(Operation.MULTIPLICATION); +//game.ResultOperation(Operation.LOWER); +//game.ResultOperation(Operation.MULTIPLICATION); +//game.ResultOperation(Operation.MULTIPLICATION); +//game.ResultOperation(Operation.HIGHER); -grille.ResultGrid(Operation.ADDITION); -grille.ResultGrid(Operation.MULTIPLICATION); -grille.ResultGrid(Operation.LOWER); -grille.ResultGrid(Operation.MULTIPLICATION); -grille.ResultGrid(Operation.MULTIPLICATION); -grille.ResultGrid(Operation.HIGHER); +game.UsedMap.Boards = list; + +game.PlaceResult(pos02, 5); +game.PlaceResult(pos03, 5); +game.PlaceResult(pos32, 5); + +game.PlaceResult(pos31, 8); +game.PlaceResult(pos21, 8); +game.PlaceResult(pos21, 8); +game.PlaceResult(pos13, 8); int cpt = 0; -foreach (var item in grille.Tiles) +/* +foreach (var item in game.UsedMap.Boards) { Console.Write(" | "); - Console.Write(item); + Console.Write(item.Value); cpt++; if (cpt % 4 == 0) Console.Write(" |\n"); } +*/ + +for (int i = 0; i Boards { get; private set; }; + public List Boards { get; set; } public string Background { get; private set; } public List OperationGrid { get; private set; } - public List> RopePaths { get; private set; } + //public List> RopePaths { get; private set; } public List> Zones { get; private set; } @@ -17,7 +17,9 @@ public class Map Boards = new List(); Background = background; OperationGrid = new List(); - RopePaths = new List>(); + //RopePaths = new List>(); Zones = new List>(); + } + } \ 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 0695f4c..c264f47 100644 --- a/source/Trek-12/Models/Game/Player.cs +++ b/source/Trek-12/Models/Game/Player.cs @@ -6,9 +6,9 @@ public class Player public string ProfilePicture { get; private set; } - public string CreationDate { get; private set; } + public string? CreationDate { get; private set; } - public string LastPlayed { get; private set; } + public string? LastPlayed { get; private set; } public Player() { diff --git a/source/Trek-12/Models/Interfaces/IRules.cs b/source/Trek-12/Models/Interfaces/IRules.cs index 249bb51..b44e43d 100644 --- a/source/Trek-12/Models/Interfaces/IRules.cs +++ b/source/Trek-12/Models/Interfaces/IRules.cs @@ -26,12 +26,14 @@ public interface IRules public bool IsValueInZones(Cell chosenCell, List> zones); + public bool IsCellInZone(Cell chosenCell, List> zones); + public void AddToZone(Cell chosenCell, List> zones); public void NewZoneIsCreated(Cell firstCell, Cell secondCell, Map map); public List EveryAdjacentCells(Cell choosenCell, List cells); - public int FinalCalculusOfZones(List> zones); + public int? FinalCalculusOfZones(List> zones); } \ No newline at end of file diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index b5ce805..3f9d9a4 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -14,13 +14,15 @@ namespace Models.Rules { if (Math.Abs(choosenCell.X - targetCell.X) > 1 || Math.Abs(choosenCell.Y - targetCell.Y) > 1) return false; + if (Math.Abs(choosenCell.X - targetCell.X) > 1 && Math.Abs(choosenCell.Y - targetCell.Y) > 1) + return false; return true; } public bool NearCellIsValid(Cell choosenCell, List cells) { - if (choosenCell == null) return false; + if (choosenCell == null || cells == null) return false; IEnumerable PlayedCellsQuery = from cell in cells @@ -33,6 +35,8 @@ namespace Models.Rules return true; } + + return false; } public bool IsZoneValidAndAddToZones(Cell chosenCell, Map map) @@ -55,7 +59,7 @@ namespace Models.Rules { NewZoneIsCreated(chosenCell, cells, map); } - return true; // Il y a une cellule adjacente avec la même valeur donc une zone est créée si elle n'est pas déjà existante + //return true; // Il y a une cellule adjacente avec la même valeur donc une zone est créée si elle n'est pas déjà existante // Si il return true, tout c'est bien passer } } @@ -77,9 +81,25 @@ namespace Models.Rules return false; } + public bool IsCellInZone(Cell chosenCell, List> zones) + { + if (chosenCell == null) return false; + + for (int i = 0; i < zones.Count; i++) + { + if (zones[i].Contains(chosenCell)) + { + return true; + } + } + return false; + } + public void AddToZone(Cell chosenCell, List> zones) { - if (chosenCell == null) return; + if (chosenCell == null || chosenCell.Value == null) return; + + if (IsCellInZone(chosenCell, zones)) return; for (int i = 0; i < zones.Count; i++) { @@ -94,6 +114,7 @@ namespace Models.Rules public void NewZoneIsCreated(Cell firstCell, Cell secondCell, Map map) { + if (firstCell == null || secondCell == null || firstCell.Value == null || secondCell.Value == null) return; List newZone = new List(); newZone.Add(firstCell); newZone.Add(secondCell); @@ -115,9 +136,9 @@ namespace Models.Rules return adjacentCells; } - public int FinalCalculusOfZones(List> zones) + public int? FinalCalculusOfZones(List> zones) { - int calculus = 0; + int? calculus = 0; for(int i = 0; i < zones.Count; i++) { calculus += zones[i].Count * zones[i][0].Value; @@ -125,5 +146,19 @@ namespace Models.Rules return calculus; } + public bool IsBugged(Cell chosenCell, List> zones) + { + if (chosenCell == null) return false; + + for (int i = 0; i < zones.Count; i++) + { + if (zones[i].Contains(chosenCell)) + { + return true; + } + } + return false; + } + } } \ No newline at end of file