コード例 #1
0
    void Update()
    {
        //Cambiar estos IF por un switch (intentarlo vaya)

        if (currentPlayerHand.Count > 0 && isCardSelector)
        {
            text.text = currentPlayerHand [pointedCardIndex].getCardName();
            uiImage.gameObject.SetActive(true);

            pointedCardIndex = cardSelector.pointAtCard(cursor, currentPlayerHand, pointedCardIndex);

            selectedCardIndex = cardSelector.selectCard(CurrentPlayer, cursor, currentPlayerHand, pointedCardIndex, board);

            if (selectedCardIndex != -1)
            {
                isCardSelector  = false;
                isBoardSelector = true;
                boardCursor     = Instantiate(cursor) as GameCursor;
                currentSlot     = findFirstEmptyGrid(board);
                boardCursor.setCursorInSlot(currentSlot);
                boardCursor.showCursor(true);
                changeCursorAlfa(cursor, 0.5f);
                uiImage.gameObject.SetActive(false);
            }
        }

        else if (currentPlayerHand.Count > 0 && isBoardSelector)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                if (currentSlot.X - 1 >= 0)
                {
                    board.putCursorInPosition(boardCursor, currentSlot.X - 1, currentSlot.Y);
                    currentSlot = board.getGridSpace(currentSlot.X - 1, currentSlot.Y);
                    boardCursor.playMoveSound();
                }
            }

            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                if (currentSlot.X + 1 < board.getBoardLength())
                {
                    board.putCursorInPosition(boardCursor, currentSlot.X + 1, currentSlot.Y);
                    currentSlot = board.getGridSpace(currentSlot.X + 1, currentSlot.Y);
                    boardCursor.playMoveSound();
                }
            }

            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                if (currentSlot.Y + 1 < board.getBoardLength())
                {
                    board.putCursorInPosition(boardCursor, currentSlot.X, currentSlot.Y + 1);
                    currentSlot = board.getGridSpace(currentSlot.X, currentSlot.Y + 1);
                    boardCursor.playMoveSound();
                }
            }

            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                if (currentSlot.Y - 1 >= 0)
                {
                    board.putCursorInPosition(boardCursor, currentSlot.X, currentSlot.Y - 1);
                    currentSlot = board.getGridSpace(currentSlot.X, currentSlot.Y - 1);
                    boardCursor.playMoveSound();
                }
            }

            if (Input.GetKeyDown(KeyCode.Return))
            {
                if (!board.getGridSpace(currentSlot.X, currentSlot.Y).containsCard())
                {
                    currentPlayerHand [selectedCardIndex].transform.localPosition = new Vector3(0, 0);

                    board.putCardInPosition(currentPlayerHand [selectedCardIndex], currentSlot.X, currentSlot.Y);
                    currentPlayerHand.RemoveAt(selectedCardIndex);
                    cursor.playOkSound();

                    Destroy(boardCursor.gameObject);
                    changeCursorAlfa(cursor, 1f);

                    if (currentPlayerHand.Count > 0)
                    {
                        resetCursorPosition(CurrentPlayer, cursor, currentPlayerHand);
                    }

                    failed = false;

                    isBoardSelector = false;

                    if (currentPlayerHand.Count > 0)
                    {
                        isCardSelector = true;
                    }

                    pointedCardIndex  = 0;
                    selectedCardIndex = -1;
                }

                else
                {
                    cursor.playFailSound();
                    failed = true;
                }
            }
        }

        else if (!isCardSelector && !isBoardSelector)
        {
            cursor.showCursor(false);
            uiImage.gameObject.SetActive(false);
        }
    }