Exemplo n.º 1
0
    /*
     * memulai giliran
     */
    public IEnumerator StartTurn()
    {
        /*
         * delay beberapa ms sebelum player dapat mengocok dadu
         */
        yield return(new WaitForSeconds(0.7f));

        Token.TokenPlayer tokenPlayer = GetCurrentTokenPlayer();
        highlighter.StopHighlight();
        highlighter.Highlight(GetCurrentTokenType());

        diceManager.ShowDice(GetCurrentTokenType());
        dice = diceManager.GetCurrentActiveDice();

        if (tokenPlayer == Token.TokenPlayer.Human)
        {
            /*
             * aktifkan dadu agar user dapat menyentuh/berinteraksi dengan dadu tsb
             */
            dice.EnableUserInteraction = true;
        }
        else if (tokenPlayer == Token.TokenPlayer.Computer)
        {
            /*
             * delay beberapa ms sebelum AI mengocok dadu
             */
            yield return(new WaitForSeconds(0.7f));

            dice.EnableUserInteraction = false;

            opponentCtrl.StartTurn(GetCurrentTokenType());
        }
    }
Exemplo n.º 2
0
    public void OnPlay()
    {
        Token.TokenPlayer[] players = new Token.TokenPlayer[playerCount];
        Token.TokenType[]   types   = new Token.TokenType[playerCount];

        for (int i = 0; i < playerCount; i++)
        {
            players [i] = Token.TokenPlayer.Computer;
            types [i]   = (Token.TokenType)i;

            if (types [i] == selectedToken)
            {
                players [i] = Token.TokenPlayer.Human;
            }
        }

        if ((int)selectedToken >= playerCount)
        {
            players [playerCount - 1] = Token.TokenPlayer.Human;
            types [playerCount - 1]   = selectedToken;
        }

        GameMaster gm = GameMaster.instance;

        gm.SelectedTokens       = types;
        gm.SelectedTokenPlayers = players;

        SceneManager.LoadScene("GamePlay");
    }
Exemplo n.º 3
0
    /*
     * method callback. akan dipanggil ketika dadu selesai dikocok
     * oleh DiceManager
     */
    public void DiceRolled(int diceNum, Token.TokenType type)
    {
        if (diceNum == 6)
        {
            diceSixCount++;
            if (diceSixCount >= 3)
            {
                dice.EnableUserInteraction = false;
                diceSixCount = 0;

                if (onSixThreeTimes != null)
                {
                    onSixThreeTimes(GetCurrentTokenType());
                }

                NextTurn();
                StartCoroutine(StartTurn());
                return;
            }
        }

        lastDiceNum = diceNum;
        Token.TokenPlayer player        = GetCurrentTokenPlayer();
        List <Token>      movableTokens = tokenManager.GetMovableTokens(GetCurrentTokenType(), diceNum);

        if (diceNum != 6 && movableTokens.Count <= 0)
        {
            NextTurn();
            StartCoroutine(StartTurn());
            return;
        }

        if (player == Token.TokenPlayer.Human)
        {
            dice.EnableUserInteraction = false;

            if (movableTokens.Count == 1)
            {
                if (!movableTokens [0].MoveToken(diceNum))
                {
                    NextTurn();
                    StartCoroutine(StartTurn());
                }
            }
            else if (movableTokens.Count > 1)
            {
                for (int i = 0; i < movableTokens.Count; i++)
                {
                    movableTokens [i].SelectionMode = true;
                }
            }
        }
        else if (player == Token.TokenPlayer.Computer)
        {
            opponentCtrl.Play(diceNum);
        }
    }
Exemplo n.º 4
0
    void CreateTokens(Token.TokenType tokenType, Token.TokenPlayer playerType)
    {
        Transform[]      homeBase    = null;
        GameObject       tokenPrefab = null;
        List <Transform> waypoint    = null;

        switch (tokenType)
        {
        case Token.TokenType.Blue:
            homeBase    = homeBaseManager.BlueHomeBase;
            tokenPrefab = playerBluePrefab;
            waypoint    = waypointManager.BlueWaypoints;
            break;

        case Token.TokenType.Red:
            homeBase    = homeBaseManager.RedHomeBase;
            tokenPrefab = playerRedPrefab;
            waypoint    = waypointManager.RedWaypoints;
            break;

        case Token.TokenType.Green:
            homeBase    = homeBaseManager.GreenHomeBase;
            tokenPrefab = playerGreenPrefab;
            waypoint    = waypointManager.GreenWaypoints;
            break;

        case Token.TokenType.Yellow:
            homeBase    = homeBaseManager.YellowHomeBase;
            tokenPrefab = playerYellowPrefab;
            waypoint    = waypointManager.YellowWaypoints;
            break;
        }

        Token[] currTokens = new Token[homeBase.Length];
        tokens.Add(tokenType, currTokens);
        for (int i = 0; i < homeBase.Length; i++)
        {
            GameObject newTokenGO = Instantiate(tokenPrefab, homeBase [i].position, Quaternion.identity);
            Token      token      = newTokenGO.GetComponent <Token> ();
            token.SetupWaypoints(waypoint, homeBase[i]);
            token.Player = playerType;

            currTokens [i] = token;
        }
    }