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

master
Jules LASCRET 11 months ago
parent 317dbeaa83
commit ecfcc1cb37

@ -552,48 +552,57 @@ namespace QwirkleClassLibrary.Games
return false;
}
public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List<Tile> checkdoubles)
public static bool CheckTileInCompletedLines(Tile? t1, Tile? t2, ref int nbTiles, ref List<Tile> checkdoubles)
{
int nbTiles = 1;
for (int i = 1; i < 7; i++)
if (t1 != null)
{
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
var extendedCell2 = b.GetCell(x - i * dx, y - i * dy);
nbTiles++;
if (extendedCell?.Tile == null && extendedCell2?.Tile == null)
if (checkdoubles.Any(t => t.CompareTo(t1) == 0))
{
break;
return false;
}
checkdoubles.Add(t1);
}
if (extendedCell?.Tile != null)
if (t2 == null) return true;
{
nbTiles++;
if(checkdoubles.Any(t => t.CompareTo(extendedCell.Tile) == 0))
if (checkdoubles.Any(t => t.CompareTo(t2) == 0))
{
return false;
}
checkdoubles.Add(extendedCell.Tile);
checkdoubles.Add(t2);
}
if (extendedCell2?.Tile == null) continue;
return true;
}
public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List<Tile> checkdoubles)
{
nbTiles++;
int nbTiles = 1;
if (checkdoubles.Any(t => t.CompareTo(extendedCell2.Tile) == 0))
for (int i = 1; i < 7; i++)
{
return false;
}
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
var extendedCell2 = b.GetCell(x - i * dx, y - i * dy);
checkdoubles.Add(extendedCell2.Tile);
if (extendedCell?.Tile == null && extendedCell2?.Tile == null)
{
break;
}
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>
@ -655,12 +664,10 @@ namespace QwirkleClassLibrary.Games
return false;
}
if (!CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles))
{
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;
}
}
if (!CheckTilesInLine(cellUsed, b, x, y))

Loading…
Cancel
Save