Пример #1
0
    void useEffect(string gamePlayed, bool won)
    {
        string json1 = File.ReadAllText(Application.dataPath + "/Effects.json");
        effect ef    = JsonUtility.FromJson <effect>(json1);

        int initialPlayerHP = playerHP;
        int initialEnemyHP  = enemyHP;

        int tempPlayerHP = playerHP;
        int tempEnemyHP  = enemyHP;

        switch (gamePlayed)
        {
        case "bomberman":
            if (won)
            {
                if (ef.bombermanDamageTurn2 == -1)
                {
                    ef.bombermanDamageTurn2 = ef.turn + 2;
                }
            }
            else
            {
                if (ef.bombermanDamageTurn1 == -1)
                {
                    ef.bombermanDamageTurn1 = ef.turn + 2;
                }
            }
            break;

        case "minesweeper":
            if (won)
            {
                tempEnemyHP -= 20 + ef.bonus1; tempPlayerHP -= 10;
            }
            else
            {
                tempPlayerHP -= 20 + ef.bonus1; tempEnemyHP -= 10;
            }
            break;

        case "Pong":
            if (won)
            {
                ef.whoReflectDamage = 1; ef.turnToReflect1 = ef.turn + 1;
            }
            else
            {
                ef.whoReflectDamage = 2; ef.turnToReflect2 = ef.turn + 1;
            }
            break;

        case "Snake":
            if (won)
            {
                ef.turnToStopPoison2 = ef.turn + 4;
            }
            else
            {
                ef.turnToStopPoison1 = ef.turn + 4;
            }
            break;

        case "SpaceInvaders":
            if (won)
            {
                ef.noInvincibleTurn1 = ef.turn + 1;
            }
            else
            {
                ef.noInvincibleTurn2 = ef.turn + 1;
            }
            break;

        case "PacMan":
            if (won)
            {
                tempPlayerHP += 10 + ef.bonus5;
            }
            else
            {
                tempEnemyHP += 10 + ef.bonus5;
            }
            break;
        }


        if (ef.turn < ef.turnToStopPoison1)
        {
            tempPlayerHP -= 5 + ef.bonus3;
        }
        else
        {
            ef.turnToStopPoison1 = -1;
        }
        if (ef.turn < ef.turnToStopPoison2)
        {
            tempEnemyHP -= 5 + ef.bonus3;
        }
        else
        {
            ef.turnToStopPoison2 = -1;
        }

        if (ef.turn == ef.bombermanDamageTurn1)
        {
            tempPlayerHP -= 35 + ef.bonus0; ef.bombermanDamageTurn1 = -1;
        }
        if (ef.turn == ef.bombermanDamageTurn2)
        {
            tempEnemyHP -= 35 + ef.bonus0; ef.bombermanDamageTurn2 = -1;
        }

        if (ef.turn < ef.noInvincibleTurn1 + ef.bonus4)
        {
            tempPlayerHP = initialPlayerHP;
        }
        else
        {
            ef.noInvincibleTurn1 = -1;
        }
        if (ef.turn < ef.noInvincibleTurn2 + ef.bonus4)
        {
            tempEnemyHP = initialEnemyHP;
        }
        else
        {
            ef.noInvincibleTurn2 = -1;
        }

        if (ef.whoReflectDamage == 1 && ef.turn == ef.turnToReflect1)
        {
            tempEnemyHP        -= (initialPlayerHP - tempPlayerHP) + ef.bonus2;
            tempPlayerHP        = initialPlayerHP;
            ef.turnToReflect1   = -1;
            ef.whoReflectDamage = 0;
        }
        if (ef.whoReflectDamage == 2 && ef.turn == ef.turnToReflect2)
        {
            tempPlayerHP       -= (initialEnemyHP - tempEnemyHP) + ef.bonus2;
            tempEnemyHP         = initialEnemyHP;
            ef.turnToReflect2   = -1;
            ef.whoReflectDamage = 0;
        }
        string json2 = JsonUtility.ToJson(ef);

        File.WriteAllText(Application.dataPath + "/Effects.json", json2);

        playerHP = tempPlayerHP;
        enemyHP  = tempEnemyHP;
        HPBar.SetHealth(playerHP);
        EHPBar.SetEHealth(enemyHP);
        HP x = new HP();

        x.playerHP = playerHP;
        x.enemyHP  = enemyHP;
        string json = JsonUtility.ToJson(x);

        File.WriteAllText(Application.dataPath + "/HPs.json", json);

        if (ef.bombermanDamageTurn1 != -1)
        {
            effectsScript.Effect1(ef.bombermanDamageTurn1 - ef.turn);
        }
        if (ef.turnToStopPoison1 != -1)
        {
            effectsScript.Effect2(ef.turnToStopPoison1 - ef.turn);
        }
        if (ef.noInvincibleTurn1 != -1)
        {
            effectsScript.Effect3(ef.noInvincibleTurn1 - ef.turn);
        }
        if (ef.whoReflectDamage == 1)
        {
            effectsScript.Effect4(true);
        }

        if (ef.bombermanDamageTurn2 != -1)
        {
            enemyEffectsScript.Effect1(ef.bombermanDamageTurn2 - ef.turn);
        }
        if (ef.turnToStopPoison2 != -1)
        {
            enemyEffectsScript.Effect2(ef.turnToStopPoison2 - ef.turn);
        }
        if (ef.noInvincibleTurn2 != -1)
        {
            enemyEffectsScript.Effect3(ef.noInvincibleTurn2 - ef.turn);
        }
        if (ef.whoReflectDamage == 2)
        {
            enemyEffectsScript.Effect4(true);
        }
    }