Example #1
0
    private void BoatBankToggleHandler()
    {
        Vector3Int boatState    = new Vector3Int(0, 0, 1);
        Dropzone   nextDropzone = (boat.onLeftBank) ? leftBank : rightBank;

        int childCount = boat.transform.childCount;
        List <Interactable> children = new List <Interactable>();

        for (int i = 0; i < childCount; i++)
        {
            Interactable interactable = boat.transform.GetChild(i).GetComponent <Interactable>();

            if (interactable.interactableType == Interactable.InteractableType.Missionary)
            {
                boatState += new Vector3Int(1, 0, 0);
            }
            else if (interactable.interactableType == Interactable.InteractableType.Cannibal)
            {
                boatState += new Vector3Int(0, 1, 0);
            }

            children.Add(interactable);
        }

        for (int i = 0; i < children.Count; i++)
        {
            nextDropzone.AddItem(children[i].gameObject);
            children[i].dropzone = boat.GetComponent <Dropzone>();
        }

        if (boat.onLeftBank)
        {
            currentState = currentState.AddState(boatState);
        }
        else
        {
            currentState = currentState.SubtractState(boatState);
        }

        bool isValid = currentState.IsValid(initalState);

        Debug.Log("Current State: " + currentState.ToString() + " isValid: " + isValid.ToString());

        if (!isValid)
        {
            Dropzone killzone = (currentState.x < currentState.y) ? leftBank : rightBank;
            KillMissonaries(killzone);
            ShowGameOver(isValid);
        }
        else if (currentState == goalState)
        {
            ShowGameOver(isValid);
        }
    }