Example #1
0
    void TryToPlayCard(PointerEventData eventData)
    {
        RaycastResult raycastResult = eventData.pointerCurrentRaycast;

        List <RaycastResult> results = new List <RaycastResult>();

        raycaster.Raycast(eventData, results);

        bool validCardPosition = false;

        for (int i = 0; i < results.Count; i++)
        {
            BoardSquareGUI_canvas square = results[i].gameObject.GetComponent <BoardSquareGUI_canvas>();
            if (square && square.Owner == Owner.PLAYER)
            {
                // Ask for permission
                validCardPosition = true;
                RequestPlayCard(square.GetPositionInParent());
                break;
            }
        }

        if (!validCardPosition)
        {
            hand.RebuildLayout();
        }
    }
Example #2
0
    private void Start()
    {
        side = GetComponentInParent <SideGUI_canvas>();

        myTransform = transform;

        myTransform.DestroyAllChildren();

        for (int i = 0; i < GameConstants.NUMBER_OF_BOARD_SLOTS_PER_PLAYER; i++)
        {
            BoardSquareGUI_canvas slotGUI = Instantiate(slotPrefab, myTransform);
            slotGUI.side            = side;
            slotGUI.gameObject.name = "slot_" + i;
        }

        // Callbacks
        HandController hand = FindObjectOfType <HandController>();

        if (side.owner == Owner.PLAYER)
        {
            hand.OnPlayerPlayedCard += PlayerPlayedCard;
        }
        else if (side.owner == Owner.ENEMY)
        {
            hand.OnEnemyPlayedCard += EnemyPlayedCard;
        }
        else
        {
            Debug.LogError("Who are you?");
        }
    }
Example #3
0
    void EnemyPlayedCard(string cardId, int squarePosition)
    {
        // mirrored!
        squarePosition = transform.childCount - 1 - squarePosition;
        BoardSquareGUI_canvas square = GetSquareAtPosition(squarePosition);

        square.TakeUp(cardId);
    }
Example #4
0
    void PlayerPlayedCard(int response, string cardId, int cardPositionInHand, int squarePosition)
    {
        if (response == Responses.CARD_PLAYED_FAILED)
        {
            return;
        }

        BoardSquareGUI_canvas square = GetSquareAtPosition(squarePosition);

        square.TakeUp(cardId);
    }