private BoardCell[][] getBoardCellArrayFromServiceStates(ChallengeService.state?[][] stateBoard) { BoardCell[][] newBoard = new BoardCell[stateBoard.Length][]; for (int x = 0; x < stateBoard.Length; ++x) { newBoard[x] = new BoardCell[stateBoard[x].Length]; for (int y = 0; y < stateBoard[x].Length; ++y) { switch (stateBoard[x][y]) { case null: case ChallengeService.state.NONE: case ChallengeService.state.EMPTY: newBoard[x][y] = BoardCell.EMPTY; break; case ChallengeService.state.FULL: newBoard[x][y] = BoardCell.WALL; break; case ChallengeService.state.OUT_OF_BOUNDS: newBoard[x][y] = BoardCell.OUT_OF_BOUNDS; break; default: newBoard[x][y] = BoardCell.OUT_OF_BOUNDS; break; } } } return newBoard; }
public PuzzleBoard(BoardConfig config) { BoardConfig = config; Board = new BoardCell[config.Width * config.Height]; for (int index = 0; index < config.Width * config.Height; index++) { var cell = new BoardCell(); Board[index] = cell; } }
public List <BoardCell> GetBoardTable() { DataRowCollection collect = ExcelAccess.GetCollection("Board.xls"); List <BoardCell> list = new List <BoardCell>(); for (int i = 1; i < collect.Count; i++) { if (collect[i][1].ToString() == "") { continue; } BoardCell cell = new BoardCell(); cell._id = int.Parse(collect[i][0].ToString()); cell._name = collect[i][1].ToString(); cell._description = collect[i][2].ToString(); cell._gold = int.Parse(collect[i][3].ToString()); list.Add(cell); } return(list); }
private void SetBuildingsToAttack(int x, int z, SpatialIndex spatialIndex) { Board board = Service.BoardController.Board; BoardCell cellAt = board.GetCellAt(x, z, true); NodeList <BuildingNode> nodeList = Service.EntityController.GetNodeList <BuildingNode>(); spatialIndex.AlreadyScannedBuildingsToAttack = true; for (BuildingNode buildingNode = nodeList.Head; buildingNode != null; buildingNode = buildingNode.Next) { SmartEntity smartEntity = (SmartEntity)buildingNode.Entity; if (smartEntity.DamageableComp != null) { if (this.IsAliveHealthNode(smartEntity)) { int squaredDistance = this.CalcSquredDistanceFromTransformToCell(smartEntity.TransformComp, cellAt); int nearness = this.CalcNearness(squaredDistance); spatialIndex.AddBuildingsToAttack(smartEntity, nearness); } } } }
public void Add(BoardCell element) { BoardCell[] array = this.Array; int length = this.Length; int capacity = this.Capacity; if (length == capacity) { int num = capacity * 2; BoardCell[] array2 = new BoardCell[num]; for (int i = 0; i < length; i++) { array2[i] = array[i]; } this.Array = array2; this.Capacity = num; array = array2; } array[length] = element; this.Length++; }
public override Move?DeterminePossibleMove(Game game) { Move?CheckCellsForBlockMove(ICollection <BoardCell> alignedCells) { // Number of cells occupied by opponent int occupiedCellsCount = alignedCells.Count(cell => cell.Figure == game.OpponentFigure); // Empty cells List <BoardCell> emptyCells = alignedCells.Where(cell => cell.Figure == Figure.Empty).ToList(); if (occupiedCellsCount == game.BoardSize - 1 && emptyCells.Count == 1) { BoardCell emptyCell = emptyCells.First(); return(new Move(emptyCell.Row, emptyCell.Column)); } return(null); } return(GetAllAlignedCells(game).Select(CheckCellsForBlockMove).FirstOrDefault(m => m.HasValue)); }
public void WinInOneMoveAllPositions() { _boardOptions = new BoardOptions(new Vector2(5, 5), 24); using StreamReader sr = File.OpenText(FILENAMEALLPOSITIONS); string instruction = string.Empty; while ((instruction = sr.ReadLine()) != null) { _board = _boardGenerator.GenerateBoard(_boardOptions); // All the positions of the board are mines. foreach (BoardCell boardCell in _board.Cells) { boardCell.IsMine = true; } // Parse the action SelectCellAction action = (SelectCellAction)_actionParser.ParseAction(instruction); BoardCell cell = _board.Cells.FirstOrDefault(x => x.Position == action.CellPosition); //The required cell is not a mine cell.IsMine = false; _boardManager.SelectCell(_board, action.CellPosition); bool result = _board.Cells.Count(c => !c.IsMine && c.Status == CellStatus.VISIBLE) == _board.Cells.Length - _board.MineNumber; try { Assert.AreEqual(true, result); _logger.Log(string.Format("Win the game in one move {0}", instruction), AutomationTestType.WinInOneMoveAllPositions); } catch (System.Exception) { _logger.Log(string.Format("ASSERT ERROR: We don't win the game in one move {0}", instruction), AutomationTestType.WinInOneMoveAllPositions); } } }
private void ImpactAreaWithSplash(Bullet bullet) { int targetBoardX = bullet.TargetBoardX; int targetBoardZ = bullet.TargetBoardZ; int splashRadius = bullet.SplashVO.SplashRadius; BoardCellDynamicArray cellsInSquare = Service.BoardController.Board.GetCellsInSquare(splashRadius, targetBoardX, targetBoardZ); Dictionary <Entity, bool> dictionary = new Dictionary <Entity, bool>(); Vector3 targetWorldLocation = bullet.TargetWorldLocation; for (int i = 0; i < cellsInSquare.Length; i++) { BoardCell boardCell = cellsInSquare.Array[i]; int chessboardDistance = BoardUtils.GetChessboardDistance(boardCell.X, boardCell.Z, targetBoardX, targetBoardZ); int splashDamagePercent = bullet.SplashVO.GetSplashDamagePercent(chessboardDistance); if (splashDamagePercent != 0) { ShieldGeneratorComponent activeShieldAffectingBoardPos = Service.ShieldController.GetActiveShieldAffectingBoardPos(boardCell.X, boardCell.Z); if (activeShieldAffectingBoardPos != null && !bullet.ProjectileType.PassThroughShield && activeShieldAffectingBoardPos.Entity.Get <TeamComponent>().TeamType != bullet.OwnerTeam) { TransformComponent transformComponent = activeShieldAffectingBoardPos.Entity.Get <TransformComponent>(); Vector3 targetPos = new Vector3(Units.BoardToWorldX(transformComponent.CenterX()), transformComponent.CenterX(), Units.BoardToWorldZ(transformComponent.CenterZ())); Vector3 zero = Vector3.zero; if (Service.ShieldController.GetRayShieldIntersection(targetWorldLocation, targetPos, activeShieldAffectingBoardPos, out zero)) { bullet.SetTargetWorldLocation(zero); } this.ImpactTargetFromSplashDamage((SmartEntity)activeShieldAffectingBoardPos.ShieldBorderEntity, bullet, splashDamagePercent, ref dictionary); } else if (boardCell.Children != null) { LinkedListNode <BoardItem> next; for (LinkedListNode <BoardItem> linkedListNode = boardCell.Children.First; linkedListNode != null; linkedListNode = next) { next = linkedListNode.Next; this.ImpactTargetFromSplashDamage((SmartEntity)linkedListNode.Value.Data, bullet, splashDamagePercent, ref dictionary); } } } } }
private (int, int, int) SeedFirstNude(Board board) { // if possible, choose a cell at the surface BoardCell nude = board.FirstOrDefault(cell => cell.IsNude && ( cell.PosX == 0 || cell.PosY == 0 || cell.PosZ == 0 || cell.PosX == board.Width - 1 || cell.PosY == board.Height - 1 || cell.PosZ == board.Depth - 1) ); if (nude != null) { nude.State = CellState.Revealed; return(nude.PosX, nude.PosY, nude.PosZ); } // commented out because Unity Engine is not threadsafe. /// Debug.Log("Did not find surface nudes."); foreach (BoardCell cell in board.Cells) { if (cell.IsNude) { cell.State = CellState.Revealed; return(cell.PosX, cell.PosY, cell.PosZ); } } // no nudes available. use any non-bomb foreach (BoardCell cell in board.Cells) { if (!cell.IsBomb) { cell.State = CellState.Revealed; return(cell.PosX, cell.PosY, cell.PosZ); } } // only bombs available! throw new EricException(); }
public bool ValidateTroopPlacement(IntPosition boardPosition, TeamType teamType, int troopWidth, bool sendEventsForInvalidPlacement, out BoardCell <Entity> pathCell, bool forceAllow) { Board <Entity> board = this.boardController.Board; BoardCell <Entity> cellAt = board.GetCellAt(boardPosition.x, boardPosition.z); pathCell = null; if (!forceAllow && (cellAt == null || cellAt.CollidesWith(CollisionFilters.TROOP))) { if (sendEventsForInvalidPlacement) { Service.Get <EventManager>().SendEvent(EventId.TroopNotPlacedInvalidArea, boardPosition); } return(false); } int num = boardPosition.x - troopWidth / 2; int num2 = boardPosition.z - troopWidth / 2; pathCell = board.GetCellAt(num, num2); if (!forceAllow && (num > 23 - troopWidth || num2 > 23 - troopWidth || pathCell == null || pathCell.Clearance < troopWidth)) { if (sendEventsForInvalidPlacement) { Service.Get <EventManager>().SendEvent(EventId.TroopNotPlacedInvalidArea, new IntPosition(boardPosition.x - Units.GridToBoardX(troopWidth), boardPosition.z - Units.GridToBoardX(troopWidth))); } return(false); } if (teamType == TeamType.Attacker) { uint num3 = cellAt.Flags & 20u; if (num3 != 0u && !forceAllow) { if (sendEventsForInvalidPlacement) { Service.Get <EventManager>().SendEvent(EventId.TroopNotPlacedInvalidArea, boardPosition); } return(false); } } return(true); }
private IntPosition DetermineSpawnPosition() { IntPosition zero = IntPosition.Zero; switch (this.Type) { case CombatTriggerType.Area: case CombatTriggerType.Load: if (this.Leashed) { TransformComponent transformComponent = ((Entity)this.Owner).Get <TransformComponent>(); if (transformComponent != null) { zero = new IntPosition(transformComponent.X, transformComponent.Z); } } else { DamageableComponent damageableComponent = ((Entity)this.Owner).Get <DamageableComponent>(); if (damageableComponent != null) { BoardCell <Entity> boardCell2; BoardCell <Entity> boardCell = damageableComponent.FindASafeSpawnSpot(this.Troop.SizeX, out boardCell2); zero = new IntPosition(boardCell.X, boardCell.Z); } } break; case CombatTriggerType.Death: { TransformComponent transformComponent = ((Entity)this.Owner).Get <TransformComponent>(); if (transformComponent != null) { zero = new IntPosition(transformComponent.CenterGridX(), transformComponent.CenterGridZ()); } break; } } return(zero); }
private List <BoardCell <Entity> > FindTheTurns(List <BoardCell <Entity> > path) { List <BoardCell <Entity> > list = new List <BoardCell <Entity> >(); int count = path.Count; list.Add(path[count - 1]); for (int i = count - 2; i > 0; i--) { BoardCell <Entity> boardCell = path[i]; BoardCell <Entity> boardCell2 = path[i + 1]; BoardCell <Entity> boardCell3 = path[i - 1]; if (boardCell.X - boardCell2.X != boardCell3.X - boardCell.X || boardCell.Z - boardCell2.Z != boardCell3.Z - boardCell.Z) { list.Add(boardCell); } } if (count >= 2) { list.Add(path[0]); } return(list); }
public void placeTresorInCell(BoardCell cell) { if ((cell.treasure == null) && (currentNbTresorsForPlayer != 0)) { Vector3 tresorPosition = cell.transform.position; tresorPosition.z = tresorPositionZ; GameObject tresorPrefab = tresorPrefabs[currentTresorId]; GameObject tresorObject = Instantiate(tresorPrefab, tresorPosition, Quaternion.identity) as GameObject; tresorObject.transform.localScale = cell.transform.localScale; tresorObject.transform.parent = tresorsParent; cell.treasure = tresorObject; cell.treasurePlayerId = currentPlayerId; setCurrentNbTresorsForPlayer(currentNbTresorsForPlayer - 1); } else if ((cell.treasure != null) && (cell.treasurePlayerId == currentPlayerId)) { DestroyImmediate(cell.treasure.gameObject); cell.treasure = null; cell.treasurePlayerId = -1; setCurrentNbTresorsForPlayer(currentNbTresorsForPlayer + 1); } }
public Vector3 MoveGameObject(GameObjectViewComponent view, PathView pathView, int troopWidth) { BoardCell <Entity> nextTurn = pathView.GetNextTurn(); if (nextTurn != null && pathView.TimeToTarget > 0f) { float num = 0f; float num2 = 0f; pathView.GetTroopClusterOffset(ref num, ref num2); float num3 = Mathf.Min(pathView.TimeOnPathSegment / pathView.TimeToTarget, 1f); Vector3 startPos = pathView.StartPos; float num4 = (Units.BoardToWorldX(nextTurn.X) - startPos.x) * num3 + startPos.x + num; float num5 = (Units.BoardToWorldX(nextTurn.Z) - startPos.z) * num3 + startPos.z + num2; num4 += Units.BoardToWorldX((float)troopWidth / 2f); num5 += Units.BoardToWorldX((float)troopWidth / 2f); Transform mainTransform = view.MainTransform; Vector3 result = new Vector3(num4 - mainTransform.position.x, 0f, num5 - mainTransform.position.z); view.SetXYZ(num4, mainTransform.position.y, num5); return(result); } return(Vector3.zero); }
private int getNbAdjacentCells(BoardCell cell, PlayerPiece piece, ref bool adjacentToPiece) { int nbAdjacentCells = 0; if (cell.rowIndex != 0) { checkAdjacentCell(cell.rowIndex - 1, cell.colIndex, piece, ref adjacentToPiece, ref nbAdjacentCells); } if (cell.rowIndex != getMaxRowIndex()) { checkAdjacentCell(cell.rowIndex + 1, cell.colIndex, piece, ref adjacentToPiece, ref nbAdjacentCells); } if (cell.colIndex != 0) { checkAdjacentCell(cell.rowIndex, cell.colIndex - 1, piece, ref adjacentToPiece, ref nbAdjacentCells); } if (cell.colIndex != getMaxColumnIndex()) { checkAdjacentCell(cell.rowIndex, cell.colIndex + 1, piece, ref adjacentToPiece, ref nbAdjacentCells); } return(nbAdjacentCells); }
public CellMarkupStructure GetLeftMoveCellsId(List <BoardCell> cellIdsList, int index) { int rowIndex = (int)(index / 8) + 1; int lowBoundary = ((rowIndex - 1) * 8); int hieBoundary = ((rowIndex) * 8) - 1; FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index; do { BoardCell boardCell = GetLeftCell(cellIdsList, ref localIndex, lowBoundary, hieBoundary); if (boardCell != null) { if (boardCell.figureOnCell != null) { Figure localFigureOnCell = boardCell.figureOnCell.GetComponent <Figure>(); if (localFigureOnCell.TeamType == figureTeamType) { break; } else { localCellMarkupStruct.canBeCapture.Add(boardCell.CellId); break; } } else { localCellMarkupStruct.canBeDreggedTo.Add(boardCell.CellId); } } else { break; } } while (true); return(localCellMarkupStruct); }
private BoardCellDynamicArray FindTheTurns(ref BoardCellDynamicArray path) { BoardCellDynamicArray result = new BoardCellDynamicArray(64); int length = path.Length; result.Add(path.Array[length - 1]); for (int i = length - 2; i > 0; i--) { BoardCell boardCell = path.Array[i]; BoardCell boardCell2 = path.Array[i + 1]; BoardCell boardCell3 = path.Array[i - 1]; if (boardCell.X - boardCell2.X != boardCell3.X - boardCell.X || boardCell.Z - boardCell2.Z != boardCell3.Z - boardCell.Z) { result.Add(boardCell); } } if (length >= 2) { result.Add(path.Array[0]); } return(result); }
public void _ship_width_less_than_one_exception() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); //Creating a ship with 0 width IBattleship battleShip = new Battleship { Width = 0, Orientation = OrientationType.Horizontal }; IBoardCell firstCell = new BoardCell { RowCoordinate = 1, ColumnCoordinate = 1 }; //Act and Assert Assert.Throws <ShipWidthCannotBeLessThanOneException>(() => _placeBattleship.CanShipBePlaced(battleShip, firstCell, board)); }
// trigger splitting animation public void Split(BoardCell dest) { // rotate cell Vector3 direction = dest.transform.position - transform.position; // mirrored spritesheet hack if (state == BoardCellState.Player2) { direction *= -1; } Quaternion rotation = Quaternion.FromToRotation(Vector3.right, direction); cellAnim.transform.rotation = rotation; dest.cellAnim.transform.rotation = rotation; PlayAnimation("Split"); GlobalAnimationTimer.AnimationTriggered(splitAnimationClip); // play audio MusicManagerSingleton.Instance.playSound(divisionAudio, audio); }
public override void Execute() { base.Execute(); BoardCell <Entity> cellAt = Service.Get <BoardController>().Board.GetCellAt(this.boardX, this.boardZ); if (cellAt == null) { Service.Get <StaRTSLogger>().ErrorFormat("Story {0} is attempting to remove a building at {1}, {2}, but there is no cell.", new object[] { this.vo.Uid, this.boardX, this.boardZ }); this.parent.ChildComplete(this); return; } if (cellAt.Children == null) { return; } this.buildingToRemove = null; for (LinkedListNode <BoardItem <Entity> > linkedListNode = cellAt.Children.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { Entity data = linkedListNode.Value.Data; BuildingComponent buildingComponent = data.Get <BuildingComponent>(); if (buildingComponent != null) { this.buildingToRemove = data; break; } } if (this.buildingToRemove != null) { this.fader = new ViewFader(); this.fader.FadeOut(this.buildingToRemove, 0f, 1f, null, new FadingDelegate(this.OnEntityFadeComplete)); Service.Get <EventManager>().SendEvent(EventId.BuildingRemovedFromBoard, this.buildingToRemove); } }
private void generateBoardCells() { boardCells = new BoardCell[nbRows][]; for (int i = 0; i < nbRows; ++i) { boardCells[i] = new BoardCell[nbColumns]; for (int j = 0; j < nbColumns; ++j) { generateBoardCellAtIndex(i, j); } } for (int i = 0; i < nbRows; ++i) { for (int j = 0; j < nbColumns; ++j) { BoardCell currentCell = boardCells[i][j]; if (i > 0) { currentCell.upCell = boardCells[i - 1][j]; } if (j > 0) { currentCell.leftCell = boardCells[i][j - 1]; } if (i < nbRows - 1) { currentCell.downCell = boardCells[i + 1][j]; } if (j < nbColumns - 1) { currentCell.rightCell = boardCells[i][j + 1]; } } } }
public void CheckVisibleWhenSelect() { // All the positions of the board are not mines. foreach (BoardCell boardCell in _board.Cells) { boardCell.IsMine = false; } using StreamReader sr = File.OpenText(FILENAMEALLPOSITIONS); string instruction = string.Empty; while ((instruction = sr.ReadLine()) != null) { // Parse the action SelectCellAction action = (SelectCellAction)_actionParser.ParseAction(instruction); try { _boardManager.SelectCell(_board, action.CellPosition); } catch (CellAlreadyVisibleException) { //We ignore this kind of exception. } BoardCell cell = _board.Cells.FirstOrDefault(x => x.Position == action.CellPosition); try { Assert.AreEqual(CellStatus.VISIBLE, cell.Status); _logger.Log(string.Format("Cell {0} is Visible", instruction), AutomationTestType.CheckVisibleWhenSelect); } catch (System.Exception) { _logger.Log(string.Format("ASSERT ERROR: Cell {0} is NOT visible", instruction), AutomationTestType.CheckVisibleWhenSelect); } } }
private void generateBoardCellAtIndex(int rowIndex, int colIndex) { Vector3 cellPosition = boardStartPosition; cellPosition.x += (colIndex + 1.5f) * spaceBetweenColumns; cellPosition.y -= (rowIndex + 1.5f) * spaceBetweenRows; GameObject boardCellObject = Instantiate(boardCellPrefab.gameObject, cellPosition, Quaternion.identity) as GameObject; if (boardCellObject == null) { return; } boardCellObject.transform.parent = boardCellsParent; boardCellObject.transform.localScale = boardCellScale; boardCellObject.name = "Board cell " + rowIndex + "," + colIndex; BoardCell boardCell = boardCellObject.GetComponent <BoardCell>(); boardCells[rowIndex][colIndex] = boardCell; boardCell.rowIndex = rowIndex; boardCell.colIndex = colIndex; }
/// <summary>Creates the board cells.</summary> private void CreateBoardCells() { for (int x = 0; x < COLUMNS; x++) { for (int y = 0; y < ROWS; y++) { if (LevelsManager.instance.currentLevel.IsValidCell(x, y)) { BoardCell cell = Instantiate(boardCellPrefab, this.transform, false) as BoardCell; cell.SetXY(x, y); cells[x, y] = cell; } else { if (y != 0) //don't need a mask at the bottom of the board { Transform maskCell = Instantiate(boardCellSpriteMaskPrefab, mask, false) as Transform; maskCell.localPosition = new Vector3(x, y); } } } } }
public void RegisterPlayer(string name, BoardCell type) { if (Player1 == null) { Player1 = TicTacToePlayer.Create(name, type); } else if (Player2 == null) { if (Player1.Name == name) { throw new InvalidOperationException("Name already registered."); } if (Player1.Type == type) { throw new InvalidOperationException("Type already registered."); } Player2 = TicTacToePlayer.Create(name, type); } else { throw new InvalidOperationException("Players already registered."); } }
void SetupMap(int xsize, int ysize) { if (cell_map == null || cell_map.GetLength(0) != xsize || cell_map.GetLength(1) != ysize) { Clear(); cell_map = new BoardCell[xsize, ysize]; for (int i = 0; i < ysize; i++) { for (int o = 0; o < xsize; o++) { //obj GameObject new_obj = Instantiate(cell_prefab, transform.position, Quaternion.identity); new_obj.transform.position = new Vector3(o * 1, i * 1, 0); new_obj.transform.parent = map_container; //cell BoardCell new_cell = new_obj.GetComponent <BoardCell>(); new_cell.coordinates = new Vector2(o, i); cell_map[o, i] = new_cell; new_obj.SetActive(true); } } } }
//[Route("api/BattleShip/Attack/{attackx}/{attacky}")] //[Route("Ship/{shipLength}")] public string Attack([FromBody] Data data) { int attackx = data.attackx; int attacky = data.attacky; string attackresult = string.Empty; BoardCell cellAttacked = battleshipBoard.cells.Where(index => index.x == attackx && index.y == attacky).First(); if (cellAttacked.cell_state != cellstate.hit) { if (cellAttacked.occupied) { attackresult = "hit"; cellAttacked.cell_state = cellstate.hit; } else { attackresult = "miss"; } } // set the values after complete ship has sunk string attackedShip = cellAttacked.ship_name; List <BoardCell> attackedShipCells = battleshipBoard.cells .Where(cell_shipname => cell_shipname.ship_name == attackedShip).ToList(); int shipCellHitCount = attackedShipCells.Where(hit => hit.cell_state == cellstate.hit).Count(); if (attackedShipCells.Count == shipCellHitCount) { foreach (BoardCell cellItem in attackedShipCells) { cellItem.occupied = false; cellItem.ship_name = string.Empty; cellItem.cell_state = cellstate.empty; } } return(attackresult); }
public SmartEntity SpawnTroop(TroopTypeVO troopType, TeamType teamType, IntPosition boardPosition, TroopSpawnMode spawnMode, bool sendPlacedEvent, bool forceAllow, VisitorType visitorType) { Entity spawnBuilding = null; BoardCell boardCell = null; if (!this.FinalizeSafeBoardPosition(troopType, ref spawnBuilding, ref boardPosition, ref boardCell, teamType, spawnMode, forceAllow)) { return(null); } SmartEntity smartEntity = Service.EntityFactory.CreateTroopEntity(troopType, teamType, boardPosition, spawnBuilding, spawnMode, true, true); if (smartEntity == null) { return(null); } SpawnComponent component = new SpawnComponent(visitorType); smartEntity.Add(component); BoardItemComponent boardItemComp = smartEntity.BoardItemComp; BoardItem boardItem = boardItemComp.BoardItem; if (Service.BoardController.Board.AddChild(boardItem, boardCell.X, boardCell.Z, null, false, !forceAllow && troopType.Type != TroopType.Champion) == null) { return(null); } Service.EntityController.AddEntity(smartEntity); Service.TroopAbilityController.OnTroopSpawned(smartEntity); if (troopType.Type != TroopType.Champion || teamType == TeamType.Attacker) { base.EnsureBattlePlayState(); } if (sendPlacedEvent) { Service.EventManager.SendEvent(EventId.TroopPlacedOnBoard, smartEntity); } return(smartEntity); }
public void Insert(int index, BoardCell element) { BoardCell[] array = this.Array; int length = this.Length; int capacity = this.Capacity; if (length == capacity) { int num = capacity * 2; BoardCell[] array2 = new BoardCell[num]; for (int i = 0; i < length; i++) { array2[i] = array[i]; } this.Array = array2; this.Capacity = num; array = array2; } if (index == length) { array[length] = element; this.Length++; } else { BoardCell boardCell = array[index]; array[index] = element; for (int j = index + 1; j < length; j++) { BoardCell boardCell2 = array[j]; array[j] = boardCell; boardCell = boardCell2; } array[length] = boardCell; this.Length++; } }
public void AssignDroidPath(DroidNode droid) { if (droid != null && droid.IsValid()) { int x = droid.Transform.X; int z = droid.Transform.Z; BoardController boardController = Service.BoardController; BoardCell startCell = boardController.Board.GetCellAt(x, z); SmartEntity smartEntity = (SmartEntity)droid.Droid.Target; TransformComponent transformComp = smartEntity.TransformComp; if (transformComp == null) { return; } int num = transformComp.X - 1; int num2 = transformComp.Z - 1; int num3 = Service.Rand.ViewRangeInt(0, transformComp.BoardWidth + transformComp.BoardDepth + 1); if (num3 <= transformComp.BoardWidth) { num += num3; } else { num2 += num3 - transformComp.BoardWidth; } BoardCell cellAt = boardController.Board.GetCellAt(num, num2); if (!droid.Droid.AnimateTravel) { startCell = cellAt; } if (cellAt != null) { Service.PathingManager.StartPathingWorkerOrPatrol((SmartEntity)droid.Entity, smartEntity, startCell, cellAt, droid.Size.Width, true); } droid.Droid.AnimateTravel = true; } }
private bool ImpactBeamTargets(Bullet bullet) { BoardCellDynamicArray beamNearbyCells = bullet.GetBeamNearbyCells(); if (beamNearbyCells.Array == null) { return(false); } for (int i = 0; i < beamNearbyCells.Length; i++) { BoardCell boardCell = beamNearbyCells.Array[i]; if (boardCell.Children != null) { int beamDamagePercent = bullet.GetBeamDamagePercent(boardCell.X, boardCell.Z); if (beamDamagePercent != 0) { for (LinkedListNode <BoardItem> linkedListNode = boardCell.Children.First; linkedListNode != null; linkedListNode = linkedListNode.Next) { SmartEntity target = (SmartEntity)linkedListNode.Value.Data; bullet.ApplyBeamDamagePercent(target, beamDamagePercent); } } } } foreach (BeamTarget current in bullet.BeamTargets.Values) { if (current.HitThisSegment) { bullet.SetTarget(current.Target); this.ImpactSingleTarget(bullet, current.CurDamagePercent, false, true); bullet.SetTarget(null); } current.OnBeamAdvance(); } bullet.AdvanceBeam(); return(true); }
public void ValidateStep45() { BoardCell cell = FindAvailableCell(); if (cell != null && (_currentLightEastColor != RayColor.NONE || _currentLightNorthEastColor != RayColor.NONE || _currentLightNorthColor != RayColor.NONE || _currentLightNorthWestColor != RayColor.NONE || _currentLightWestColor != RayColor.NONE || _currentLightSouthWestColor != RayColor.NONE || _currentLightSouthColor != RayColor.NONE || _currentLightSouthEastColor != RayColor.NONE )) { GameObject laserGameObject = Instantiate(LightSourcePrefab, ItemsContainer.transform); cell.AddItem(laserGameObject); Laser laser = laserGameObject.GetComponent <Laser>(); laser.IsColorable = false; laser.IsOrientable = false; AddRayToLightSource(laser, _currentLightEastColor, Direction.East); AddRayToLightSource(laser, _currentLightNorthEastColor, Direction.NorthEast); AddRayToLightSource(laser, _currentLightNorthColor, Direction.North); AddRayToLightSource(laser, _currentLightNorthWestColor, Direction.NorthWest); AddRayToLightSource(laser, _currentLightWestColor, Direction.West); AddRayToLightSource(laser, _currentLightSouthWestColor, Direction.SouthWest); AddRayToLightSource(laser, _currentLightSouthColor, Direction.South); AddRayToLightSource(laser, _currentLightSouthEastColor, Direction.SouthEast); DragAndDrop dragAndDrop = laserGameObject.GetComponent <DragAndDrop>(); dragAndDrop.IsDraggable = true; } Inventory.SetActive(false); Step45.SetActive(false); Step40.SetActive(true); }
private bool checkIsBulletInAir(BoardCell[][] board, ChallengeService.player me, ChallengeService.unit tank) { var bulletInAir = false; if (me.bullets != null) { foreach (var bullet in me.bullets) { if (Math.Abs(bullet.x - tank.x) < board.Length / 6) { bulletInAir = true; } } } return bulletInAir; }
// Distancia manhattan con respecto a otra ficha public int distancia(BoardCell ficha) { return System.Math.Abs(x - ficha.x) > System.Math.Abs(y - ficha .y) ? System.Math.Abs(x - ficha.x) : System.Math.Abs(y - ficha .y); }
BoardCell obtenerPelotaAdyacente(BoardCell ficha) { for (int i = (ficha.x - 1); i <= (ficha.x + 1); i++) { for (int j = (ficha.y - 1); j <= (ficha.y + 1); j++) { if (i > 0 && i < (alto - 1) && j >= 0 && j < ancho && board[i, j].ficha == TipoFicha.Pelota) { return board[i, j]; } } } return null; }
public Estado(BoardCell[,] board, int nivel, int alto, int ancho, Equipo equipo) { this.board = board; this.alto = alto; this.ancho = ancho; this.equipo = equipo; // Indicar la cantidad de fichas en base al nivel if (nivel == 1 || nivel == 2) { cantidadFichas = nivel; } else if (nivel == 3) { cantidadFichas = 5; } jugadores = new BoardCell[cantidadFichas]; oponentes = new BoardCell[cantidadFichas]; // Inicializar la lista de jugadores, oponentes y pelota int ij = 0; int io = 0; for (int i = 1; i < alto - 1; i++) { for (int j = 0; j < ancho; j++) { if (board[i, j].ficha == TipoFicha.Pelota) { pelota = board[i, j]; } if (board[i, j].fichaEquipo() == equipo) { jugadores[ij] = board[i, j]; ij += 1; // En caso que sea el arquero del equipo if (board[i,j].esArquero(false)) { arqueroJugador = board[i,j]; } } else if (board[i, j].fichaEquipo() != Equipo.Ninguno) { oponentes[io] = board[i, j]; io += 1; // En caso que sea el arquero del equipo if (board[i,j].esArquero(false)) { arqueroOponente = board[i,j]; } } } } }
public void Init() { cells = new BoardCell[rowCount, colCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { cells[i, j] = new BoardCell(i,j); } } }
public void mover(Equipo turno, Jugada jugada, bool deshacer) { int fichaX, fichaY, destinoX, destinoY; // Definir el sentido del movimiento if (deshacer) { fichaX = jugada.destinoX; fichaY = jugada.destinoY; destinoX = jugada.fichaX; destinoY = jugada.fichaY; } else { fichaX = jugada.fichaX; fichaY = jugada.fichaY; destinoX = jugada.destinoX; destinoY = jugada.destinoY; } // Realizar los cambios de posicion setFicha(destinoX, destinoY, board[fichaX, fichaY].ficha); setFicha(fichaX, fichaY, TipoFicha.Vacio); // Actualizar la referencia // Pelota if (board[destinoX, destinoY].ficha == TipoFicha.Pelota) { pelota = board[destinoX, destinoY]; } // Jugador else { for (int i = 0; i < cantidadFichas; i++) { if (equipo == turno && jugadores[i].x == fichaX && jugadores[i].y == fichaY) { jugadores[i] = board[destinoX, destinoY]; } else if (equipo != turno && oponentes[i].x == fichaX && oponentes[i].y == fichaY) { oponentes[i] = board[destinoX, destinoY]; } } } }
//Cell manipulators //Get, set, retrieve, remove public void SetCellAtPos(int x, int y, BoardCell cell) { SetCellAtIndex(BoardConfig.GetIndex(x, y), cell); }
public Move GetBestMove(ChallengeService.game game, BoardCell[][] board, ChallengeService.player me, ChallengeService.player enemy) { Move move = null; ChallengeService.unit tank = findTankInPlayer(_tankId, me); if (tank == null) { return null; } if (tank.x != _lastX || tank.y != _lastY) { _hasShotFromLastPosition = false; } var bulletInAir = checkIsBulletInAir(board, me, tank); var stuckLastTurn = checkStuckLastTurn(tank); var enemyBase = enemy.@base; var pastMidpoint = (Math.Abs(enemyBase.y-tank.y) < (board[0].Length / 2)); if (stuckLastTurn && (tank.direction == ChallengeService.direction.UP || tank.direction == ChallengeService.direction.DOWN) && enemyBase.x != tank.x) { _targetX = tank.x + (pastMidpoint!=(tank.x > enemyBase.x) ? +1 : -1); } if (_checkForOpenPathToMiddle && !_headingToMiddle && tank.x != enemyBase.x) { _headingToMiddle = testPathToMiddleIsOpen(board, tank, enemyBase); } else if (_checkForOpenPathToMiddle && _headingToMiddle && tank.x == enemyBase.x) { _headingToMiddle = false; } ChallengeService.direction chosenDirection = _headingToMiddle ? ( tank.x > enemyBase.x ? ChallengeService.direction.LEFT : ChallengeService.direction.RIGHT ) : ( tank.y != enemyBase.y ? ( _targetX.HasValue && _targetX != tank.x ? ( tank.x > _targetX ? ChallengeService.direction.LEFT : ChallengeService.direction.RIGHT ) : ( tank.y > enemyBase.y ? ChallengeService.direction.UP : ChallengeService.direction.DOWN ) ) : ( tank.x > enemyBase.x ? ChallengeService.direction.LEFT : ChallengeService.direction.RIGHT ) ); if (chosenDirection != tank.direction || bulletInAir || _headingToMiddle) { move = MoveInDirection(tank.id, chosenDirection); } else { move = new Move(tank.id, ChallengeService.action.FIRE); _hasShotFromLastPosition = true; } _lastX = tank.x; _lastY = tank.y; _lastAction = move.Action; return move; }
private bool testPathToMiddleIsOpen(BoardCell[][] board, ChallengeService.unit tank, ChallengeService.@base enemyBase) { var minY = tank.y - 2; var maxY = tank.y + 2; var minX = Math.Min(tank.x, enemyBase.x)-2; var maxX = Math.Max(tank.x, enemyBase.x)+2; bool insideRange = board.Length > maxX && board[maxX].Length > maxY && 0 <= minX && 0 <= minY; if (!insideRange) { return false; } for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { if (board[x][y] != BoardCell.EMPTY) { return false; } } } return true; }
public void SetCellAtIndex(int index, BoardCell cell) { BoardConfig.ValidateIndex(index); Board[index] = cell; }
// Inicializa la matriz con los valores segun las posiciones de las fichas void initializeMatrix() { // Cargar la matriz con celdas vacias for (int i = 0; i < alto; i++) { for (int j = 0; j < ancho; j++) { board[i, j] = new BoardCell(alto, ancho, i, j); } } // Cargar la matriz con los valores segun el nivel switch (MenuController.level) { case 1: setFicha(10, 5, TipoFicha.BlancoFicha); setFicha(4, 5, TipoFicha.RojoFicha); break; case 2: setFicha(10, 5, TipoFicha.BlancoFicha); setFicha(12, 5, TipoFicha.BlancoFicha); setFicha(4, 5, TipoFicha.RojoFicha); setFicha(2, 5, TipoFicha.RojoFicha); break; case 3: setFicha(8, 2, TipoFicha.BlancoFicha); setFicha(8, 8, TipoFicha.BlancoFicha); setFicha(10, 3, TipoFicha.BlancoFicha); setFicha(10, 7, TipoFicha.BlancoFicha); setFicha(12, 5, TipoFicha.BlancoArquero); setFicha(6, 2, TipoFicha.RojoFicha); setFicha(6, 8, TipoFicha.RojoFicha); setFicha(4, 3, TipoFicha.RojoFicha); setFicha(4, 7, TipoFicha.RojoFicha); setFicha(2, 5, TipoFicha.RojoArquero); break; } setFicha(7, 5, TipoFicha.Pelota); }