/// <summary> /// Checks the necessary conditions to perform split. /// If satisfied, returns true and performs split. /// Otherwise, returns false. /// If split is performed, the frame moves to the newly created army. /// </summary> private bool ProcessSplitClickOnAdjacent(IntVector2 position) { //We must have a chosen army, active split mode, //target position should be reachable from the chosen one and should not be a pass, //we must not overcome the limit of our armies on the board. if (chosenArmyItem == null || !splitButtonClicked || boardStorage.GetBonusItem(position) is Pass || !ReachableFromChosen(position)) { return(false); } if (boardStorage.FindPlayerArmies(playerType).Count >= MAX_ARMIES) { //An attempt to create too many armies. armyText.DisplayMaximumArmiesOnBoard(); return(false); } //All conditions satisfied, perform split. ProcessSplit(chosenArmyPosition, position); SetActiveFrame(position); SetSplitModeActive(false); chosenArmyItem = null; chosenArmyPosition = null; return(true); }
/// <summary> /// Creates an icon by the given sprite (it is inactive at this point) and fills the given cell with /// created ArmyStorageItem. /// </summary> private void CompleteArmyCellInitialization(BoardStorageItem[,] currentBoardTable, int col, int row, Army currentArmy, Sprite currentSprite) { var iconGO = InstantiateIcon(currentSprite); iconGO.SetActive(false); currentBoardTable[col, row] = new ArmyStorageItem(currentArmy, iconGO); }
/// <summary> /// Clears all move state. /// Clears the army text and disables the current frame (if exists). /// </summary> private void ClearMoveState() { SetActiveFrame(null); armyText.Clear(); chosenArmyItem = null; currentTargetPosition = null; currentMover = null; chosenArmyPosition = null; SetSplitModeActive(false); }
/// <summary> /// Processes the single click. /// Updates move state if necessary. /// </summary> private void ProcessAction(IntVector2 position) { var chooseOrMoveClick = false; if (boardStorage.GetItem(position) is ArmyStorageItem) { //Click on a cell with an army. if (!ProcessClickOnArmy(position, ref chooseOrMoveClick)) { //Nothing to do, repeated click on the same army. return; } } else { //Click on an empty cell. armyText.Clear(); SetActiveFrame(null); if (ProcessSplitClickOnAdjacent(position)) { //It was a click on an empty cell in a split mode, already processed. return; } } if (ProcessMoveClickOnAdjacent(position)) { //It was a click on adjacent with the chosen cell, so army move was processed. //Note that adjacent cell can be both empty or with an army. //That is why we have this condition separate with the previous one. return; } if (!chooseOrMoveClick) { //It was not click to choose or move an army. //So drop the current state. chosenArmyItem = null; chosenArmyPosition = null; //We process the pass only if it was not move click on it. if (boardStorage.GetBonusItem(position) is Pass) { //It was a simple click on a pass since we have already processed any army move. //So just change the current block. var pass = boardStorage.GetBonusItem(position) as Pass; pass.ChangeBlock(); } } //Split mode is active only during the next click. SetSplitModeActive(false); }
/// <summary> /// Determines whether the click was a chose click and remembers the clicked army, if so /// and if this army belongs to the player and is active. /// If it was an enemy army or an inactive army, drops the possibly previously chosen army. /// If it was not a choose click, nothing changes. /// Returns true if it was choose or move click. /// </summary> private bool ProcessChooseClick(IntVector2 position, ArmyStorageItem clickedArmyItem) { if (clickedArmyItem.Army.PlayerType != playerType || !((UserArmy)clickedArmyItem.Army).IsActive()) { //A clicked army does not belong to the player or is inactive. return(false); } if (chosenArmyItem != null && ReachableFromChosen(position)) { //It was a move click. Will be processed further. return(true); } //Remember the clicked army, it was a choose click. chosenArmyItem = clickedArmyItem; chosenArmyPosition = position; return(true); }
private bool GetArmyColor(ArmyStorageItem armyItem, out Color color) { color = Color.clear; if (armyItem.Army is UserArmy userArmy) { color = GetUserArmyFrameColor(userArmy); } else if (armyItem.Army is NeutralFriendlyArmy) { color = neutralFriendlyArmyFrameColor; } else if (armyItem.Army is NeutralAggressiveArmy) { color = neutralAggressiveArmyFrameColor; } else { //Something strange on this cell. return(false); } return(true); }
/// <summary> /// Transfers the given army and changes block. /// Removes the given army from the current block, changes the block and places the army to the new block. /// </summary> public void PassArmy(ArmyStorageItem army) { boardManager.GetCurrentBlock().SetItem(FromPosition, null); ChangeBlock(); boardManager.GetCurrentBlock().SetItem(ToPosition, army); }
public ItemAndPosition(ArmyStorageItem item, Cell cell) { Item = item; Cell = cell; }