public void GetNextPiece() { CurrentSelectedPiece = null; CurrentPieceRotation = (BasePiece.RotationDirection)Random.Range(0, (int)BasePiece.RotationDirection.Count); //BasePiece.RotationDirection.Normal; List <BoardGridLocation> availableLocations = new List <BoardGridLocation>(); int xLength = BoardGridLocations.GetLength(0); int yLength = BoardGridLocations.GetLength(1); for (int x = 0; x < xLength; x++) { for (int y = 0; y < yLength; y++) { BoardGridLocation checkLocation = BoardGridLocations[x, y]; if (checkLocation == null || checkLocation.InUse) { continue; } availableLocations.Add(checkLocation); } } int targetCategory = 0; int totalTiles = xLength * yLength; int availableTiles = availableLocations.Count; if (availableTiles > ((float)totalTiles * 0.8f)) { targetCategory = 2; } else if (availableTiles > (float)(totalTiles * 0.5f)) { targetCategory = 1; } else { targetCategory = 0; } List <int> checkPieces = GetPieceIndexesForCategory(targetCategory); int pieceIndex = 0; if (checkPieces != null && checkPieces.Count > 0) { pieceIndex = checkPieces[Random.Range(0, checkPieces.Count)]; } UpdatePiece(pieceIndex); if (availableLocations.Count > 0) { BoardGridLocation randomStartingPlace = availableLocations[Random.Range(0, availableLocations.Count)]; MoveCurrentPieceToBoardLocation(randomStartingPlace); } }
public BoardGridLocation GetLocationAtPosition(int x, int y) { if (BoardGridLocations == null || x >= BoardGridLocations.GetLength(0) || y >= BoardGridLocations.GetLength(1)) { return(null); } return(BoardGridLocations[x, y]); }
public BoardGridLocation GetValidLocationAtPosition(int x, int y) { if (BoardGridLocations == null || BoardGridLocations.GetLength(0) <= 0 || BoardGridLocations.GetLength(1) <= 0) { return(null); } int closestXLocation = Mathf.Clamp(x, 0, BoardGridLocations.GetLength(0) - 1); int closestYLocation = Mathf.Clamp(y, 0, BoardGridLocations.GetLength(1) - 1); return(BoardGridLocations[closestXLocation, closestYLocation]); }
public bool IsGameOver() { int numPlayers = PersistentData.instance.NumberOfPlayers; int numTilesRemaining = 0; for (int x = 0; x < BoardGridLocations.GetLength(0); x++) { for (int y = 0; y < BoardGridLocations.GetLength(1); y++) { BoardGridLocation checkLocation = BoardGridLocations[x, y]; if (checkLocation == null || checkLocation.InUse) { continue; } numTilesRemaining++; } } return(numTilesRemaining < numPlayers); }