Fix 1 minor code smell (normally)
continuous-integration/drone/push Build is passing Details

master
Jules LASCRET 11 months ago
parent 317dbeaa83
commit ecfcc1cb37

@ -551,6 +551,35 @@ namespace QwirkleClassLibrary.Games
return false;
}
public static bool CheckTileInCompletedLines(Tile? t1, Tile? t2, ref int nbTiles, ref List<Tile> checkdoubles)
{
if (t1 != null)
{
nbTiles++;
if (checkdoubles.Any(t => t.CompareTo(t1) == 0))
{
return false;
}
checkdoubles.Add(t1);
}
if (t2 == null) return true;
{
nbTiles++;
if (checkdoubles.Any(t => t.CompareTo(t2) == 0))
{
return false;
}
checkdoubles.Add(t2);
}
return true;
}
public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List<Tile> checkdoubles)
{
@ -566,34 +595,14 @@ namespace QwirkleClassLibrary.Games
break;
}
if (extendedCell?.Tile != null)
{
nbTiles++;
if(checkdoubles.Any(t => t.CompareTo(extendedCell.Tile) == 0))
{
return false;
}
checkdoubles.Add(extendedCell.Tile);
}
if (extendedCell2?.Tile == null) continue;
{
nbTiles++;
if (checkdoubles.Any(t => t.CompareTo(extendedCell2.Tile) == 0))
{
return false;
}
checkdoubles.Add(extendedCell2.Tile);
}
return CheckTileInCompletedLines(extendedCell?.Tile, extendedCell2?.Tile, ref nbTiles, ref checkdoubles);
}
return nbTiles <= 6;
}
/// <summary>
/// Main method to check if the move the player is trying to make is correct
/// </summary>
@ -654,12 +663,10 @@ namespace QwirkleClassLibrary.Games
{
return false;
}
if (!CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles))
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)"));
return false;
}
if (CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles)) continue;
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)"));
return false;
}

Loading…
Cancel
Save