Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        gameTextDisplay2.text = resultMessage;

        switch (state)
        {
        case States.Preparing:

            if (resultMessage == "")
            {
                gameTextDisplay1.text = "Remove your hands off the screen to start";
            }
            else
            {
                gameTextDisplay1.text = "Remove your hands off the screen to restart";
            }

            if (leap_controller_.Frame().Hands.Count == 0)
            {
                resultMessage = "";
                state         = States.Playing;
            }
            break;

        case States.Playing:
            gameTextDisplay1.text = "Now make your gestures and place your hands in the center";

            Frame    frame = leap_controller_.Frame();
            HandList hands = frame.Hands;
            if (hands.Count >= 2)
            {
                Hand firstHand  = hands[0];
                Hand secondHand = hands[1];

                Hand leftmost = frame.Hands.Leftmost;
                if (leftmost.Id != firstHand.Id)
                {
                    secondHand = firstHand;
                    firstHand  = leftmost;
                }

                float z1 = firstHand.WristPosition.z;
                float z2 = secondHand.WristPosition.z;

                int move1 = classifier.getClassification(firstHand);
                int move2 = classifier.getClassification(secondHand);


                if (move1 == -1 || move2 == -1)
                {
                    gameTextDisplay1.text = "Invalid gesture!";
                }
                else if (z1 <= playZ)
                {
                    resultMessage = "Player 1 played " + moveNames[move1 - 1] + ". Player 2 played " + moveNames[move2 - 1] + ". ";
                    state         = States.Preparing;
                    int result = mechanic.decision(move1, move2);
                    switch (result)
                    {
                    case (0):
                        resultMessage = resultMessage + "Draw!";
                        break;

                    case (1):
                        resultMessage = resultMessage + "Player 1 wins!";
                        break;

                    case (2):
                        resultMessage = resultMessage + "Player 2 wins!";
                        break;

                    default:
                        break;
                    }
                }
            }

            break;

        default:
            break;
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        gameTextDisplay2.text = resultMessage;

        switch (state)
        {
        case States.Preparing:

            if (resultMessage == "")
            {
                gameTextDisplay1.text = "Remove your hands off the screen to start";
            }
            else
            {
                gameTextDisplay1.text = "Remove your hands off the screen to restart";
            }
//			resultMessage

            if (leap_controller_.Frame().Hands.Count == 0)
            {
                resultMessage = "";
                state         = States.Playing;
                computer.transform.GetChild(computerMove).gameObject.SetActive(false);
                computer.transform.GetChild(computerMove).GetComponent <ComputerHandController>().DestroyAllHands();
                computerMove = Random.Range(0, 5);
                computer.transform.GetChild(computerMove).gameObject.SetActive(true);
            }
            break;

        case States.Playing:
            gameTextDisplay1.text = "Now make your gesture and place your hand in the center";

            Frame    frame = leap_controller_.Frame();
            HandList hands = frame.Hands;
            if (hands.Count >= 1)
            {
                Hand  firstHand = hands[0];
                float z         = firstHand.WristPosition.z;
                int   move      = classifier.getClassification(firstHand);
                if (move == -1)
                {
                    gameTextDisplay1.text = "Invalid gesture!";
                }
                else if (z <= playZ)
                {
                    resultMessage = "You played " + moveNames[move - 1] + ". Computer played " + moveNames[computerMove] + ". ";
//					gameTextDisplay.text
                    state = States.Preparing;
                    int result = mechanic.decision(move, computerMove + 1);
                    switch (result)
                    {
                    case (0):
                        resultMessage = resultMessage + "Draw!";
                        break;

                    case (1):
                        resultMessage = resultMessage + "Player wins!";
                        break;

                    case (2):
                        resultMessage = resultMessage + "Computer wins!";
                        break;

                    default:
                        break;
                    }
                }
            }

            break;

        default:
            break;
        }
    }