diff --git a/source/Trek-12/Models/Game/Map.cs b/source/Trek-12/Models/Game/Map.cs index 737e0b2..cfb2956 100644 --- a/source/Trek-12/Models/Game/Map.cs +++ b/source/Trek-12/Models/Game/Map.cs @@ -23,7 +23,8 @@ namespace Models.Game [DataMember] [Ignore] public ReadOnlyObservableCollection Boards { get; private set; } - ObservableCollection board = new ObservableCollection(); + + private readonly ObservableCollection _board = new ObservableCollection(); /// /// It is the backgrond image of the map @@ -36,7 +37,8 @@ namespace Models.Game /// [DataMember] public ReadOnlyObservableCollection OperationGrid { get; private set; } - ObservableCollection operationGrid = new ObservableCollection(); + + private readonly ObservableCollection _operationGrid = new ObservableCollection(); /// /// It is a list of a list containing user's rope paths in the current game @@ -53,15 +55,16 @@ namespace Models.Game /// /// Initializes a new instance of the Map class. /// + /// /// The background of the map. public Map(string name, string background) { Name = name; Background = background; - Boards = new ReadOnlyObservableCollection(board); - InitializeBoards(board); - OperationGrid = new ReadOnlyObservableCollection(operationGrid); - InitializeOperationGrid(operationGrid); + Boards = new ReadOnlyObservableCollection(_board); + InitializeBoards(_board); + OperationGrid = new ReadOnlyObservableCollection(_operationGrid); + InitializeOperationGrid(_operationGrid); RopePaths = new List>(); Zones = new List>(); } @@ -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)); } } } \ No newline at end of file diff --git a/source/Trek-12/Tests/MapTests.cs b/source/Trek-12/Tests/MapTests.cs index 9bfa3e2..9858d86 100644 --- a/source/Trek-12/Tests/MapTests.cs +++ b/source/Trek-12/Tests/MapTests.cs @@ -92,6 +92,17 @@ public class MapTests var paths = new List { 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); } }