✔ Chemins de corde
continuous-integration/drone/push Build was killed Details

pull/109/head
Lucas DUFLOT 1 year ago
parent 56c47829e8
commit 2595ac686f

@ -1,414 +1,414 @@
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information
using Models; using Models;
using Models.Events; using Models.Events;
using Models.Game; using Models.Game;
using Models.Interfaces; using Models.Interfaces;
using DataContractPersistence; using DataContractPersistence;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace ConsoleApp; namespace ConsoleApp;
class Program class Program
{ {
static Game Game { get; set; } static Game Game { get; set; }
/// <summary> /// <summary>
/// Main function of the console app /// Main function of the console app
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Enter your pseudo:"); Console.WriteLine("Enter your pseudo:");
string? pseudo = Console.ReadLine(); string? pseudo = Console.ReadLine();
if (pseudo != null) if (pseudo != null)
{ {
IPersistence persistence = new DataContractXml(); IPersistence persistence = new DataContractXml();
Player player = new Player(pseudo, "test.png"); Player player = new Player(pseudo, "test.png");
Map map = new Map("Dunai","background"); Map map = new Map("Dunai","background");
Game = new Game(persistence); Game = new Game(persistence);
// Abonnement aux événements // Abonnement aux événements
Game.GameStarted += OnGameStarted!; Game.GameStarted += OnGameStarted!;
Game.GameEnded += OnGameEnded!; Game.GameEnded += OnGameEnded!;
Game.BoardUpdated += OnBoardUpdated!; Game.BoardUpdated += OnBoardUpdated!;
Game.DiceRolled += OnDiceRolled!; Game.DiceRolled += OnDiceRolled!;
Game.OperationChosen += OnOperationChosen!; Game.OperationChosen += OnOperationChosen!;
Game.CellChosen += OnCellChosen!; Game.CellChosen += OnCellChosen!;
Game.PlayerChooseOp += OnPlayerSelectionOp!; Game.PlayerChooseOp += OnPlayerSelectionOp!;
Game.PlayerOption += OnPlayerOption!; Game.PlayerOption += OnPlayerOption!;
Game.PlayerChooseCell += OnPlayerSelectionCell!; Game.PlayerChooseCell += OnPlayerSelectionCell!;
// Initialisation // Initialisation
Game.InitializeGame(map, player); Game.InitializeGame(map, player);
} }
} }
static void OnPlayerSelectionCell(Object sender, PlayerChooseCellEventArgs e) static void OnPlayerSelectionCell(Object sender, PlayerChooseCellEventArgs e)
{ {
int row, column; int row, column;
while (true) while (true)
{ {
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Enter the position of the cell you want to play"); Console.WriteLine("Enter the position of the cell you want to play");
Console.WriteLine("Enter the row number (0-6)"); Console.WriteLine("Enter the row number (0-6)");
Console.ResetColor(); Console.ResetColor();
if (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 7) if (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 7)
{ {
Console.ForegroundColor= ConsoleColor.Red; Console.ForegroundColor= ConsoleColor.Red;
Console.WriteLine("Invalid row number. Please enter a number between 0 and 6."); Console.WriteLine("Invalid row number. Please enter a number between 0 and 6.");
Console.ResetColor(); Console.ResetColor();
continue; continue;
} }
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Enter the column number (0-6)"); Console.WriteLine("Enter the column number (0-6)");
Console.ResetColor(); Console.ResetColor();
if (!int.TryParse(Console.ReadLine(), out column) || column < 0 || column >= 7) if (!int.TryParse(Console.ReadLine(), out column) || column < 0 || column >= 7)
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid column number. Please enter a number between 0 and 6."); Console.WriteLine("Invalid column number. Please enter a number between 0 and 6.");
Console.ResetColor(); Console.ResetColor();
continue; continue;
} }
Game.PlayerCell = new Cell(row, column); Game.PlayerCell = new Cell(row, column);
break; break;
} }
} }
static void OnPlayerOption(object sender, PlayerOptionEventArgs e) static void OnPlayerOption(object sender, PlayerOptionEventArgs e)
{ {
Console.WriteLine(); Console.WriteLine();
if(e.Turn != 1) if(e.Turn != 1)
{ {
IEnumerable<Cell> PlayedCellsQuery = IEnumerable<Cell> PlayedCellsQuery =
from cell in e.Board from cell in e.Board
where cell.Valid == true where cell.Valid == true
where cell.Value != null where cell.Value != null
select cell; select cell;
foreach (var item in e.Board) foreach (var item in e.Board)
{ {
if (item.X == 6) if (item.X == 6)
Console.WriteLine(); Console.WriteLine();
if (!item.Valid) if (!item.Valid)
Console.Write(" "); Console.Write(" ");
else if (item.Value != null) else if (item.Value != null)
Console.Write($"{item.Value}"); Console.Write($"{item.Value}");
else else
{ {
foreach (var item1 in PlayedCellsQuery) foreach (var item1 in PlayedCellsQuery)
{ {
if (Math.Abs(item.X - item1.X) <= 1 && Math.Abs(item.Y - item1.Y) <= 1) if (Math.Abs(item.X - item1.X) <= 1 && Math.Abs(item.Y - item1.Y) <= 1)
{ {
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"{e.Resultat}"); Console.Write($"{e.Resultat}");
Console.ResetColor(); Console.ResetColor();
} }
} }
} }
} }
return; return;
} }
foreach (var item in e.Board) foreach (var item in e.Board)
{ {
if (!item.Valid) if (!item.Valid)
Console.Write(" "); Console.Write(" ");
else else
{ {
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"{e.Resultat}"); Console.Write($"{e.Resultat}");
Console.ResetColor(); Console.ResetColor();
} }
if (item.X == 6) if (item.X == 6)
Console.WriteLine(); Console.WriteLine();
} }
Console.WriteLine(); Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Choose an Available cell."); Console.WriteLine("Choose an Available cell.");
Console.ResetColor(); Console.ResetColor();
} }
static void OnPlayerSelectionOp(object sender, PlayerChooseOperationEventArgs e) static void OnPlayerSelectionOp(object sender, PlayerChooseOperationEventArgs e)
{ {
Console.WriteLine(); Console.WriteLine();
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList()); DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList());
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("0. Lower | 1. Higher | 2. Substraction | 3. Addition | 4. Multiplication"); Console.WriteLine("0. Lower | 1. Higher | 2. Substraction | 3. Addition | 4. Multiplication");
string? op = Console.ReadLine(); string? op = Console.ReadLine();
while (op != "0" && op != "1" && op != "2" && op != "3" && op != "4") while (op != "0" && op != "1" && op != "2" && op != "3" && op != "4")
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid operation. Please choose again."); Console.WriteLine("Invalid operation. Please choose again.");
Console.ResetColor(); Console.ResetColor();
op = Console.ReadLine(); op = Console.ReadLine();
} }
int test = Convert.ToInt32(op); int test = Convert.ToInt32(op);
Game.PlayerOperation = (Operation)test; Game.PlayerOperation = (Operation)test;
} }
/// <summary> /// <summary>
/// Handles the event when the game has started. /// Handles the event when the game has started.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
static void OnGameStarted(object sender, GameStartedEventArgs e) static void OnGameStarted(object sender, GameStartedEventArgs e)
{ {
Console.WriteLine($"The game has started! Player: {e.CurrentPlayer.Pseudo}"); Console.WriteLine($"The game has started! Player: {e.CurrentPlayer.Pseudo}");
} }
/// <summary> /// <summary>
/// Handles the event when the game has ended. /// Handles the event when the game has ended.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
static void OnGameEnded(object sender, GameEndedEventArgs e) static void OnGameEnded(object sender, GameEndedEventArgs e)
{ {
Console.WriteLine($"The game has ended! Player: {e.CurrentPlayer.Pseudo}"); Console.WriteLine($"The game has ended! Player: {e.CurrentPlayer.Pseudo}");
Console.WriteLine($"Points: {e.Point}"); Console.WriteLine($"Points: {e.Point}");
} }
/// <summary> /// <summary>
/// Handles the event when the board is updated. /// Handles the event when the board is updated.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
static void OnBoardUpdated(object sender, BoardsUpdateEventArgs e) static void OnBoardUpdated(object sender, BoardsUpdateEventArgs e)
{ {
foreach (var item in e.Boards) foreach (var item in e.Boards)
{ {
if (!item.Valid) if (!item.Valid)
Console.Write(" "); Console.Write(" ");
else if (item.Value != null) else if (item.Value != null)
Console.Write($"{item.Value}"); Console.Write($"{item.Value}");
else Console.Write("O"); else Console.Write("O");
if (item.X == 6) if (item.X == 6)
Console.WriteLine(); Console.WriteLine();
} }
} }
/// <summary> /// <summary>
/// Handles the event when the dice are rolled. /// Handles the event when the dice are rolled.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
static void OnDiceRolled(object sender, DiceRolledEventArgs e) static void OnDiceRolled(object sender, DiceRolledEventArgs e)
{ {
// Console.Clear(); // Console.Clear();
Console.WriteLine($"Dice 1: {e.Dice1Value} | Dice 2: {e.Dice2Value}"); Console.WriteLine($"Dice 1: {e.Dice1Value} | Dice 2: {e.Dice2Value}");
Console.WriteLine(); Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Choose an operation."); Console.WriteLine("Choose an operation.");
Console.ResetColor(); Console.ResetColor();
} }
/// <summary> /// <summary>
/// Handles the event when an operation is chosen by the player. /// Handles the event when an operation is chosen by the player.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
static void OnOperationChosen(object sender, OperationChosenEventArgs e) static void OnOperationChosen(object sender, OperationChosenEventArgs e)
{ {
Console.WriteLine($"Operation: {e.Operation}, Result: {e.Result}"); Console.WriteLine($"Operation: {e.Operation}, Result: {e.Result}");
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList()); DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList());
Cell playerChoice = GetPlayerChoice(); Cell playerChoice = GetPlayerChoice();
bool test = ((Game)sender).HandlePlayerChoice(playerChoice, e.Result); bool test = ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
if(!test) if(!test)
{ {
Console.WriteLine("Invalid cell. Please choose again."); Console.WriteLine("Invalid cell. Please choose again.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(); Console.WriteLine();
DisplayBoard(((Game)sender).UsedMap); DisplayBoard(((Game)sender).UsedMap);
OnOperationChosen(sender, e); OnOperationChosen(sender, e);
} }
/* /*
try try
{ {
((Game)sender).HandlePlayerChoice(playerChoice, e.Result); ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
} }
catch (InvalidCellCoordinatesException err) catch (InvalidCellCoordinatesException err)
{ {
Console.WriteLine(err.Message); Console.WriteLine(err.Message);
playerChoice = GetPlayerChoice(); playerChoice = GetPlayerChoice();
((Game)sender).HandlePlayerChoice(playerChoice, e.Result); ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
} }
catch (InvalidCellException err) catch (InvalidCellException err)
{ {
Console.WriteLine(err.Message); Console.WriteLine(err.Message);
playerChoice = GetPlayerChoice(); playerChoice = GetPlayerChoice();
((Game)sender).HandlePlayerChoice(playerChoice, e.Result); ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
} }
catch (InvalidPlaceResultException err) catch (InvalidPlaceResultException err)
{ {
Console.WriteLine(err.Message); Console.WriteLine(err.Message);
playerChoice = GetPlayerChoice(); playerChoice = GetPlayerChoice();
((Game)sender).HandlePlayerChoice(playerChoice, e.Result); ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
} }
*/ */
} }
/// <summary> /// <summary>
/// Handles the event when a cell is chosen by the player. /// Handles the event when a cell is chosen by the player.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
static void OnCellChosen(object sender, CellChosenEventArgs e) static void OnCellChosen(object sender, CellChosenEventArgs e)
{ {
Console.WriteLine($"Cell chosen: ({e.Cell.X}, {e.Cell.Y}) with result: {e.Result}"); Console.WriteLine($"Cell chosen: ({e.Cell.X}, {e.Cell.Y}) with result: {e.Result}");
DisplayBoard(((Game)sender).UsedMap); DisplayBoard(((Game)sender).UsedMap);
} }
/// <summary> /// <summary>
/// Displays the game board. /// Displays the game board.
/// </summary> /// </summary>
/// <param name="map">Used map to display</param> /// <param name="map">Used map to display</param>
static void DisplayBoard(Map map) static void DisplayBoard(Map map)
{ {
int cpt = 0; int cpt = 0;
for (int i = 0; i < map.Boards.Count; i++) for (int i = 0; i < map.Boards.Count; i++)
{ {
if (cpt % 6 == 0) if (cpt % 6 == 0)
{ {
Console.Write("| "); Console.Write("| ");
} }
if (map.Boards[i].Value.HasValue) if (map.Boards[i].Value.HasValue)
{ {
Console.Write(map.Boards[i].Value?.ToString().PadLeft(2)); Console.Write(map.Boards[i].Value?.ToString().PadLeft(2));
} }
else else
{ {
Console.Write(" O"); Console.Write(" O");
} }
cpt++; cpt++;
if (cpt % 6 == 0) if (cpt % 6 == 0)
{ {
Console.Write(" |"); Console.Write(" |");
Console.WriteLine(); Console.WriteLine();
} }
} }
} }
/// <summary> /// <summary>
/// Displays the operation table. /// Displays the operation table.
/// </summary> /// </summary>
/// <param name="operationTable">The operation table to display.</param> /// <param name="operationTable">The operation table to display.</param>
static void DisplayOperationTable(List<OperationCell> operationTable) static void DisplayOperationTable(List<OperationCell> operationTable)
{ {
Console.ForegroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Yellow;
foreach ( var cell in operationTable) foreach ( var cell in operationTable)
{ {
if (cell.X == 0 && cell.Y == 0) if (cell.X == 0 && cell.Y == 0)
Console.Write("Lower => "); Console.Write("Lower => ");
if (cell.X == 0 && cell.Y == 1) if (cell.X == 0 && cell.Y == 1)
Console.Write("Higher => "); Console.Write("Higher => ");
if (cell.X == 0 && cell.Y == 2) if (cell.X == 0 && cell.Y == 2)
Console.Write("Substraction => "); Console.Write("Substraction => ");
if (cell.X == 0 && cell.Y == 3) if (cell.X == 0 && cell.Y == 3)
Console.Write("Addition => "); Console.Write("Addition => ");
if (cell.X == 0 && cell.Y == 4) if (cell.X == 0 && cell.Y == 4)
Console.Write("Multiplication => "); Console.Write("Multiplication => ");
if (cell.IsChecked) if (cell.IsChecked)
Console.Write("X | "); Console.Write("X | ");
if (!cell.IsChecked) if (!cell.IsChecked)
Console.Write(" | "); Console.Write(" | ");
if (cell.X == 3) if (cell.X == 3)
Console.WriteLine(); Console.WriteLine();
} }
Console.ResetColor(); Console.ResetColor();
} }
/// <summary> /// <summary>
/// Gets the cell chosen by the player. /// Gets the cell chosen by the player.
/// </summary> /// </summary>
/// <returns>The cell chosen by the player.</returns> /// <returns>The cell chosen by the player.</returns>
static Cell GetPlayerChoice() static Cell GetPlayerChoice()
{ {
int row, column; int row, column;
while (true) while (true)
{ {
Console.WriteLine("Enter the position of the cell you want to play"); Console.WriteLine("Enter the position of the cell you want to play");
Console.WriteLine("Enter the row number (0-5)"); Console.WriteLine("Enter the row number (0-5)");
if (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 6) if (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 6)
{ {
Console.WriteLine("Invalid row number. Please enter a number between 0 and 5."); Console.WriteLine("Invalid row number. Please enter a number between 0 and 5.");
continue; continue;
} }
Console.WriteLine("Enter the column number (0-5)"); Console.WriteLine("Enter the column number (0-5)");
if (!int.TryParse(Console.ReadLine(), out column) || column < 0 || column >= 6) if (!int.TryParse(Console.ReadLine(), out column) || column < 0 || column >= 6)
{ {
Console.WriteLine("Invalid column number. Please enter a number between 0 and 5."); Console.WriteLine("Invalid column number. Please enter a number between 0 and 5.");
continue; continue;
} }
return new Cell(row, column); return new Cell(row, column);
} }
} }
/// <summary> /// <summary>
/// Gets the operation chosen by the player. /// Gets the operation chosen by the player.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception>
static Operation GetPlayerOperation(object? sender) static Operation GetPlayerOperation(object? sender)
{ {
DisplayOperationOptions(); DisplayOperationOptions();
string? op = Console.ReadLine(); string? op = Console.ReadLine();
while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5") while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5")
{ {
Console.WriteLine("Invalid operation. Please choose again."); Console.WriteLine("Invalid operation. Please choose again.");
op = Console.ReadLine(); op = Console.ReadLine();
} }
int test = Convert.ToInt32(op); int test = Convert.ToInt32(op);
while(((Game)sender).UsedMap.CheckOperationPossible(test-1)) while(((Game)sender).UsedMap.CheckOperationPossible(test-1))
{ {
Console.WriteLine("Invalid operation. Please choose again."); Console.WriteLine("Invalid operation. Please choose again.");
Console.WriteLine(); Console.WriteLine();
op = Console.ReadLine(); op = Console.ReadLine();
while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5") while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5")
{ {
Console.WriteLine("Invalid operation. Please choose again."); Console.WriteLine("Invalid operation. Please choose again.");
op = Console.ReadLine(); op = Console.ReadLine();
} }
test = Convert.ToInt32(op); test = Convert.ToInt32(op);
} }
return op switch return op switch
{ {
"1" => Operation.ADDITION, "1" => Operation.ADDITION,
"2" => Operation.SUBTRACTION, "2" => Operation.SUBTRACTION,
"3" => Operation.MULTIPLICATION, "3" => Operation.MULTIPLICATION,
"4" => Operation.LOWER, "4" => Operation.LOWER,
"5" => Operation.HIGHER, "5" => Operation.HIGHER,
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
} }
/// <summary> /// <summary>
/// Displays the operation options for the player to choose from. /// Displays the operation options for the player to choose from.
/// </summary> /// </summary>
static void DisplayOperationOptions() static void DisplayOperationOptions()
{ {
Console.WriteLine("Choose an operation:"); Console.WriteLine("Choose an operation:");
Console.WriteLine("1: Addition (+)"); Console.WriteLine("1: Addition (+)");
Console.WriteLine("2: Subtraction (-)"); Console.WriteLine("2: Subtraction (-)");
Console.WriteLine("3: Multiplication (*)"); Console.WriteLine("3: Multiplication (*)");
Console.WriteLine("4: Lower Dice (less)"); Console.WriteLine("4: Lower Dice (less)");
Console.WriteLine("5: Higher Dice (high)"); Console.WriteLine("5: Higher Dice (high)");
} }
} }

