Ejemplo n.º 1
0
    void Update()
    {
        if (animMan.isPlayingAnim() && !animMan.getKO())           // Both characters must be in idle
        {
            if ((Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.RightArrow)) ||
                (Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.LeftArrow)) ||
                (Input.GetKeyDown(KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.RightArrow)) ||
                (Input.GetKeyDown(KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.LeftArrow))) // All possible movements
            {
                Debug.Log(IA.PrintTablesData());                                              // Prints the table (messages in log)

                // Get movement having in mind the inputs
                if (Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.RightArrow))
                {
                    playerOption = Movements.AttackMedium;
                }
                else if (Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    playerOption = Movements.DefenseMedium;
                }
                else if (Input.GetKeyDown(KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.RightArrow))
                {
                    playerOption = Movements.AttackLow;
                }
                else
                {
                    playerOption = Movements.DefenseLow;
                }

                totalMovements++;

                // IA movement
                IAOption = IA.nextMove();

                // Activate animations of movements
                animMan.launchRyuAnim(this.playerOption);
                animMan.launchKenAnim(IAOption);

                MatchStateText.text = "La IA selecciona: " + IAOption + "\n";

                // Victory condition IA
                if (VictoryCondition(IAOption, playerOption))
                {
                    // Ken
                    animMan.launchRyuKO(true);
                    MatchStateText.text += "¡La IA ha ganado!\n";
                    IAWin++;
                }
                // Victory condition Player
                else if (VictoryCondition(playerOption, IAOption))
                {
                    // Ryu
                    animMan.launchKenKO(true);
                    MatchStateText.text += "¡La IA ha perdido!\n";
                    playerWin++;
                }
                // Double KO
                else if (LoseCondition(IAOption, playerOption))
                {
                    animMan.doubleKO(true);
                    MatchStateText.text += "¡Doble KO!\n";
                }
                else                 // Tie
                {
                    MatchStateText.text += "¡Empate!\n";
                }

                MatchStateText.text += "Tasa de victoria: " + (100 * (float)IAWin / totalMovements) + "%\n";
                MatchStateText.text += "Tasa de derrota: " + (100 * (float)playerWin / totalMovements) + "%\n";

                WinStateText.text = "Player: " + playerWin + "   IA: " + IAWin + "\n" + playerOption + " VS " + IAOption;

                // Save the options
                IA.saveMovements(playerOption);
            }
        }
        else if (animMan.getKO()) // Reset the KO characters to idle
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                animMan.doubleKO(false);
            }
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (animMan.isPlayingAnim() && !animMan.getKO())           // Both characters must be in idle
        {
            if ((Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.RightArrow)) ||
                (Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.LeftArrow)) ||
                (Input.GetKeyDown(KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.RightArrow)) ||
                (Input.GetKeyDown(KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.LeftArrow))) // All possible char
            {
                Debug.Log(IA.PrintTablesData());                                              // Prints the table (messages in log)

                // Get movement having in mind the inputs
                if (Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.RightArrow))
                {
                    playerOption = "1";
                }
                else if (Input.GetKeyDown(KeyCode.UpArrow) && Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    playerOption = "3";
                }
                else if (Input.GetKeyDown(KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.RightArrow))
                {
                    playerOption = "2";
                }
                else
                {
                    playerOption = "4";
                }

                totalchar++;

                // IA movement
                IAOption = IA.nextMove();

                // Activate animations of char
                animMan.launchRyuAnim(this.playerOption);
                animMan.launchKenAnim(IAOption);

                MatchStateText.text = "La IA selecciona: " + IAOption + "\n";

                // If the IA predicts the movement correctly
                if (reverseMove(IAOption) == playerOption)
                {
                    IAAccuracy++;
                }

                // Victory condition IA
                if (VictoryCondition(IAOption, playerOption))
                {
                    // Ken
                    animMan.launchRyuKO(true);
                    MatchStateText.text += "¡La IA ha ganado!\n";
                    IAWin++;
                }
                // Victory condition Player
                else if (VictoryCondition(playerOption, IAOption))
                {
                    // Ryu
                    animMan.launchKenKO(true);
                    MatchStateText.text += "¡La IA ha perdido!\n";
                    playerWin++;
                }
                // Double KO
                else if (LoseCondition(IAOption, playerOption))
                {
                    animMan.doubleKO(true);
                    MatchStateText.text += "¡Doble KO!\n";
                }
                else                 // Tie
                {
                    MatchStateText.text += "¡Empate!\n";
                }

                MatchStateText.text += "Tasa de detección victoriosa: " + (100 * (float)IAAccuracy / totalchar) + "%\n";

                WinStateText.text  = "Player: " + playerWin + "   IA: " + IAWin + "\n";
                WinStateText.text += selectedMove(playerOption) + " VS " + selectedMove(IAOption);

                // Save the options
                IA.savechar(playerOption);
            }
        }
        else if (animMan.getKO()) // Reset the KO characters to idle
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                animMan.doubleKO(false);
            }
        }
    }