/// <summary> /// Converts the given array of bytes to the board storage by the following convention: /// From left to right, from bottom to up. /// First the cellTypeId goes. /// If it is not an id of an empty cell, it is followed by three bytes: spearmen, archers, cavalrymen /// in the current army respectively. /// The rest of the initialization process is the same as in the random filling. /// </summary> public void FillBoardStorageFromArray(byte[] array, IBoardStorage boardStorage, BoardType configurationType, BoardManager boardManager) { InitializeConfigurationParameters(configurationType, boardManager); CreateGlobalTables(out var currentBoardTable, out var currentBonusTable); FillBonusTable(currentBonusTable); var currentInd = 0; for (var col = 1; col <= blockWidth * blocksHorizontal; col++) { for (var row = 1; row <= blockHeight * blocksVertical; row++) { var currentType = array[currentInd]; currentInd++; if (currentType == emptyCellId) { continue; } var armyComposition = FillArmyCompositionFromArray(array, currentInd); // Three bytes were read from array currentInd += 3; InitializeCellById(currentType, armyComposition, out var currentArmy, out var currentSprite); CompleteArmyCellInitialization(currentBoardTable, col, row, currentArmy, currentSprite); } } boardStorage.Fill(currentBoardTable, currentBonusTable); }
/// <summary> /// Fills the given storage randomly according to the given configuration type. /// The given board manager must be the one produced in constructor when creating given board storage. /// It will be transferred to passes. /// Creates two tables for army and bonus layers, fills them with BoardStorageItems (Army + Icon) and /// transfers them to the board storage. /// Note, that this method works properly with any implementations of IBoardStorage. /// </summary> public void FillBoardStorageRandomly(IBoardStorage boardStorage, BoardType configurationType, BoardManager boardManager) { //Initialize and save most common parameters to fields in order not to touch the configuration object every time. InitializeConfigurationParameters(configurationType, boardManager); //Create tables for army and bonus layers. CreateGlobalTables(out var currentBoardTable, out var currentBonusTable); //Fill bonus layer. FillBonusTable(currentBonusTable); //Fill army layer. for (var col = 1; col <= blockWidth * blocksHorizontal; col++) { for (var row = 1; row <= blockHeight * blocksVertical; row++) { if (!InitializeCell(col, row, out var currentArmy, out var currentSprite)) { //The cell is empty. continue; } //Now we know that the cell is not empty. CompleteArmyCellInitialization(currentBoardTable, col, row, currentArmy, currentSprite); } } //Fill the storage using filled tables. boardStorage.Fill(currentBoardTable, currentBonusTable); }
/// <inheritdoc/> protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { var path = HexgridPath as IDisposable; if (path != null) { path.Dispose(); path = null; } if (Landmarks != null) { Landmarks.Dispose(); Landmarks = null; } if (_boardHexes != null) { _boardHexes.Dispose(); _boardHexes = null; } } _isDisposed = true; } }
/// <summary> /// Initialization method. Must be called before every round. /// </summary> public void Initialize(IBoardStorage boardStorage) { this.boardStorage = boardStorage; }
/// <summary> /// Initializes a new instance of the <see cref="BoardsController" /> class. /// </summary> /// <param name="boardStorage">The board storage.</param> /// <param name="mapper">The mapper.</param> /// <exception cref="System.ArgumentNullException">boardStorage</exception> public BoardsController(IBoardStorage boardStorage, IMapper mapper) { this._boardStorage = boardStorage ?? throw new ArgumentNullException(nameof(boardStorage)); this._mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }
/// <summary> /// Returns a copy of boardIcon on the given position of the storage. /// Icon is placed on the same position. /// </summary> public GameObject CloneBoardIcon(IBoardStorage boardStorage, int fromX, int fromY) { var item = boardStorage.GetItem(fromX, fromY); return(InstantiateIcon(item.StoredObject.GetComponent <Image>().sprite)); }
internal Landmark(HexCoords coords, IBoardStorage <int> distanceTo, IBoardStorage <int> distanceFrom) { Coords = coords; BackingStore = new IBoardStorage <int>[] { distanceTo, distanceFrom }; }
public GameSimulation(IBoardStorage boardStorage) { this.boardStorage = boardStorage.CloneBoardStorage(); }