From 462e8dc74494e0310722f8ab13295bccfd0dc1e9 Mon Sep 17 00:00:00 2001 From: Duflot Lucas Date: Sat, 8 Jun 2024 03:28:52 +0200 Subject: [PATCH 1/2] :construction: Finalisation de la gameLoop --- source/Trek-12/ConsoleApp/Program.cs | 166 +++++++++++++++--- .../Models/Events/BoardsUpdateEventArgs.cs | 2 +- .../Events/PlayerChooseCellEventArgs.cs | 18 ++ .../Events/PlayerChooseOperationEventArgs.cs | 19 ++ .../Models/Events/PlayerOptionEventArgs.cs | 23 +++ source/Trek-12/Models/Game/Game.cs | 89 +++++----- source/Trek-12/Models/Game/Map.cs | 2 +- source/Trek-12/Models/Rules/Rules.cs | 18 +- 8 files changed, 273 insertions(+), 64 deletions(-) create mode 100644 source/Trek-12/Models/Events/PlayerChooseCellEventArgs.cs create mode 100644 source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs create mode 100644 source/Trek-12/Models/Events/PlayerOptionEventArgs.cs diff --git a/source/Trek-12/ConsoleApp/Program.cs b/source/Trek-12/ConsoleApp/Program.cs index ad4d2b5..1e01d72 100644 --- a/source/Trek-12/ConsoleApp/Program.cs +++ b/source/Trek-12/ConsoleApp/Program.cs @@ -6,6 +6,9 @@ using Models.Exceptions; using Models.Game; using Models.Interfaces; using DataContractPersistence; +using Microsoft.Extensions.Logging; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace ConsoleApp; @@ -34,12 +37,116 @@ class Program game.DiceRolled += OnDiceRolled!; game.OperationChosen += OnOperationChosen!; game.CellChosen += OnCellChosen!; + game.PlayerChooseOp += OnPlayerSelectionOp!; + game.PlayerOption += OnPlayerOption!; + game.PlayerChooseCell += OnPlayerSelectionCell!; // Initialisation game.InitializeGame(map, player); } + + } + static void OnPlayerSelectionCell(Object sender, PlayerChooseCellEventArgs e) + { + int row, column; + while (true) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("Enter the position of the cell you want to play"); + Console.WriteLine("Enter the row number (0-6)"); + Console.ResetColor(); + if (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 7) + { + Console.ForegroundColor= ConsoleColor.Red; + Console.WriteLine("Invalid row number. Please enter a number between 0 and 6."); + Console.ResetColor(); + continue; + } + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("Enter the column number (0-6)"); + Console.ResetColor(); + if (!int.TryParse(Console.ReadLine(), out column) || column < 0 || column >= 7) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Invalid column number. Please enter a number between 0 and 6."); + Console.ResetColor(); + continue; + } + + e.Cell = new Cell(row, column); + break; + } + } + + static void OnPlayerOption(object sender, PlayerOptionEventArgs e) + { + Console.WriteLine(); + if(e.Turn != 1) + { + IEnumerable PlayedCellsQuery = + from cell in e.Board + where cell.Value != null + select cell; + foreach (var item in e.Board) + { + if (!item.Valid) + Console.Write(" "); + else if (item.Value != null) + Console.Write($"{item.Value}"); + else + { + foreach (var item1 in PlayedCellsQuery) + { + if (Math.Abs(item.X - item1.X) <= 1 && Math.Abs(item.Y - item1.Y) <= 1) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.Write($"{e.Resultat}"); + Console.ResetColor(); + } + } + } + } + } + foreach (var item in e.Board) + { + if (!item.Valid) + Console.Write(" "); + else + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.Write($"{e.Resultat}"); + Console.ResetColor(); + + } + if (item.X == 6) + Console.WriteLine(); + } + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("Choose an Available cell."); + Console.ResetColor(); + } + + static void OnPlayerSelectionOp(object sender, PlayerChooseOperationEventArgs e) + { + Console.WriteLine(); + DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList()); + Console.WriteLine(); + Console.WriteLine("1. Lower | 2. Higher | 3. Substraction | 4. Addition | 5. Multiplication"); + string? op = Console.ReadLine(); + while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5") + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Invalid operation. Please choose again."); + Console.ResetColor(); + op = Console.ReadLine(); + } + e.Operation = 3; + } + + /// /// Handles the event when the game has started. /// @@ -66,10 +173,20 @@ class Program /// /// /// - static void OnBoardUpdated(object sender, EventArgs e) + static void OnBoardUpdated(object sender, BoardsUpdateEventArgs e) { - DisplayBoard(((Game)sender).UsedMap); - DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList()); + foreach (var item in e.Boards) + { + if (!item.Valid) + Console.Write(" "); + else + { + Console.Write($"{item.Value}"); + + } + if (item.X == 6) + Console.WriteLine(); + } } /// @@ -79,9 +196,12 @@ class Program /// static void OnDiceRolled(object sender, DiceRolledEventArgs e) { + // Console.Clear(); Console.WriteLine($"Dice 1: {e.Dice1Value} | Dice 2: {e.Dice2Value}"); - Operation playerOperation = GetPlayerOperation(sender); - ((Game)sender).HandlePlayerOperation(playerOperation); + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("Choose an operation."); + Console.ResetColor(); } /// @@ -181,24 +301,28 @@ class Program /// The operation table to display. static void DisplayOperationTable(List operationTable) { - Console.WriteLine("Operation Table:"); - string[] operations = { "Addition (+)", "Subtraction (-)", "Multiplication (*)", "Lower Dice (less)", "Higher Dice (high)" }; - - for (int i = 0; i < operations.Length; i++) + Console.ForegroundColor = ConsoleColor.Yellow; + foreach ( var cell in operationTable) { - Console.Write(operations[i].PadRight(18)); - - for (int j = 0; j < 4; j++) - { - int index = i * 4 + j; - if (index < operationTable.Count) - { - string status = operationTable[index].IsChecked ? "X" : " "; - Console.Write($" | {status}"); - } - } - Console.WriteLine(); + + if (cell.X == 0 && cell.Y == 0) + Console.Write("Lower => "); + if (cell.X == 0 && cell.Y == 1) + Console.Write("Higher => "); + if (cell.X == 0 && cell.Y == 2) + Console.Write("Substraction => "); + if (cell.X == 0 && cell.Y == 3) + Console.Write("Addition => "); + if (cell.X == 0 && cell.Y == 4) + Console.Write("Multiplication => "); + if (cell.IsChecked) + Console.Write("X | "); + if (!cell.IsChecked) + Console.Write(" | "); + if (cell.X == 3) + Console.WriteLine(); } + Console.ResetColor(); } /// diff --git a/source/Trek-12/Models/Events/BoardsUpdateEventArgs.cs b/source/Trek-12/Models/Events/BoardsUpdateEventArgs.cs index 22e205f..1526db6 100644 --- a/source/Trek-12/Models/Events/BoardsUpdateEventArgs.cs +++ b/source/Trek-12/Models/Events/BoardsUpdateEventArgs.cs @@ -7,7 +7,7 @@ namespace Models.Events /// public class BoardsUpdateEventArgs : EventArgs { - public List Boards { get; } + public List Boards { get; set; } public BoardsUpdateEventArgs(List board) { diff --git a/source/Trek-12/Models/Events/PlayerChooseCellEventArgs.cs b/source/Trek-12/Models/Events/PlayerChooseCellEventArgs.cs new file mode 100644 index 0000000..cf51950 --- /dev/null +++ b/source/Trek-12/Models/Events/PlayerChooseCellEventArgs.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Models.Game; + +namespace Models.Events +{ + public class PlayerChooseCellEventArgs : EventArgs + { + public Cell Cell { get; set; } + public PlayerChooseCellEventArgs(Cell cell) + { + Cell = cell; + } + } +} diff --git a/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs b/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs new file mode 100644 index 0000000..a1b0a80 --- /dev/null +++ b/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs @@ -0,0 +1,19 @@ +using Models.Game; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models.Events +{ + public class PlayerChooseOperationEventArgs : EventArgs + { + public int Operation { get; set; } + + public PlayerChooseOperationEventArgs(int op) + { + Operation = op; + } + } +} diff --git a/source/Trek-12/Models/Events/PlayerOptionEventArgs.cs b/source/Trek-12/Models/Events/PlayerOptionEventArgs.cs new file mode 100644 index 0000000..036370b --- /dev/null +++ b/source/Trek-12/Models/Events/PlayerOptionEventArgs.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Models.Game; + +namespace Models.Events +{ + public class PlayerOptionEventArgs : EventArgs + { + public List Board { get; set; } + public int Resultat { get; set; } + public int Turn { get; set; } + + public PlayerOptionEventArgs(List boards, int resultat, int turn) + { + Board = boards; + Resultat = resultat; + Turn = turn; + } + } +} diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index e0f1059..482a5cf 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -115,7 +115,11 @@ namespace Models.Game public event EventHandler DiceRolled; public event EventHandler OperationChosen; public event EventHandler CellChosen; - + public event EventHandler PlayerChooseOp; + public event EventHandler PlayerOption; + public event EventHandler PlayerChooseCell; + + public void AddPlayer(Player player) { Players.Add(player); @@ -224,9 +228,9 @@ namespace Models.Game /// Marks an operation as checked in the operation grid of the game. /// /// - public void MarkOperationAsChecked(Operation operation) + private void MarkOperationAsChecked(Operation operation) { - int operationIndex = (int)operation; + int operationIndex = (int)operation; IEnumerable sortPaths = from cell in UsedMap.OperationGrid where cell.Y == operationIndex @@ -264,8 +268,6 @@ namespace Models.Game Operation.MULTIPLICATION => Dice2.Value * Dice1.Value, _ => throw new ArgumentOutOfRangeException() }; - - MarkOperationAsChecked(o); return result; } @@ -276,25 +278,18 @@ namespace Models.Game /// /// The cell chosen by the player to place the result. /// The result of the dice operation to be placed in the cell. - private bool PlaceResult(Cell playerChoice, int result) + private void PlaceResult(Cell playerChoice, int result) { - if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards.ToList())) - { - for (int i = 0; i < UsedMap.Boards.Count; i++) - { - if (UsedMap.Boards[i].X == playerChoice.X && UsedMap.Boards[i].Y == playerChoice.Y) - { - if (UsedMap.Boards[i].Value != null) - return false; - UsedMap.Boards[i].Value = result; - BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); - return true; - } - } - //playerChoice.Value = result; + IEnumerable ValidCell = + from cell in UsedMap.Boards + where cell.Value == null + where cell.Valid == true + select cell; + foreach (var item in ValidCell) + { + if(item.X == playerChoice.X && item.Y == playerChoice.Y) + item.Value = result; } - return false; - } /// @@ -376,28 +371,42 @@ namespace Models.Game /// private void GameLoop() { + int res = 0,turn = 1; + Cell cell; while (IsRunning) { - if (Turn == 20) - { - foreach(var cells in UsedMap.Boards.ToList()) - { - GameRules.IsZoneValidAndAddToZones(cells, UsedMap); - AddToRopePath(cells, GameRules.EveryAdjacentCells(cells, UsedMap.Boards.ToList())); - } - int? points = GameRules.FinalCalculusOfZones(UsedMap.Zones); - for (int i = 0; i < UsedMap.RopePaths.Count; i++) - { - points += GameRules.ScoreRopePaths(UsedMap.RopePaths[i]); - } - EndGame(points); - break; - } - RollAllDice(); + res = PlayerChooseOperation(); + PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn)); + cell = PlayerCell(); + PlaceResult(cell,res); + BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); + + } + } - Turn++; + public int PlayerChooseOperation() + { + int operation=0; + PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation)); + while(!GameRules.OperationAvailable(operation,UsedMap.OperationGrid.ToList())) + { + PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation)); + } + MarkOperationAsChecked((Operation)operation); + return ResultOperation((Operation)operation); + } + + public Cell PlayerCell() + { + Cell ?playerCell = new Cell(1,0); + playerCell.Valid = true; + PlayerChooseCell?.Invoke(this,new PlayerChooseCellEventArgs(playerCell)); + while(!GameRules.NearCellIsValid(playerCell,UsedMap.Boards.ToList())) + { + PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(playerCell)); } + return playerCell; } /// @@ -431,7 +440,7 @@ namespace Models.Game //throw new InvalidCellException("Cell is not valid. Please choose again."); } - bool res = PlaceResult(cell, result); + bool res = true; if (!res) { return false; diff --git a/source/Trek-12/Models/Game/Map.cs b/source/Trek-12/Models/Game/Map.cs index 6acd93a..a340e68 100644 --- a/source/Trek-12/Models/Game/Map.cs +++ b/source/Trek-12/Models/Game/Map.cs @@ -72,7 +72,7 @@ namespace Models.Game { for (int i = 0; i < 49; i++) // 7x7 board { - board.Add(new Cell(i / 7, i % 7)); + board.Add(new Cell(i % 7, i / 7)); } board[1].Valid = true; board[3].Valid = true; diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 7e17b3e..9ef5e82 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -110,11 +110,13 @@ namespace Models.Rules IEnumerable PlayedCellsQuery = from cell in cells - where cell.Value != null + where cell.Valid == true select cell; foreach (var cell in PlayedCellsQuery) { + if (choosenCell.X == cell.X && choosenCell.Y == cell.Y && cell.Value == null) + return true; if (IsCellAdjacent(choosenCell, cell)) { return true; @@ -256,5 +258,19 @@ namespace Models.Rules return score; } + public bool OperationAvailable(int operation,List operationGrid) + { + IEnumerable row = + from cell in operationGrid + where cell.Y == operation + select cell; + foreach (var item in row) + { + if (!item.IsChecked) + return true; + } + return false; + } + } } \ No newline at end of file From d516b5898dd2a4e8787bbadb0743358f7bfb3d24 Mon Sep 17 00:00:00 2001 From: Lucas DUFLOT Date: Sat, 8 Jun 2024 10:00:50 +0200 Subject: [PATCH 2/2] :construction: Console App --- source/Trek-12/ConsoleApp/Program.cs | 47 +++++++++++-------- .../Events/PlayerChooseOperationEventArgs.cs | 6 +-- source/Trek-12/Models/Game/Game.cs | 40 ++++++++-------- source/Trek-12/Models/Rules/Rules.cs | 18 +++---- 4 files changed, 57 insertions(+), 54 deletions(-) diff --git a/source/Trek-12/ConsoleApp/Program.cs b/source/Trek-12/ConsoleApp/Program.cs index 1e01d72..bd9f6ae 100644 --- a/source/Trek-12/ConsoleApp/Program.cs +++ b/source/Trek-12/ConsoleApp/Program.cs @@ -14,6 +14,9 @@ namespace ConsoleApp; class Program { + + static Game Game { get; set; } + /// /// Main function of the console app /// @@ -28,21 +31,21 @@ class Program Player player = new Player(pseudo, "test.png"); Map map = new Map("Dunai","background"); - Game game = new Game(persistence); + Game = new Game(persistence); // Abonnement aux événements - game.GameStarted += OnGameStarted!; - game.GameEnded += OnGameEnded!; - game.BoardUpdated += OnBoardUpdated!; - game.DiceRolled += OnDiceRolled!; - game.OperationChosen += OnOperationChosen!; - game.CellChosen += OnCellChosen!; - game.PlayerChooseOp += OnPlayerSelectionOp!; - game.PlayerOption += OnPlayerOption!; - game.PlayerChooseCell += OnPlayerSelectionCell!; + Game.GameStarted += OnGameStarted!; + Game.GameEnded += OnGameEnded!; + Game.BoardUpdated += OnBoardUpdated!; + Game.DiceRolled += OnDiceRolled!; + Game.OperationChosen += OnOperationChosen!; + Game.CellChosen += OnCellChosen!; + Game.PlayerChooseOp += OnPlayerSelectionOp!; + Game.PlayerOption += OnPlayerOption!; + Game.PlayerChooseCell += OnPlayerSelectionCell!; // Initialisation - game.InitializeGame(map, player); + Game.InitializeGame(map, player); } @@ -75,7 +78,7 @@ class Program continue; } - e.Cell = new Cell(row, column); + Game.PlayerCell = new Cell(row, column); break; } } @@ -86,11 +89,14 @@ class Program if(e.Turn != 1) { IEnumerable PlayedCellsQuery = - from cell in e.Board + from cell in e.Board + where cell.Valid == true where cell.Value != null select cell; foreach (var item in e.Board) { + if (item.X == 6) + Console.WriteLine(); if (!item.Valid) Console.Write(" "); else if (item.Value != null) @@ -108,6 +114,7 @@ class Program } } } + return; } foreach (var item in e.Board) { @@ -134,16 +141,18 @@ class Program Console.WriteLine(); DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList()); Console.WriteLine(); - Console.WriteLine("1. Lower | 2. Higher | 3. Substraction | 4. Addition | 5. Multiplication"); + Console.WriteLine("0. Lower | 1. Higher | 2. Substraction | 3. Addition | 4. Multiplication"); string? op = Console.ReadLine(); - while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5") + while (op != "0" && op != "1" && op != "2" && op != "3" && op != "4") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid operation. Please choose again."); Console.ResetColor(); op = Console.ReadLine(); } - e.Operation = 3; + int test = Convert.ToInt32(op); + Game.PlayerOperation = (Operation)test; + } @@ -179,11 +188,9 @@ class Program { if (!item.Valid) Console.Write(" "); - else - { + else if (item.Value != null) Console.Write($"{item.Value}"); - - } + else Console.Write("O"); if (item.X == 6) Console.WriteLine(); } diff --git a/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs b/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs index a1b0a80..ccbcd6b 100644 --- a/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs +++ b/source/Trek-12/Models/Events/PlayerChooseOperationEventArgs.cs @@ -9,11 +9,11 @@ namespace Models.Events { public class PlayerChooseOperationEventArgs : EventArgs { - public int Operation { get; set; } + public Operation PlayerOp { get; set; } - public PlayerChooseOperationEventArgs(int op) + public PlayerChooseOperationEventArgs(Operation op) { - Operation = op; + PlayerOp = op; } } } diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index 482a5cf..ec73759 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -105,6 +105,10 @@ namespace Models.Game [DataMember] public int Turn { get; private set; } + public Operation PlayerOperation { get; set; } + + public Cell PlayerCell { get; set; } + public Rules.Rules GameRules { get; } @@ -285,10 +289,10 @@ namespace Models.Game where cell.Value == null where cell.Valid == true select cell; - foreach (var item in ValidCell) - { - if(item.X == playerChoice.X && item.Y == playerChoice.Y) - item.Value = result; + foreach (var item in ValidCell) + { + if(item.X == playerChoice.X && item.Y == playerChoice.Y) + item.Value = result; } } @@ -378,35 +382,31 @@ namespace Models.Game RollAllDice(); res = PlayerChooseOperation(); PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn)); - cell = PlayerCell(); - PlaceResult(cell,res); + PlayerSelectionCell(); + PlaceResult(PlayerCell,res); BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); - + turn++; } } public int PlayerChooseOperation() { - int operation=0; - PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation)); - while(!GameRules.OperationAvailable(operation,UsedMap.OperationGrid.ToList())) + PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation)); + while(!GameRules.OperationAvailable(PlayerOperation,UsedMap.OperationGrid.ToList())) { - PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation)); + PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation)); } - MarkOperationAsChecked((Operation)operation); - return ResultOperation((Operation)operation); + return ResultOperation(PlayerOperation); } - public Cell PlayerCell() + public void PlayerSelectionCell() { - Cell ?playerCell = new Cell(1,0); - playerCell.Valid = true; - PlayerChooseCell?.Invoke(this,new PlayerChooseCellEventArgs(playerCell)); - while(!GameRules.NearCellIsValid(playerCell,UsedMap.Boards.ToList())) + PlayerChooseCell?.Invoke(this,new PlayerChooseCellEventArgs(PlayerCell)); + while(!GameRules.NearCellIsValid(PlayerCell,UsedMap.Boards.ToList())) { - PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(playerCell)); + PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(PlayerCell)); } - return playerCell; + MarkOperationAsChecked(PlayerOperation); } /// diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 9ef5e82..7b73de9 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -54,10 +54,7 @@ namespace Models.Rules { if (Math.Abs(choosenCell.X - targetCell.X) <= 1 && Math.Abs(choosenCell.Y - targetCell.Y) <= 1) { - if (choosenCell.X != targetCell.X || choosenCell.Y != targetCell.Y) - { return true; - } } return false; @@ -118,9 +115,8 @@ namespace Models.Rules if (choosenCell.X == cell.X && choosenCell.Y == cell.Y && cell.Value == null) return true; if (IsCellAdjacent(choosenCell, cell)) - { return true; - } + } return false; @@ -258,16 +254,16 @@ namespace Models.Rules return score; } - public bool OperationAvailable(int operation,List operationGrid) + public bool OperationAvailable(Operation operation,List operationGrid) { IEnumerable row = from cell in operationGrid - where cell.Y == operation + where cell.Y == (int)operation select cell; - foreach (var item in row) - { - if (!item.IsChecked) - return true; + foreach (var item in row) + { + if (!item.IsChecked) + return true; } return false; }