regles des chemins de corde #64

Merged
remi.neveu merged 1 commits from regleCheminCorde into dev 12 months ago

@ -1,6 +1,6 @@
namespace Models; namespace Models;
public class Cell : Position public class Cell : Position, IEquatable<Cell>
{ {
private int? _value; private int? _value;
public int? Value { public int? Value {
@ -26,4 +26,11 @@ public class Cell : Position
} }
public bool GetCellType() => IsDangerous; public bool GetCellType() => IsDangerous;
public bool Equals(Cell? other)
{
if (other == null) return false;
if (this.X == other.X && this.Y == other.Y) return true;
return false;
}
} }

@ -88,38 +88,48 @@ namespace Models.Game
} }
} }
public void AddToRopePath(Cell playerChoice, List<List<Cell>> ropePaths,Cell adjacente) public void AddToRopePath(Cell playerChoice,List<Cell> adjacentes)
{ {
int index =0;
List<List<Cell>> possiblePaths; foreach (var cells in adjacentes)
{
// {adjacentes} ne doit pas etre egale a {playerChoice} // La cellule choisi peut creer/s'ajouter a un chemin de corde
if (adjacente.Value == playerChoice.Value) return; if (cells.Value - playerChoice.Value == 1 || cells.Value - playerChoice.Value == -1)
// {adjacentes} doit etre croissant ou decroissant
if ((adjacente.Value - playerChoice.Value > 1) || (adjacente.Value - playerChoice.Value < -1)) return;
// Un nombre ne peut appartenir qu'a un seul chemin de corde
foreach (List<Cell> paths in ropePaths)
{
foreach (var cells in paths)
{ {
if (adjacente.X == cells.X && adjacente.Y == adjacente.Y) // Le cas si il n'existe aucun chemin de corde
if (UsedMap.RopePaths.Count == 0)
{ {
possiblePaths.Add(paths); // 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 (GameRules.IsInRopePaths(playerChoice, UsedMap.RopePaths, index)) break;
} // Le cas si il existe des chemins de corde
// Est-ce que la cellule adjacentes fait parti d'un chemin de corde
if (!GameRules.IsInRopePaths(cells,UsedMap.RopePaths,index))
{
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, cells });
continue;
}
// Si {ropePaths} est vide, il faut alors creer un chemin de corde entre {playerChoice} if (!GameRules.AsValue(playerChoice,UsedMap.RopePaths,index))
if (ropePaths.Count == 0) {
{ UsedMap.RopePaths[index].Add(playerChoice);
}
// Si oui, est-ce que le chemin possede deja la valeur correspondante a la valeur de la cellule du joueur choisi
// {playerChoice.Value} n'est pas dans le chemin de corde
// Ajouter au chemin
// {playerChoice.Value} existe dans le chemin de corde pas possible
}
} }
} }
/// <summary> /// <summary>

@ -36,4 +36,8 @@ public interface IRules
public int? FinalCalculusOfZones(List<List<Cell>> zones); public int? FinalCalculusOfZones(List<List<Cell>> zones);
public bool IsInRopePaths(Cell adjacente, List<List<Cell>> ropePaths, int index);
public bool AsValue(Cell choosenCell, List<List<Cell>> ropePaths, int index);
} }

@ -18,13 +18,29 @@ namespace Models.Rules
return false; return false;
return true; return true;
}
public bool IsInRopePaths (Cell adjacente,List<List<Cell>> ropePaths,int index)
{
foreach (List<Cell> path in ropePaths)
{
if (path.Contains(adjacente))
{
index=ropePaths.IndexOf(path);
return true;
}
}
return false;
} }
public bool ropePathCellIsValid (Cell choosenCell, Cell targetCell) public bool AsValue (Cell choosenCell, List<List<Cell>> ropePaths,int index)
{ {
if (Math.Abs(choosenCell.Value - targetCell.Value ) foreach (var item in ropePaths[index])
{
if (choosenCell.Value == item.Value) return true;
}
return false;
} }
public bool NearCellIsValid(Cell choosenCell, List<Cell> cells) public bool NearCellIsValid(Cell choosenCell, List<Cell> cells)
{ {
if (choosenCell == null || cells == null) return false; if (choosenCell == null || cells == null) return false;

Loading…
Cancel
Save