Code Smells de Map.cs
continuous-integration/drone/push Build is passing Details

pull/112/head
Rémi LAVERGNE 11 months ago
parent 170e5c5a66
commit cd2c35c481

@ -23,7 +23,8 @@ namespace Models.Game
[DataMember]
[Ignore]
public ReadOnlyObservableCollection<Cell> Boards { get; private set; }
ObservableCollection<Cell> board = new ObservableCollection<Cell>();
private readonly ObservableCollection<Cell> _board = new ObservableCollection<Cell>();
/// <summary>
/// It is the backgrond image of the map
@ -36,7 +37,8 @@ namespace Models.Game
/// </summary>
[DataMember]
public ReadOnlyObservableCollection<OperationCell> OperationGrid { get; private set; }
ObservableCollection<OperationCell> operationGrid = new ObservableCollection<OperationCell>();
private readonly ObservableCollection<OperationCell> _operationGrid = new ObservableCollection<OperationCell>();
/// <summary>
/// It is a list of a list containing user's rope paths in the current game
@ -53,15 +55,16 @@ namespace Models.Game
/// <summary>
/// Initializes a new instance of the Map class.
/// </summary>
/// <param name="name"></param>
/// <param name="background">The background of the map.</param>
public Map(string name, string background)
{
Name = name;
Background = background;
Boards = new ReadOnlyObservableCollection<Cell>(board);
InitializeBoards(board);
OperationGrid = new ReadOnlyObservableCollection<OperationCell>(operationGrid);
InitializeOperationGrid(operationGrid);
Boards = new ReadOnlyObservableCollection<Cell>(_board);
InitializeBoards(_board);
OperationGrid = new ReadOnlyObservableCollection<OperationCell>(_operationGrid);
InitializeOperationGrid(_operationGrid);
RopePaths = new List<List<Cell>>();
Zones = new List<List<Cell>>();
}
@ -138,26 +141,12 @@ namespace Models.Game
public bool IsCellInZones(Cell cell)
{
foreach (var zone in Zones)
{
if (zone.Contains(cell))
{
return true;
}
}
return false;
return Zones.Any(zone => zone.Contains(cell));
}
public bool IsCellInRopePath(Cell cell)
{
foreach (var path in RopePaths)
{
if (path.Contains(cell))
{
return true;
}
}
return false;
return RopePaths.Any(path => path.Contains(cell));
}
}
}

@ -92,6 +92,17 @@ public class MapTests
var paths = new List<Cell> { cell };
map.RopePaths.Add(paths);
Assert.False(map.IsCellInRopePath(othercell));
}
[Fact]
public void Clone_ReturnsNewMap()
{
var map = new Map("test_name", "test_background.png");
var clone = map.Clone();
Assert.NotEqual(map, clone);
Assert.Equal(map.Name, clone.Name);
Assert.Equal(map.Background, clone.Background);
}
}

Loading…
Cancel
Save