You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
5.0 KiB
156 lines
5.0 KiB
using System.Collections.ObjectModel;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace Models.Game
|
|
{
|
|
|
|
/// <summary>
|
|
/// The Map class is the representation of the game map with the board and the operations table.
|
|
/// </summary>
|
|
[DataContract]
|
|
public class Map
|
|
{
|
|
/// <summary>
|
|
/// It is the list of cells on the map.
|
|
/// </summary>
|
|
[DataMember]
|
|
public ReadOnlyObservableCollection<Cell> Boards { get; private set; }
|
|
ObservableCollection<Cell> board = new ObservableCollection<Cell>();
|
|
|
|
/// <summary>
|
|
/// The displaying name of the map
|
|
/// </summary>
|
|
[DataMember]
|
|
public string Name { get; private set; }
|
|
|
|
/// <summary>
|
|
/// It is the backgrond image of the map
|
|
/// </summary>
|
|
[DataMember]
|
|
public string Background { get; private set; }
|
|
|
|
/// <summary>
|
|
/// It is the grid of the possible operation in the game
|
|
/// </summary>
|
|
[DataMember]
|
|
public ReadOnlyObservableCollection<OperationCell> OperationGrid { get; private set; }
|
|
ObservableCollection<OperationCell> operationGrid = new ObservableCollection<OperationCell>();
|
|
|
|
/// <summary>
|
|
/// It is a list of a list containing user's rope paths in the current game
|
|
/// </summary>
|
|
[DataMember]
|
|
public List<List<Cell>> RopePaths { get; private set; }
|
|
|
|
/// <summary>
|
|
/// It is a list of a list containing user's zones in the current game
|
|
/// </summary>
|
|
[DataMember]
|
|
public List<List<Cell>> Zones { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the Map class.
|
|
/// </summary>
|
|
/// <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);
|
|
RopePaths = new List<List<Cell>>();
|
|
Zones = new List<List<Cell>>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clone the map to avoid reference problems.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Map Clone()
|
|
{
|
|
Map map = new Map(Name, Background);
|
|
return map;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes the boards of the map.
|
|
/// </summary>
|
|
/// <returns>Return the boards</returns>
|
|
private void InitializeBoards(ObservableCollection<Cell> board)
|
|
{
|
|
for (int i = 0; i < 49; i++) // 7x7 board
|
|
{
|
|
board.Add(new Cell(i % 7, i / 7));
|
|
}
|
|
board[1].Valid = true;
|
|
board[3].Valid = true;
|
|
board[4].Valid = true;
|
|
board[5].Valid = true;
|
|
board[9].Valid = true;
|
|
board[12].Valid = true;
|
|
board[15].Valid = true;
|
|
board[16].Valid = true;
|
|
board[17].Valid = true;
|
|
board[21].Valid = true;
|
|
board[24].Valid = true;
|
|
board[25].Valid = true;
|
|
board[28].Valid = true;
|
|
board[30].Valid = true;
|
|
board[31].Valid = true;
|
|
board[32].Valid = true;
|
|
board[40].Valid = true;
|
|
board[41].Valid = true;
|
|
board[48].Valid = true;
|
|
|
|
board[3].IsDangerous = true;
|
|
board[15].IsDangerous = true;
|
|
board[16].IsDangerous = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes the operation grid of the map.
|
|
/// </summary>
|
|
/// <returns>Return the operation grid</returns>
|
|
private void InitializeOperationGrid(ObservableCollection<OperationCell>operationGrid)
|
|
{
|
|
for (int i = 0; i < 5; i++) // 5 operations
|
|
{
|
|
for (int j = 0; j < 4; j++) // 4 cells per operation
|
|
{
|
|
operationGrid.Add(new OperationCell(j, i));
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool CheckOperationPossible(int x)
|
|
{
|
|
return OperationGrid[x * 4 + 3].IsChecked;
|
|
}
|
|
|
|
public bool IsCellInZones(Cell cell)
|
|
{
|
|
foreach (var zone in Zones)
|
|
{
|
|
if (zone.Contains(cell))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsCellInRopePath(Cell cell)
|
|
{
|
|
foreach (var path in RopePaths)
|
|
{
|
|
if (path.Contains(cell))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
} |