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; } ///