Exemplo n.º 1
0
    private void SelectChessman(int x, int y)
    {
        if (Chessman[x, y] == null)
        {
            return;                                 // No chessman at that hit point
        }
        if (Chessman[x, y].isWhite != isWhiteTurn)
        {
            return;                                                // Not white team at first move
        }
        bool hasAtLeastOneMove = false;

        allowedMove = Chessman[x, y].PossibleMove();
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (allowedMove [i, j])
                {
                    hasAtLeastOneMove = true;
                }
            }
        }

        if (!hasAtLeastOneMove)
        {
            return;
        }

        selectedChessman        = Chessman[x, y];
        previousMat             = selectedChessman.GetComponentInChildren <MeshRenderer>().material;
        selectedMat.mainTexture = previousMat.mainTexture;
        selectedChessman.GetComponentInChildren <MeshRenderer>().material = selectedMat;
        BoardHighlight.Instance.HighlightAllowedMoves(allowedMove);
    }
Exemplo n.º 2
0
    private void ActivateChessman()
    {
        if (selectedChessman == null)
        {
            return;
        }

        if (selectedChessman.isWhite != isWhiteTurn)
        {
            selectedChessman = null;
            return;
        }

        /*bool hasAtleastOneMove = false;
         *      allowedMoves = selectedChessman.PossibleMove ();
         *      for (int i = 0; i < 8; i++)
         *              for (int j = 0; j < 8; j++)
         *                      if (allowedMoves [i, j])
         *                              hasAtleastOneMove = true;
         *
         *      if (!hasAtleastOneMove)
         *              return;
         */

        //selectedChessman = Chessmans [x, y];
        previousMat             = selectedChessman.GetComponentInChildren <MeshRenderer> ().material;
        selectedMat.mainTexture = previousMat.mainTexture;
        selectedChessman.GetComponentInChildren <MeshRenderer> ().material = selectedMat;
        //BoardHighlights.Instance.HighlightAllowedMoves (allowedMoves);
    }
Exemplo n.º 3
0
    public void playerChessHitEnemy(Chessman OverlappingChessman)
    {
        inAttack          = true;
        playerHitChessman = OverlappingChessman;
        selectedChessman.GetComponentInChildren <Animator>().SetTrigger("onAttack"); //SetTrigger在Animator是指提取Animator當中的變數。

        switch (selectedChessman.id)
        {
        case 0:
            audioEffectScript.instance.attackBoy();
            break;

        case 2:
            audioEffectScript.instance.attackGirl();
            break;

        case 7:
            audioEffectScript.instance.attackBoy();
            break;

        case 8:
            break;
        }

        selectedChessman.curActionVal--;
        gameController.instance.thisRoundsPlayerTakeSp = 1;
        gameView.instance.updateActonDisplay();
        return;
    } //角色攻擊敵人
Exemplo n.º 4
0
    } //檢查角色是否重疊

    public void OnPlayerFinishAttack()
    {
        if (selectedChessman.CurrentX == playerHitChessman.CurrentX + 1 && selectedChessman.CurrentY == playerHitChessman.CurrentY)
        {
            playerHitChessman.gameObject.transform.rotation = Quaternion.Euler(0, 270, 0);
        }
        else if (selectedChessman.CurrentX == playerHitChessman.CurrentX - 1 && selectedChessman.CurrentY == playerHitChessman.CurrentY)
        {
            playerHitChessman.gameObject.transform.rotation = Quaternion.Euler(0, 90, 0);
        }
        else if (selectedChessman.CurrentX == playerHitChessman.CurrentX && selectedChessman.CurrentY == playerHitChessman.CurrentY + 1)
        {
            playerHitChessman.gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
        }
        else if (selectedChessman.CurrentX == playerHitChessman.CurrentX && selectedChessman.CurrentY == playerHitChessman.CurrentY - 1)
        {
            playerHitChessman.gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
        }
        playerHitChessman.GetComponentInChildren <Animator>().SetTrigger("onAttack");
    } //當角色完成攻擊
Exemplo n.º 5
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMove[x, y])
        {
            Chessman c = Chessman [x, y];

            if (c != null && c.isWhite != isWhiteTurn)             /* there is an enemy that can be captured */
            {
                // Capture a piece

                // If it is the King
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    NewGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            if (x == EnPassantMove[0] && y == EnPassantMove[1])
            {
                if (isWhiteTurn)
                {
                    c = Chessman[x, y - 1];
                }
                else
                {
                    c = Chessman[x, y + 1];
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            EnPassantMove[0] = -1;             /* Reset the value first */
            EnPassantMove[1] = -1;             /* Reset the value first */
            if (selectedChessman.GetType() == typeof(Pawn))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(1, x, y);
                    selectedChessman = Chessman[x, y];
                }
                else if (y == 0)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(7, x, y);
                    selectedChessman = Chessman[x, y];
                }

                if (selectedChessman.CurrentY == 1 && y == 3)                 /* White pawn en passant move */
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y - 1;
                }
                else if (selectedChessman.CurrentY == 6 && y == 4)                 /* Black pawn en passant move */
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y + 1;
                }
            }

            Chessman[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; // set the start position to null
            selectedChessman.transform.position = GetTileCenter(x, y);             // move that selected chessman to the new position
            selectedChessman.SetPosition(x, y);
            Chessman[x, y] = selectedChessman;                                     // store new position value in the script
            isWhiteTurn    = !isWhiteTurn;
        }

        selectedChessman.GetComponentInChildren <MeshRenderer>().material = previousMat;
        BoardHighlight.Instance.HideHighLight();
        selectedChessman = null;         // make player unselect his/her chessman
    }
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];

            if (c != null && c.isWhite != isWhiteTurn)
            {
                //Capture a piece

                //If it is the king
                if (c.GetType() == typeof(King))
                {
                    //End the game. Checkmate!!!
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            if (x == EnPassantMove[0] && y == EnPassantMove[1])
            {
                if (isWhiteTurn)
                {
                    c = Chessmans[x, y - 1];
                }

                else
                {
                    c = Chessmans[x, y + 1];
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }
            EnPassantMove[0] = -1;
            EnPassantMove[1] = -1;
            if (selectedChessman.GetType() == typeof(Pawn))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(1, x, y);
                    selectedChessman = Chessmans[x, y];
                }

                else if (y == 0)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChessman(7, x, y);
                    selectedChessman = Chessmans[x, y];
                }


                if (selectedChessman.CurrentY == 1 && y == 3)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y - 1;
                }

                else if (selectedChessman.CurrentY == 6 && y == 4)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y + 1;
                }
            }

            Chessmans [selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;
        }

        selectedChessman.GetComponentInChildren <MeshRenderer>().material = previousMat;
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }