bool CanPlace(DiceUnfoldData diceUnfoldData, TwoDCoordinate objPos, Rotation rotation, TeamEnum team) { bool canPlace = false; List <TileData> myTiles = GetMyTiles(diceUnfoldData, objPos, rotation); List <TileData> tilesToCheck = new List <TileData>(); foreach (TileData myTile in myTiles) { foreach (TileData tile in tileData) { if (tile.coordinates.x == myTile.coordinates.x && tile.coordinates.y == myTile.coordinates.y && !tile.isFilled) { tilesToCheck.Add(tile); canPlace = true; break; } else { canPlace = false; } } if (!canPlace) { break; } } if (canPlace) { foreach (TileData tile in tilesToCheck) { if (tile.isConnected == true) { canPlace = true; break; } else { canPlace = false; } } } if (canPlace) { foreach (TileData tile in tilesToCheck) { if (tile.DoesTeamExist(team)) { canPlace = true; break; } else { canPlace = false; } } } return(canPlace); }
public void PlaceBox(DiceUnfoldData diceUnfoldData, TwoDCoordinate objPos, Rotation rotation, TeamEnum team) { if (CanPlace(diceUnfoldData, objPos, rotation, team)) { List <TileData> myTiles = GetMyTiles(diceUnfoldData, objPos, rotation); List <TileData> connectedTiles = new List <TileData>(); foreach (TileData myTile in myTiles) { TileData tile1 = new TileData(); tile1.coordinates = new TwoDCoordinate(myTile.coordinates.x + 2, myTile.coordinates.y); connectedTiles.Add(tile1); TileData tile2 = new TileData(); tile2.coordinates = new TwoDCoordinate(myTile.coordinates.x - 2, myTile.coordinates.y); connectedTiles.Add(tile2); TileData tile3 = new TileData(); tile3.coordinates = new TwoDCoordinate(myTile.coordinates.x, myTile.coordinates.y - 2); connectedTiles.Add(tile3); TileData tile4 = new TileData(); tile4.coordinates = new TwoDCoordinate(myTile.coordinates.x, myTile.coordinates.y + 2); connectedTiles.Add(tile4); } foreach (TileData myTile in myTiles) { foreach (TileData tile in tileData) { if (tile.coordinates.x == myTile.coordinates.x && tile.coordinates.y == myTile.coordinates.y && !tile.isFilled) { tile.isFilled = true; tile.isConnected = true; tile.AddTeam(team); break; } } } foreach (TileData myTile in connectedTiles) { foreach (TileData tile in tileData) { if (tile.coordinates.x == myTile.coordinates.x && tile.coordinates.y == myTile.coordinates.y) { tile.isConnected = true; tile.AddTeam(team); break; } } } pathFinder.UpdateGrid(tileData, boardSize); } }
List <TileData> GetMyTiles(DiceUnfoldData diceUnfoldData, TwoDCoordinate objPos, Rotation rotation) { List <TileData> myTiles = new List <TileData>(); foreach (TwoDCoordinate item in diceUnfoldData.myCoordinates) { TileData myTile = new TileData(); myTile.coordinates = new TwoDCoordinate(-1, -1); TwoDCoordinate pos = new TwoDCoordinate(2 * item.x, -2 * item.y); if (rotation == Rotation.Zero) { myTile.coordinates.x = objPos.x + pos.x; myTile.coordinates.y = objPos.y + pos.y; } else if (rotation == Rotation.Ninety) { myTile.coordinates.x = objPos.x + pos.y; myTile.coordinates.y = objPos.y - pos.x; } else if (rotation == Rotation.OneEighty) { myTile.coordinates.x = objPos.x - pos.x; myTile.coordinates.y = objPos.y - pos.y; } else if (rotation == Rotation.TwoSeventy) { myTile.coordinates.x = objPos.x - pos.y; myTile.coordinates.y = objPos.y + pos.x; } myTile.isFilled = false; myTiles.Add(myTile); } return(myTiles); }