Utilisation de LINQ. Amélioration de la sécurité (visibilité et static). Factorisation et réduction d'imbrication du code.
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/pr Build is failing Details

pull/57/head
Rémi LAVERGNE 12 months ago
parent 96dee898ad
commit 619cdaf3cc
No known key found for this signature in database
GPG Key ID: CA264B55E97FD220

@ -8,107 +8,83 @@ namespace Models.Rules
{
public class Rules
{
public bool NearCell(Cell playerChoice, List<Cell> cells)
public static bool NearCell(Cell playerChoice, List<Cell> cells)
{
foreach (var item in cells)
{
if(playerChoice.Pos.X == item.Pos.X +1 || playerChoice.Pos.X == item.Pos.X - 1
|| playerChoice.Pos.Y == item.Pos.Y +1 || playerChoice.Pos.Y == item.Pos.Y -1 )
{
return true;
}
}
return false;
return cells.Any(item => playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1);
}
public bool IsCellEmpty(Cell playerChoice)
public static bool IsCellEmpty(Cell playerChoice)
{
if (playerChoice.Value == null)
{
return true;
}
return false;
return playerChoice.Value == null;
}
public bool IsCellValid(Cell playerChoice, List<Cell> cells)
public static bool IsCellValid(Cell playerChoice, List<Cell> cells)
{
if (NearCell(playerChoice, cells) && IsCellEmpty(playerChoice))
{
return true;
}
return false;
return NearCell(playerChoice, cells) && IsCellEmpty(playerChoice);
}
public bool IsZone(Cell playerChoice, List<Cell> cells)
public static bool IsZone(Cell playerChoice, List<Cell> cells)
{
foreach (var item in cells)
{
if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1
|| playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1)
if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
if (playerChoice.Value == item.Value)
{
if (playerChoice.Value == item.Value)
{
return true;
}
return true;
}
}
return false;
}
public bool IsCheminDeCorde(Cell playerChoice, List<Cell> cells, List<Cell> cheminsDeCorde)
public static bool IsRopePath(Cell playerChoice, List<Cell> cells, List<Cell> ropePaths)
{
foreach (var item in cells)
{
if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1
|| playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1)
if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
if (playerChoice.Value != item.Value + 1 && playerChoice.Value != item.Value - 1) continue;
foreach (var path in ropePaths)
{
if (playerChoice.Value == item.Value+1 || playerChoice.Value == item.Value-1)
if (path.Equals(playerChoice))
{
foreach (var chemin in cheminsDeCorde)
{
if (chemin.Equals(playerChoice))
{
return true;
}
}
return IsCheminDeCorde(item, cells, cheminsDeCorde);
return true;
}
}
return IsRopePath(item, cells, ropePaths);
}
return false;
}
public int HowMany(Cell playerChoice, List<Cell> cells)
public static int HowMany(Cell playerChoice, List<Cell> cells)
{
foreach(var pos in cells)
{
if (pos.Equals(playerChoice))
{
if (pos.GetCellType())
{
return 6;
}
return 12;
return pos.GetCellType() ? 6 : 12;
}
}
return 0;
}
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Cell> cells)
public static void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Cell> cells)
{
int val = HowMany(playerChoice, cells);
foreach (var pos in cells)
{
if (pos.Equals(playerChoice))
if (!pos.Equals(playerChoice)) continue;
if (valueChoice > val)
{
if (valueChoice > val)
{
playerChoice.Background = "notcontent";
}
playerChoice.Value = valueChoice;
playerChoice.Background = "penalty";
}
playerChoice.Value = valueChoice;
}
}
}

Loading…
Cancel
Save