Un truc de plus fonctionne

pull/87/head
Remi NEVEU 11 months ago
parent 9fae1d2702
commit fd019fb45a

@ -0,0 +1,17 @@
using Models.Game;
namespace Models.Events
{
/// <summary>
/// Event arguments for when the board change.
/// </summary>
public class BoardsUpdateEventArgs : EventArgs
{
public List<Cell> Boards { get; }
public BoardsUpdateEventArgs(List<Cell> board)
{
Boards = board;
}
}
}

@ -32,7 +32,7 @@ namespace Models.Game
// == Events ==
public event EventHandler<GameStartedEventArgs> GameStarted;
public event EventHandler<GameEndedEventArgs> GameEnded;
public event EventHandler BoardUpdated;
public event EventHandler<BoardsUpdateEventArgs> BoardUpdated;
public event EventHandler<DiceRolledEventArgs> DiceRolled;
public event EventHandler<OperationChosenEventArgs> OperationChosen;
public event EventHandler<CellChosenEventArgs> CellChosen;
@ -121,8 +121,16 @@ namespace Models.Game
{
if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards))
{
for (int i = 0; i < UsedMap.Boards.Count; i++)
{
if (UsedMap.Boards[i].X == playerChoice.X && UsedMap.Boards[i].Y == playerChoice.Y)
{
UsedMap.Boards[i].Value = result;
break;
}
}
playerChoice.Value = result;
BoardUpdated?.Invoke(this, EventArgs.Empty);
BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards));
}
}
@ -235,7 +243,7 @@ namespace Models.Game
GameRules.IsZoneValidAndAddToZones(cell, UsedMap);
AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards));
CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result));
BoardUpdated?.Invoke(this, EventArgs.Empty);
//BoardUpdated?.Invoke(this, EventArgs.Empty);
}
}
}

@ -29,26 +29,40 @@ namespace Models.Rules
return true;
}
//public bool IsCellAdjacent(Cell choosenCell, Cell targetCell)
//{
// if (Math.Abs(choosenCell.X - targetCell.X) > 1 || Math.Abs(choosenCell.Y - targetCell.Y) > 1)
// return false;
// if (Math.Abs(choosenCell.X - targetCell.X) > 1 && Math.Abs(choosenCell.Y - targetCell.Y) > 1)
// return false;
// if (choosenCell.X == 0 && targetCell.X == 4)
// return false;
// if (choosenCell.Y == 0 && targetCell.Y == 4)
// return false;
// if (choosenCell.X == 4 && targetCell.X == 0)
// return false;
// if (choosenCell.Y == 4 && targetCell.Y == 0)
// return false;
// if (choosenCell.X == targetCell.X && choosenCell.Y == targetCell.Y)
// return false;
// return true;
//}
public bool IsCellAdjacent(Cell choosenCell, Cell targetCell)
{
if (Math.Abs(choosenCell.X - targetCell.X) > 1 || Math.Abs(choosenCell.Y - targetCell.Y) > 1)
return false;
if (Math.Abs(choosenCell.X - targetCell.X) > 1 && Math.Abs(choosenCell.Y - targetCell.Y) > 1)
return false;
if (choosenCell.X == 0 && targetCell.X == 4)
return false;
if (choosenCell.Y == 0 && targetCell.Y == 4)
return false;
if (choosenCell.X == 4 && targetCell.X == 0)
return false;
if (choosenCell.Y == 4 && targetCell.Y == 0)
return false;
if (choosenCell.X == targetCell.X && choosenCell.Y == targetCell.Y)
return false;
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 true;
return false;
}
public bool IsInRopePaths (Cell adjacente,List<List<Cell>> ropePaths,int index)
{
foreach (List<Cell> path in ropePaths)
@ -70,6 +84,25 @@ namespace Models.Rules
}
return false;
}
//public bool NearCellIsValid(Cell choosenCell, List<Cell> cells)
//{
// if (choosenCell == null || cells == null) return false;
// IEnumerable<Cell> PlayedCellsQuery =
// from cell in cells
// where cell.Value != null
// select cell;
// foreach (var cell in PlayedCellsQuery)
// {
// if(!IsCellAdjacent(choosenCell, cell)) continue;
// return true;
// }
// return false;
//}
public bool NearCellIsValid(Cell choosenCell, List<Cell> cells)
{
if (choosenCell == null || cells == null) return false;
@ -81,14 +114,16 @@ namespace Models.Rules
foreach (var cell in PlayedCellsQuery)
{
if(!IsCellAdjacent(choosenCell, cell)) continue;
return true;
if (IsCellAdjacent(choosenCell, cell))
{
return true;
}
}
return false;
}
public void IsZoneValidAndAddToZones(Cell chosenCell, Map map)
{
if (chosenCell == null ||chosenCell.Value == null) return;

Loading…
Cancel
Save