From e90f8cb1852b61b65baa165dd500f0be46d56d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Wed, 29 May 2024 15:27:43 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20des=20op=C3=A9rations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/ConsoleApp/Program.cs | 12 ++++++++++-- source/Trek-12/Models/Game/Game.cs | 2 +- source/Trek-12/Models/Game/Map.cs | 5 +++++ source/Trek-12/Models/Game/OperationCell.cs | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/source/Trek-12/ConsoleApp/Program.cs b/source/Trek-12/ConsoleApp/Program.cs index 69dfa14..adc70f7 100644 --- a/source/Trek-12/ConsoleApp/Program.cs +++ b/source/Trek-12/ConsoleApp/Program.cs @@ -76,7 +76,7 @@ class Program static void OnDiceRolled(object sender, DiceRolledEventArgs e) { Console.WriteLine($"Dice 1: {e.Dice1Value} | Dice 2: {e.Dice2Value}"); - Operation playerOperation = GetPlayerOperation(); + Operation playerOperation = GetPlayerOperation(sender); ((Game)sender).HandlePlayerOperation(playerOperation); } @@ -230,7 +230,7 @@ class Program /// /// /// - static Operation GetPlayerOperation() + static Operation GetPlayerOperation(object? sender) { DisplayOperationOptions(); string? op = Console.ReadLine(); @@ -239,6 +239,14 @@ class Program Console.WriteLine("Invalid operation. Please choose again."); op = Console.ReadLine(); } + int test = Convert.ToInt32(op); + while(((Game)sender).UsedMap.CheckOperationPossible(test-1)) + { + Console.WriteLine("Invalid operation. Please choose again."); + Console.WriteLine(); + op = Console.ReadLine(); + test = Convert.ToInt32(op); + } return op switch { diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index 586ce34..a9b9d10 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -94,7 +94,7 @@ namespace Models.Game /// If the operation is MULTIPLICATION, it returns the product of the values of the two dice. /// If the operation is not one of the operations, it throws an ArgumentOutOfRangeException. /// - private int ResultOperation(Operation o) + public int ResultOperation(Operation o) { int result = o switch { diff --git a/source/Trek-12/Models/Game/Map.cs b/source/Trek-12/Models/Game/Map.cs index 56dbb69..ccc327b 100644 --- a/source/Trek-12/Models/Game/Map.cs +++ b/source/Trek-12/Models/Game/Map.cs @@ -74,5 +74,10 @@ } return operationGrid; } + + public bool CheckOperationPossible(int x) + { + return OperationGrid[x * 4 + 3].IsChecked; + } } } \ No newline at end of file diff --git a/source/Trek-12/Models/Game/OperationCell.cs b/source/Trek-12/Models/Game/OperationCell.cs index d8ac6da..4667ff0 100644 --- a/source/Trek-12/Models/Game/OperationCell.cs +++ b/source/Trek-12/Models/Game/OperationCell.cs @@ -17,6 +17,7 @@ namespace Models.Game /// public OperationCell(int x, int y) : base(x, y) { + IsChecked = false; } ///