Je réécris encore le code de l'autre Rémi
continuous-integration/drone/push Build is passing Details

pull/87/head
Remi NEVEU 11 months ago
parent fd019fb45a
commit 8cc8435b3f

@ -90,6 +90,19 @@ class Program
Console.WriteLine($"Operation: {e.Operation}, Result: {e.Result}"); Console.WriteLine($"Operation: {e.Operation}, Result: {e.Result}");
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid); DisplayOperationTable(((Game)sender).UsedMap.OperationGrid);
Cell playerChoice = GetPlayerChoice(); Cell playerChoice = GetPlayerChoice();
bool test = ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
if(!test)
{
Console.WriteLine("Invalid cell. Please choose again.");
Console.WriteLine();
Console.WriteLine();
DisplayBoard(((Game)sender).UsedMap);
OnOperationChosen(sender, e);
}
/*
try try
{ {
((Game)sender).HandlePlayerChoice(playerChoice, e.Result); ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
@ -106,6 +119,13 @@ class Program
playerChoice = GetPlayerChoice(); playerChoice = GetPlayerChoice();
((Game)sender).HandlePlayerChoice(playerChoice, e.Result); ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
} }
catch (InvalidPlaceResultException err)
{
Console.WriteLine(err.Message);
playerChoice = GetPlayerChoice();
((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
}
*/
} }
/// <summary> /// <summary>

@ -0,0 +1,11 @@
namespace Models.Exceptions
{
/// <summary>
/// Exception for when the cell is invalid.
/// </summary>
public class InvalidPlaceResultException : Exception
{
public InvalidPlaceResultException(string message) : base(message) { }
}
}

@ -117,7 +117,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 bool PlaceResult(Cell playerChoice, int result)
{ {
if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards)) if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards))
{ {
@ -125,13 +125,17 @@ namespace Models.Game
{ {
if (UsedMap.Boards[i].X == playerChoice.X && UsedMap.Boards[i].Y == playerChoice.Y) 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; UsedMap.Boards[i].Value = result;
break; BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards));
return true;
} }
} }
playerChoice.Value = result; //playerChoice.Value = result;
BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards));
} }
return false;
} }
/// <summary> /// <summary>
@ -227,22 +231,30 @@ namespace Models.Game
/// <param name="result"></param> /// <param name="result"></param>
/// <exception cref="InvalidCellCoordinatesException"></exception> /// <exception cref="InvalidCellCoordinatesException"></exception>
/// <exception cref="InvalidCellException"></exception> /// <exception cref="InvalidCellException"></exception>
public void HandlePlayerChoice(Cell cell, int result) public bool HandlePlayerChoice(Cell cell, int result)
{ {
if (cell.X < 0 || cell.X >= UsedMap.Boards.Count / 6 || cell.Y < 0 || cell.Y >= 6) if (cell.X < 0 || cell.X >= UsedMap.Boards.Count / 6 || cell.Y < 0 || cell.Y >= 6)
{ {
throw new InvalidCellCoordinatesException("Invalid cell coordinates. Please choose again."); return false;
//throw new InvalidCellCoordinatesException("Invalid cell coordinates. Please choose again.");
} }
if (!GameRules.IsCellValid(cell, UsedMap.Boards)) if (!GameRules.IsCellValid(cell, UsedMap.Boards))
{ {
throw new InvalidCellException("Cell is not valid. Please choose again."); return false;
//throw new InvalidCellException("Cell is not valid. Please choose again.");
} }
PlaceResult(cell, result); bool res = PlaceResult(cell, result);
if (!res)
{
return false;
//throw new InvalidPlaceResultException("Cell is not valid for place result. Please choose again.");
}
GameRules.IsZoneValidAndAddToZones(cell, UsedMap); GameRules.IsZoneValidAndAddToZones(cell, UsedMap);
AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards)); AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards));
CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result)); CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result));
return true;
//BoardUpdated?.Invoke(this, EventArgs.Empty); //BoardUpdated?.Invoke(this, EventArgs.Empty);
} }
} }

Loading…
Cancel
Save