public bool GetSpaceEnabled(Enums.Player player) { if (_spaces.ContainsKey(player)) { return(_spaces[player].Active); } return(false); }
public IEnumerable <UnitController> GetAlliedUnits(Enums.Player player) { var alliedUnits = _unitsMovingThrough.Where(u => u.Player == player).ToList(); if (CurrentUnit != null && CurrentUnit.Player == player) { alliedUnits.Add(CurrentUnit); } return(alliedUnits); }
public void TurnChange() { currentTurnPieceList.Clear(); int minXPos = 0; if (currentTurnPlayer == Enums.Player.Player2 || !isGameStart) { currentTurnPlayer = Enums.Player.Player1; minXPos = Defines.BoardProperty.COL_COUNT; List <Piece> tmpList = new List <Piece>(); foreach (Piece piece in PieceManager.player1Pieces.Values) { tmpList.Add(piece); } for (int i = 0; i < Defines.BoardProperty.COL_COUNT; i++) { List <Piece> foundPiece = tmpList.FindAll(x => x.GetPoint().GetXPos() == i && x.GetIsAlive()); for (int j = 0; j < foundPiece.Count; j++) { currentTurnPieceList.Add(foundPiece[j]); } } isGameStart = true; } else if (currentTurnPlayer == Enums.Player.Player1) { currentTurnPlayer = Enums.Player.Player2; minXPos = Defines.BoardProperty.COL_COUNT; List <Piece> tmpList = new List <Piece>(); foreach (Piece piece in PieceManager.player2Pieces.Values) { tmpList.Add(piece); } for (int i = minXPos - 1; i >= 0; i--) { List <Piece> foundPiece = tmpList.FindAll(x => x.GetPoint().GetXPos() == i && x.GetIsAlive()); for (int j = 0; j < foundPiece.Count; j++) { currentTurnPieceList.Add(foundPiece[j]); } } } inputManager.TurnChange(currentTurnPlayer); }
public int GetAlliedUnits(Enums.Player player) { var rUnits = Right?.GetAlliedUnits(player).ToList(); var lUnits = Left?.GetAlliedUnits(player).ToList(); var uUnits = Up?.GetAlliedUnits(player).ToList(); var dUnits = Down?.GetAlliedUnits(player).ToList(); var totalUnits = rUnits.UnionNull(lUnits).UnionNull(uUnits).UnionNull(dUnits).ToList(); int count = totalUnits.Count; return(count); }
private static List <Location> GetWalkableAdjacentSquares(Enums.Player player, int x, int y, GridBlock[,] map) { List <Location> returnList = new List <Location>(); var proposedLocations = new List <Location>() { new Location { X = x, Y = y - 1 }, new Location { X = x, Y = y + 1 }, new Location { X = x - 1, Y = y }, new Location { X = x + 1, Y = y }, }; foreach (var loc in proposedLocations) { if (loc.X < 0 || loc.Y < 0) { continue; } if (loc.X >= map.GetLength(0) || loc.Y >= map.GetLength(1)) { continue; } var gridBlock = map[loc.X, loc.Y]; if (gridBlock == null) { continue; } var aS = gridBlock.ActiveSpace; if (player == Enums.Player.Player1 && aS != Enums.ActiveSpace.Move) { continue; } if (gridBlock.Unpassable) { continue; } returnList.Add(loc); } return(returnList); }
public void TurnChange(Enums.Player to) { Debug.Log("a"); currentCursor.SetActive(false); if (to == Enums.Player.Player1) { currentCursor = player1SelectCursor; } else if (to == Enums.Player.Player2) { currentCursor = player2SelectCursor; } currentCursor.SetActive(true); currentTargetIdx = 0; TargettingEffect(); }
public GridSpace this[Enums.Player player] { get { if (_spaces.ContainsKey(player)) { return(_spaces[player]); } else { return(null); } } set { _spaces[player] = value; } }
public bool IsEnemy(Enums.Player player) { return(Player != player);// && //!AlliedWith.Contains(player); }
public bool IsCurrentUnitEnemy(Enums.Player player) { return(!Utility.TrueNull(CurrentUnit) && CurrentUnit.Player != player);// && //!CurrentUnit.AlliedWith.Contains(player); }
public void Disable(Enums.Player player) { _gridParams.Reset(); }
public bool ContainsPlayer(Enums.Player player) { return(_spaces.ContainsKey(player)); }
public static IEnumerable <GridBlock> CreatePath(Enums.Player player, GridBlock gbStart, GridBlock gbTarget, GridBlock[,] map) { Location current = null; Location start = null; Location target = null; start = new Location { X = (int)gbStart.GridPosition.x, Y = (int)gbStart.GridPosition.y }; target = new Location { X = (int)gbTarget.GridPosition.x, Y = (int)gbTarget.GridPosition.y }; var openList = new List <Location>(); var closedList = new List <Location>(); var pathList = new List <GridBlock>(); int g = 0; // start by adding the original position to the open list openList.Add(start); while (openList.Count > 0) { // Check if the target has been added to the list current = openList.FirstOrDefault(l => l.H == 0); if (current == null) { // get the square with the lowest F score var lowest = openList.Min(l => l.F); current = openList.FirstOrDefault(l => l.F == lowest); } // add the current square to the closed list closedList.Add(current); // remove it from the open list openList.Remove(current); // if we added the destination to the closed list, we've found a path if (current.X == target.X && current.Y == target.Y) { break; } var adjacentSquares = GetWalkableAdjacentSquares(player, current.X, current.Y, map); g++; foreach (Location adjacentSquare in adjacentSquares) { int asX = adjacentSquare.X; int asY = adjacentSquare.Y; // Skip if the square has a unit that doesn't belong to the player and isn't the target of movement; if (map[asX, asY].CurrentUnit != null && map[asX, asY].CurrentUnit.Player != player && !(asX == target.X && asY == target.Y)) { continue; } // if this adjacent square is already in the closed list, ignore it if (closedList.FirstOrDefault(l => l.X == asX && l.Y == asY) != null) { continue; } // if it's not in the open list... if (openList.FirstOrDefault(l => l.X == asX && l.Y == asY) == null) { // compute its score, set the parent adjacentSquare.G = g; adjacentSquare.H = ComputeHScore(asX, asY, target.X, target.Y); adjacentSquare.F = adjacentSquare.G + adjacentSquare.H + (map[asX, asY].MovementCost * MOVEMENTCOSTMODIFIER); adjacentSquare.Parent = current; // and add it to the open list openList.Insert(0, adjacentSquare); } else { // test if using the current G score makes the adjacent square's F score // lower, if yes update the parent because it means it's a better path if (g + adjacentSquare.H < adjacentSquare.F) { adjacentSquare.G = g; adjacentSquare.F = adjacentSquare.G + adjacentSquare.H;// - map[asX, asY].MovementCost; adjacentSquare.Parent = current; } } } } Vector2? lastDir = null; Vector2? dir = null; GridBlock pB = null; while (current != null) { GridBlock gB = map[current.X, current.Y]; pathList.Add(gB); if (current.Parent != null) { pB = map[current.Parent.X, current.Parent.Y]; dir = gB.Position - pB.Position; // Since the first lastDir is null, it will create an arrow spacefd if (player == Enums.Player.Player1) { gB.UpdatePathState(gbStart.CurrentUnit, dir.Value, lastDir); } } else if (player == Enums.Player.Player1) { // Reached the first space, make it the start gB.UpdatePathState(gbStart.CurrentUnit, new Vector2(0, 0), lastDir); } lastDir = dir; current = current.Parent; } pathList.Reverse(); return(pathList); }