Example #1
0
    private void Start()
    {
        recorder = new CCRecorder();

        scoringValues = new Dictionary <int, int>();
        scoringValues.Add(0, 0);
        scoringValues.Add(1, 0);
        scoringValues.Add(2, 2);
        scoringValues.Add(3, 3);
        scoringValues.Add(4, 8);
        scoringValues.Add(5, 10);

        for (int i = 0; i < gameGrid.Length; i++)
        {
            DieValueViewer square = gameGrid[i];
            square.SetToUnused();
            ExhibitUtilities.AddEventTrigger(square.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerUp, () => { SquareClicked(square); });
        }

        for (int i = 0; i < dice.Length; i++)
        {
            Die die = dice[i];
            ExhibitUtilities.AddEventTrigger(die.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerUp, () => { DieClicked(die); });
        }



        // game over panel
        gameOverPanel.Setup(RetryButtonPressed, RetrySameButtonPressed);


        // start game
        SetupForGame();
    }
Example #2
0
    private void SetupForGame()
    {
        originalCameraShakeStrength = cameraShakeStrength;

        gameOverPanel.Hide();

        for (int i = 0; i < gameGrid.Length; i++)
        {
            gameGrid[i].SetToUnused();
        }

        DieFace startingFace = dice[0].RandomFace();

        if (recorder.dice[0] == null || !retrySame)
        {
            recorder.dice[0] = startingFace;
        }
        else
        {
            startingFace = recorder.dice[0];
        }
        GetSquare(0, 0).SetViewAnimated(startingFace);
        recordDieIndex = 1;

        selectedDie         = null;
        selectedSquare      = null;
        cameraShakeStrength = 10f;

        CalculateScore();
        StartRound();
    }
Example #3
0
 public void SquareClicked(DieValueViewer square)
 {
     if (square.Outlined())
     {
         selectedSquare = square;
         ApplyDieValueToSquare();
     }
 }
Example #4
0
    private void ApplyDieValueToSquare()
    {
        CameraShake();

        selectedDie.Hide();
        selectedSquare.SetViewAnimated(selectedDie.GetFace());

        HideHighlights();

        diceSet++;

        CalculateScore();

        if (DoneWithRound())
        {
            if (NoRoomLeft())
            {
                GameEnded();
            }
            else
            {
                StartRound();
            }
        }
        else
        {
            for (int j = 0; j < dice.Length; j++)
            {
                if (dice[j].Available())
                {
                    selectedDie = dice[j]; selectedDie.Highlight(); break;
                }
            }
            HighlightApplicableSquares();
        }

        if (AllDiceNotPlaced())
        {
            GameEnded();
        }

        selectedSquare = null;
    }
Example #5
0
    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);
    }
Example #6
0
    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);
    }
Example #7
0
    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);
    }
Example #8
0
    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);
        }
    }