private int GetRowsScore() { int rowsScore = 0; for (int y = 1; y < rowScores.Length; y++) { int score = 0; int inARow = 1; Color lastColor = GetSquare(0, y - 1).GetCurrentFace().color; for (int x = 1; x < COLUMNS; x++) { DieValueViewer currentSquare = GetSquare(x, y - 1); Color thisColor = currentSquare.GetCurrentFace().color; if (thisColor == lastColor && !currentSquare.Unused()) { inARow++; } else { score += scoringValues[inARow]; inARow = 1; } lastColor = thisColor; } score += scoringValues[inARow]; if (score == 0) { score = -5; } rowScores[y].SetText(score.ToString()); rowsScore += score; } return(rowsScore); }
private int GetColumnsScore() { int columnsScore = 0; for (int x = 0; x < columnScores.Length; x++) { int score = 0; int inARow = 1; Color lastColor = GetSquare(x, 0).GetCurrentFace().color; for (int y = 1; y < ROWS; y++) { DieValueViewer currentSquare = GetSquare(x, y); Color thisColor = currentSquare.GetCurrentFace().color; if (thisColor == lastColor && !currentSquare.Unused()) { inARow++; } else { score += scoringValues[inARow]; inARow = 1; } lastColor = thisColor; } score += scoringValues[inARow]; if (score == 0) { score = -5; } columnScores[x].SetText(score.ToString()); columnsScore += score; } return(columnsScore); }
private int GetDiagonalScore() { int diagonalScore = 0; int x = 0; int inARow = 1; Color lastColor = GetSquare(x, ROWS - 1).GetCurrentFace().color; for (int y = ROWS - 2; y >= 0; y--) { x++; DieValueViewer currentSquare = GetSquare(x, y); Color thisColor = currentSquare.GetCurrentFace().color; if (thisColor == lastColor && !currentSquare.Unused()) { inARow++; } else { diagonalScore += scoringValues[inARow]; inARow = 1; } lastColor = thisColor; } diagonalScore += scoringValues[inARow]; if (diagonalScore == 0) { diagonalScore = -5; } rowScores[0].SetText(diagonalScore.ToString()); return(diagonalScore); }
private void HighlightApplicableSquares() { List <DieValueViewer> squaresToHighlight = new List <DieValueViewer>(); if (diceSet == 0) { for (int i = 0; i < gameGrid.Length; i++) { if (gameGrid[i].Unused()) { squaresToHighlight.Add(gameGrid[i]); } } } else if (diceSet == 1) { for (int i = 0; i < gameGrid.Length; i++) { if (gameGrid[i] == selectedSquare) { Vector2Int coordinates = GetSquareCoordinates(i); if (coordinates.x >= 1) { DieValueViewer square = GetSquare(coordinates.x - 1, coordinates.y); if (square.Unused()) { squaresToHighlight.Add(square); } } if (coordinates.x < COLUMNS - 1) { DieValueViewer square = GetSquare(coordinates.x + 1, coordinates.y); if (square.Unused()) { squaresToHighlight.Add(square); } } if (coordinates.y >= 1) { DieValueViewer square = GetSquare(coordinates.x, coordinates.y - 1); if (square.Unused()) { squaresToHighlight.Add(square); } } if (coordinates.y < ROWS - 1) { DieValueViewer square = GetSquare(coordinates.x, coordinates.y + 1); if (square.Unused()) { squaresToHighlight.Add(square); } } break; } } } highlightedSquares = squaresToHighlight.Count; Color dieColor = selectedDie.GetFace().color; for (int i = 0; i < squaresToHighlight.Count; i++) { squaresToHighlight[i].SetOutline(dieColor); } }