@ -317,7 +317,7 @@ namespace Models.Game
/// </summary> /// </summary>
/// <param name="playerChoice">The cell chosen by the player to place the result.</param> /// <param name="playerChoice">The cell chosen by the player to place the result.</param>
/// <param name="result">The result of the dice operation to be placed in the cell.</param> /// <param name="result">The result of the dice operation to be placed in the cell.</param>
private void PlaceResult(Cell playerChoice, int result) private void PlaceResult(Cell playerChoice)
{ {
IEnumerable<Cell> ValidCell = IEnumerable<Cell> ValidCell =
from cell in UsedMap.Boards from cell in UsedMap.Boards
@ -326,8 +326,11 @@ namespace Models.Game
select cell; select cell;
foreach (var item in ValidCell) foreach (var item in ValidCell)
{ {
if(item.X == playerChoice.X && item.Y == playerChoice.Y) if (item.X == playerChoice.X && item.Y == playerChoice.Y)
item.Value = result; {
item.Value = PlayerCell.Value;
return;
}
} }
} }
@ -336,36 +339,33 @@ namespace Models.Game
/// </summary> /// </summary>
/// <param name="playerChoice"></param> /// <param name="playerChoice"></param>
/// <param name="adjacentes"></param> /// <param name="adjacentes"></param>
private void AddToRopePath(Cell playerChoice,List<Cell> adjacentes) private void AddToRopePath(Cell playerChoice,List<Cell> board)
{ {
int index =0;
foreach (var cells in adjacentes.Where(cells => cells.Value - playerChoice.Value == 1 || cells.Value - playerChoice.Value == -1))
{
// Le cas si il n'existe aucun chemin de corde
if (UsedMap.RopePaths.Count == 0)
{
// Creer un nouveau chemin de corde avec la cellule choisi par le joueur et celle adjacente
UsedMap.RopePaths.Add(new List<Cell> {playerChoice, cells});
}
// A modifier dans le cas ou il est possible de fusionner deux chemins de corde if(Turn==1) return;
if (GameRules.IsInRopePaths(playerChoice, UsedMap.RopePaths, index)) break; int index = 0;
// Le cas si il existe des chemins de corde IEnumerable<Cell> ValidCell =
from cell in UsedMap.Boards
where cell.Value != null && cell.Valid == true && cell != playerChoice
select cell;
// Est-ce que la cellule adjacentes fait parti d'un chemin de corde foreach (var item in ValidCell)
if (!GameRules.IsInRopePaths(cells,UsedMap.RopePaths,index)) {
if (!GameRules.IsCellAdjacent(playerChoice, item))
continue;
if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1))
continue;
if (!GameRules.IsInRopePaths(item,UsedMap.RopePaths,index))
{ {
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, cells }); UsedMap.RopePaths.Add(new List<Cell> { playerChoice, item });
continue; return;
} }
if (!GameRules.AsValue(playerChoice, UsedMap.RopePaths, index))
if (!GameRules.AsValue(playerChoice,UsedMap.RopePaths,index))
{ {
UsedMap.RopePaths[index].Add(playerChoice); UsedMap.RopePaths[index].Add(playerChoice);
} return;
}
} }
} }
@ -410,17 +410,17 @@ namespace Models.Game
/// </summary> /// </summary>
private void GameLoop() private void GameLoop()
{ {
int res = 0,turn = 1;
Cell cell;
while (IsRunning) while (IsRunning)
{ {
RollAllDice(); RollAllDice();
res = PlayerChooseOperation(); int res = PlayerChooseOperation();
PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn)); PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,Turn));
PlayerSelectionCell(); PlayerSelectionCell();
PlaceResult(PlayerCell,res); PlayerCell.Value = res;
AddToRopePath(PlayerCell,UsedMap.Boards.ToList());
PlaceResult(PlayerCell);
BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList()));
turn++; Turn++;
} }
} }

@ -87,28 +87,23 @@ public partial class PageBoard : ContentPage
private void HigherClicked(object sender, EventArgs e) private void HigherClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.HIGHER);
Higher.IsVisible = false; Higher.IsVisible = false;
} }
private void LowerClicked(object sender, EventArgs e) private void LowerClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.LOWER);
} }
private void AdditionClicked(object sender, EventArgs e) private void AdditionClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.ADDITION);
} }
private void SubstractionClicked(object sender, EventArgs e) private void SubstractionClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.SUBTRACTION);
} }
private void MultiplicationClicked(object sender, EventArgs e) private void MultiplicationClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.MULTIPLICATION);
} }
private void DiceButton_Clicked(object sender, EventArgs e) private void DiceButton_Clicked(object sender, EventArgs e)

Loading…
Cancel
Save