diff --git a/source/Trek-12/ConsoleApp/Program.cs b/source/Trek-12/ConsoleApp/Program.cs index 7fecb55..cd0a03e 100644 --- a/source/Trek-12/ConsoleApp/Program.cs +++ b/source/Trek-12/ConsoleApp/Program.cs @@ -96,24 +96,24 @@ for (int i = 0; i /// Places the result of a dice operation into a chosen cell on the game board. /// The result can be placed in the chosen cell if it's the first turn or if the chosen cell is valid according to the game rules. @@ -165,18 +166,84 @@ namespace Models.Game /// private async void GameLoop() { + Cell PlayerChoice = new Cell(0, 0); + string op = ""; + Operation convOp = new Operation(); + int valueCurrentCell = 0; while (_isRunning) { + if (Turn == 20) GameEnded?.Invoke(this, new GameEndedEventArgs(CurrentPlayer)); /* if (CheckGameEnd()) //TODO Règle pour check si fin de jeu { _isRunning = false; //TODO Code pour comptabiliser les points + int scoreZones = GameRules.FinalCalculusOfZones(UsedMap.Zones); //GameEnded?.Invoke(this, new GameEndedEventArgs(player)); } */ await Task.Delay(1000); // 1 seconde + UsedMap.DisplayBoards(); + RollAllDice(); + Console.WriteLine($"Dice 1: {Dice1.Value} | Dice 2: {Dice2.Value}"); + Console.WriteLine("What do you want : " + + "Addition ? ( + )" + + "Substraction ? ( - )" + + "Multiplication ? ( * )" + + "The lower dice ? ( less )" + + "The higher dice ? high )"); + + op = Console.ReadLine(); + while (op != "+" && op != "-" && op != "*" && op != "less" && op != "high") + { + op = Console.ReadLine(); + } + + if (op == "less") + { + convOp = Operation.LOWER; + //incrémentation du tableau des opérations + } + + else if (op == "high") + { + convOp = Operation.HIGHER; + //incrémentation du tableau des opérations + } + if (op == "+") + { + convOp = Operation.ADDITION; + //incrémentation du tableau des opérations + } + if (op == "-") + { + convOp = Operation.SUBTRACTION; + //incrémentation du tableau des opérations + } + if (op == "*") + { + convOp = Operation.MULTIPLICATION; + //incrémentation du tableau des opérations + } + + valueCurrentCell = ResultOperation(convOp); + Console.WriteLine($"The value of the dice is : {valueCurrentCell}"); + Console.WriteLine(); + PlayerChoice = UsedMap.PlayerChoiceOfPosition(); + + while (!GameRules.IsCellValid(PlayerChoice, UsedMap.Boards)) + { + PlayerChoice = UsedMap.PlayerChoiceOfPosition(); + } + PlaceResult(PlayerChoice, valueCurrentCell); + + GameRules.IsZoneValidAndAddToZones(PlayerChoice, UsedMap); + AddToRopePath(PlayerChoice, GameRules.EveryAdjacentCells(PlayerChoice, UsedMap.Boards)); + + Turn++; + + } } diff --git a/source/Trek-12/Models/Game/Map.cs b/source/Trek-12/Models/Game/Map.cs index 2b094db..ab60b79 100644 --- a/source/Trek-12/Models/Game/Map.cs +++ b/source/Trek-12/Models/Game/Map.cs @@ -31,9 +31,87 @@ public class Map public Map(string background) { Boards = new List(); + Boards = InitializeBoards(); Background = background; OperationGrid = new List(); - //RopePaths = new List>(); + RopePaths = new List>(); Zones = new List>(); } + + public static List InitializeBoards() + { + 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); + Cell pos14 = new Cell(3, 1); + Cell pos15 = new Cell(4, 1); + + Cell pos21 = new Cell(0, 2); + 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); + 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); + list.Add(pos04); + list.Add(pos05); + + list.Add(pos11); + list.Add(pos12); + list.Add(pos13); + list.Add(pos14); + list.Add(pos15); + + list.Add(pos21); + list.Add(pos22); + list.Add(pos23); + list.Add(pos24); + list.Add(pos25); + + list.Add(pos31); + list.Add(pos32); + list.Add(pos33); + list.Add(pos34); + list.Add(pos35); + + return list; + } + + public void DisplayBoards() + { + int cpt = 0; + for (int i = 0; i < Boards.Count; i++) + { + Console.Write(" | "); + Console.Write(Boards[i].Value); + cpt++; + if (cpt % 5 == 0) Console.Write(" |\n"); + } + } + + public Cell PlayerChoiceOfPosition() + { + Console.WriteLine("Enter the position of the cell you want to play"); + Console.WriteLine("Enter the row number"); + int row = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Enter the column number"); + int column = Convert.ToInt32(Console.ReadLine()); + return new Cell(row, column); + } } diff --git a/source/Trek-12/Models/Interfaces/IRules.cs b/source/Trek-12/Models/Interfaces/IRules.cs index cf79a0c..691df73 100644 --- a/source/Trek-12/Models/Interfaces/IRules.cs +++ b/source/Trek-12/Models/Interfaces/IRules.cs @@ -6,9 +6,9 @@ public interface IRules { //public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary cells); - //public bool IsCellEmpty(Cell playerChoice); + public bool IsCellEmpty(Cell playerChoice); - //public bool IsCellValid(Position playerChoicePosition, List cells); + public bool IsCellValid(Cell playerChoicePosition, List cells); //public bool IsRopePath(Cell playerChoice, HashSet ropePaths); diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 723a0d6..25f0d64 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -10,6 +10,22 @@ namespace Models.Rules { public class Rules : IRules { + + public bool IsCellEmpty(Cell playerChoice) + { + if (playerChoice == null || playerChoice.Value == null) return true; + return false; + } + + public bool IsCellValid(Cell playerChoicePosition, List cells) + { + if (!IsCellEmpty(playerChoicePosition)) return false; + + if (EveryAdjacentCells(playerChoicePosition, cells).Count == 1) return false; + + return true; + } + public bool IsCellAdjacent(Cell choosenCell, Cell targetCell) { if (Math.Abs(choosenCell.X - targetCell.X) > 1 || Math.Abs(choosenCell.Y - targetCell.Y) > 1) @@ -72,7 +88,7 @@ namespace Models.Rules public void IsZoneValidAndAddToZones(Cell chosenCell, Map map) { - if (chosenCell == null ||chosenCell.Value == null) return false; + if (chosenCell == null ||chosenCell.Value == null) return; List adjacentCells = new List(); @@ -95,7 +111,7 @@ namespace Models.Rules } } - return false; + return; } public bool IsValueInZones(Cell chosenCell, List> zones) @@ -158,6 +174,7 @@ namespace Models.Rules foreach (var cell in cells) { + if (choosenCell == cell) continue; if (IsCellAdjacent(choosenCell, cell)) { adjacentCells.Add(cell); @@ -172,7 +189,11 @@ namespace Models.Rules int? calculus = 0; for(int i = 0; i < zones.Count; i++) { - calculus += zones[i].Count * zones[i][0].Value; + calculus += zones[i].Count - 1 + zones[i][0].Value; + if (zones[i].Count > 9) + { + calculus += (zones[i].Count - 9) * 5; + } } return calculus; }