/// <summary>
        /// Converts the given storage to the list of bytes by the same convention as in FillBoardStorageFromArray.
        /// Bonus layer is stored in the configuration so we do not need to transfer them.
        /// </summary>
        public List <byte> ConvertBoardStorageToBytes(BlockBoardStorage boardStorage)
        {
            //Ignore bonus layer.
            boardStorage.ConvertToArrays(out var items, out _);

            var byteList = new List <byte>();

            for (var col = 1; col <= blockWidth * blocksHorizontal; col++)
            {
                for (var row = 1; row <= blockHeight * blocksVertical; row++)
                {
                    byte currentType = emptyCellId;
                    Army army        = null;
                    if (items[col, row] != null && items[col, row] is ArmyStorageItem)
                    {
                        army        = ((ArmyStorageItem)items[col, row]).Army;
                        currentType = (byte)GetArmyIdType(army);
                    }
                    byteList.Add(currentType);

                    if (currentType != emptyCellId) // it is an army, not an empty cell
                    {
                        SerializeArmyComposition(army, byteList);
                    }
                }
            }

            return(byteList);
        }
        /// <summary>
        /// Creates an empty block storage of the given type and boardManager associated with it.
        /// </summary>
        public BlockBoardStorage CreateEmptyBlockStorage(BoardType configurationType, out BoardManager boardManager)
        {
            var configuration = GetConfigurationByType(configurationType);
            var storage       = new BlockBoardStorage(configuration.BlocksHorizontal, configuration.BlocksHorizontal, board);

            boardManager = new BoardManager(storage, configuration.FirstStartBlock, configuration.SecondStartBlock);
            return(storage);
        }
 public UserController(PlayerType playerType, BlockBoardStorage storage, BoardFactory boardFactory,
                       PlayGameState playGameState, ArmyText armyText, RoundEffects roundEffects)
 {
     this.playerType    = playerType;
     boardStorage       = storage;
     this.boardFactory  = boardFactory;
     this.playGameState = playGameState;
     this.armyText      = armyText;
     this.roundEffects  = roundEffects;
     roundEffects.Initialize(storage);
 }
示例#4
0
        /// <summary>
        /// Common setup for all child classes.
        /// </summary>
        protected void SetupGame()
        {
            menuActivator.OpenMenu(playMenu);

            lerpedText.FinishedLerp += CloseGame;

            boardStorage = boardFactory.CreateEmptyBlockStorage(ConfigurationType, out boardManager);

            playedTurns = 0;

            timer.OnFinish += ChangeTurn;

            exitListener.Enable();
            exitListener.OnExitClicked += OnBackButtonPressed;
        }
示例#5
0
        public Graph(BlockBoardStorage boardStorage)
        {
            this.boardStorage = boardStorage;
            size = boardStorage.GetNumberOfCells();
            InitializeEdges();

            var index = 0;
            var cells = boardStorage.GetListOfCells();

            foreach (var cell in cells)
            {
                nodeIndexByCell.Add(cell, index);
                index++;
            }

            AddEdges(cells);
            CalculateDistances();
        }
示例#6
0
        /// <summary>
        /// Creates the copy of the board storage.
        /// </summary>
        public IBoardStorage CloneBoardStorage()
        {
            var clonedStorage = new BlockBoardStorage(width, height, board)
            {
                currentBlockPosition = currentBlockPosition.CloneVector()
            };

            for (var i = 1; i <= width; i++)
            {
                for (var j = 1; j <= height; j++)
                {
                    clonedStorage.blocks[i, j] = blocks[i, j].CloneBoardStorage() as SingleBoardStorage;
                }
            }

            clonedStorage.currentBlock = clonedStorage.blocks[currentBlockPosition.x, currentBlockPosition.y];
            clonedStorage.CompleteBoardInitialization();
            return(clonedStorage);
        }