private int GetScoreOfChosenWay(ChosenWayToPlay wayToPlay)
        {
            int score = 0;

            // If history has no domino
            if (history.horizontalDominoes.Count == 0)
            {
                if (wayToPlay.chosenDomino.direction == DominoController.Direction.Horizontal)
                {
                    int value = wayToPlay.chosenDomino.leftValue + wayToPlay.chosenDomino.rightValue;
                    score = (value % 5 == 0) ? value : 0;
                }
                else
                {
                    int value = wayToPlay.chosenDomino.upperValue + wayToPlay.chosenDomino.lowerValue;
                    score = (value % 5 == 0) ? value : 0;
                }
                return(score);
            }
            // Else that history has at least 1 domino
            DominoController  copiedDomino  = Instantiate <DominoController>(wayToPlay.chosenDomino);
            HistoryController copiedHistory = Instantiate <HistoryController>(history);

            // Simulate to place a domino and then calculate the sum
            PlaceDomino(copiedDomino, wayToPlay.chosenPlace, copiedHistory);
            copiedHistory.Add(copiedDomino, wayToPlay.chosenPlace);
            score = Utility.GetSumOfHistoryDominoes(copiedHistory.horizontalDominoes, copiedHistory.verticalDominoes, copiedHistory.spinner);
            score = score % 5 == 0 ? score : 0;
            Destroy(copiedDomino.gameObject);
            Destroy(copiedHistory.gameObject);
            return(score);
        }
Exemplo n.º 2
0
    public void PlayerPlayDomino(PlayerController player, DominoController domino, DominoController anotherDomino)
    {
        Assert.IsNotNull(player);
        Assert.IsNotNull(domino);

        if (player == player1)
        {
            isPlayer1Blocked = false;
        }
        else
        {
            isPlayer2Blocked = false;
        }
        // Put the played domino into history
        history.Add(domino, anotherDomino);
        // Calculate the score of current play
        ScoreByCurrentPlay(player);

        if (scoreOfPlayer1 >= MaxScore || scoreOfPlayer2 >= MaxScore)
        {
            ShowPlayerWin();
            if (Round <= TestTimes)
            {
                Rounds.text = "Round:" + Round;
                if (scoreOfPlayer1 >= scoreOfPlayer2)
                {
                    if (Round < TestTimes / 2)
                    {
                        P1count++;
                    }
                    else
                    {
                        P1count2++;
                    }
                    P1Wins.text = "Player1 Wins:" + P1count + "," + P1count2;
                }
                else
                {
                    if (Round < TestTimes / 2)
                    {
                        P2count++;
                    }
                    else
                    {
                        P2count2++;
                    }
                    P2Wins.text = "Player2 Wins:" + P2count + "," + P2count2;
                }
                Round = Round + 1;
                PlayAgainButtonOnClick();
                return;
            }
            else
            {
                playAgainButton.gameObject.SetActive(true);
                mainMenuButton.gameObject.SetActive(true);
                return;
            }
        }

        // Ending a hand
        if (player.dominoControllers.Count == 0)
        {
            UpdateTurnText(player);
            // Calculate the score by ending a hand
            if (player == player1)
            {
                ScoreByEndingHand(player, GetSumOfDominoInHand(player2));
            }
            else
            {
                ScoreByEndingHand(player, GetSumOfDominoInHand(player1));
            }
            if (scoreOfPlayer1 >= MaxScore || scoreOfPlayer2 >= MaxScore)
            {
                ShowPlayerWin();
                if (Round <= TestTimes)
                {
                    Rounds.text = "Round:" + Round;
                    if (scoreOfPlayer1 >= scoreOfPlayer2)
                    {
                        if (Round < TestTimes / 2)
                        {
                            P1count++;
                        }
                        else
                        {
                            P1count2++;
                        }
                        P1Wins.text = "Player1 Wins:" + P1count + "," + P1count2;
                    }
                    else
                    {
                        if (Round < TestTimes / 2)
                        {
                            P2count++;
                        }
                        else
                        {
                            P2count2++;
                        }
                        P2Wins.text = "Player2 Wins:" + P2count + "," + P2count2;
                    }
                    Round = Round + 1;
                    PlayAgainButtonOnClick();
                    return;
                }
                else
                {
                    playAgainButton.gameObject.SetActive(true);
                    mainMenuButton.gameObject.SetActive(true);
                    return;
                }
            }
            ResetHand();
            StartHand(player);
            return;
        }
        // Or ending a turn
        if (player.playerName == player1.playerName)
        {
            UpdateTurnText(player2);
            player2.PlayDomino();
        }
        else
        {
            UpdateTurnText(player1);
            player1.PlayDomino();
        }
    }