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,6 +552,35 @@ namespace QwirkleClassLibrary.Games
return false; 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) public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List<Tile> checkdoubles)
{ {
int nbTiles = 1; int nbTiles = 1;
@ -566,34 +595,14 @@ namespace QwirkleClassLibrary.Games
break; break;
} }
if (extendedCell?.Tile != null) return CheckTileInCompletedLines(extendedCell?.Tile, extendedCell2?.Tile, ref nbTiles, ref checkdoubles);
{
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 nbTiles <= 6; return nbTiles <= 6;
} }
/// <summary> /// <summary>
/// Main method to check if the move the player is trying to make is correct /// Main method to check if the move the player is trying to make is correct
/// </summary> /// </summary>
@ -655,11 +664,9 @@ namespace QwirkleClassLibrary.Games
return false; 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)"));
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)")); return false;
return false;
}
} }

Loading…
Cancel
Save