示例#1
0
    /*
     * public void setAttackDistanceIndex() {
     *  int a = GameManager.Instance.getUnitPosXIndex(selectedSoldier.name);
     *  int b = GameManager.Instance.getUnitPosYIndex(selectedSoldier.name);
     *  SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent<Unit>().m_pSoldier;
     *  if (mySoldier.getAttackDistance() == 1) {
     *      if (b % 2 == 1)
     *      {
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *      }
     *      else
     *      {
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b + 1);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *      }
     *  } else if (mySoldier.getAttackDistance() == 2) {
     *      if (b % 2 == 1)
     *      {
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *          checkEnemyWithinAttackDistance(a + 2, b);
     *          checkEnemyWithinAttackDistance(a + 2,b - 1);
     *          checkEnemyWithinAttackDistance(a + 1, b - 2 );
     *          checkEnemyWithinAttackDistance(a,b-2);
     *          checkEnemyWithinAttackDistance(a-1,b-2 );
     *          checkEnemyWithinAttackDistance(a-1,b-1 );
     *          checkEnemyWithinAttackDistance(a-2,b );
     *          checkEnemyWithinAttackDistance(a-1,b+1 );
     *          checkEnemyWithinAttackDistance(a - 1,b+2 );
     *          checkEnemyWithinAttackDistance(a,b+2 );
     *          checkEnemyWithinAttackDistance(a + 1,b + 2);
     *          checkEnemyWithinAttackDistance(a + 2, b + 1);
     *
     *      }
     *      else
     *      {
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b + 1);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *          checkEnemyWithinAttackDistance(a+2, b);
     *          checkEnemyWithinAttackDistance(a+1,b-1 );
     *          checkEnemyWithinAttackDistance(a+1,b-2 );
     *          checkEnemyWithinAttackDistance(a,b-2 );
     *          checkEnemyWithinAttackDistance(a-1,b-2 );
     *          checkEnemyWithinAttackDistance(a-2,b-1 );
     *          checkEnemyWithinAttackDistance(a-2, b);
     *          checkEnemyWithinAttackDistance(a-2,b+1 );
     *          checkEnemyWithinAttackDistance(a-1,b+2 );
     *          checkEnemyWithinAttackDistance(a,b+2 );
     *          checkEnemyWithinAttackDistance(a+1, b+2);
     *          checkEnemyWithinAttackDistance(a+1, b+1);
     *      }
     *  }
     * }
     *
     *
     * void checkEnemyWithinAttackDistance(int x, int y) {
     *  int enemyXindex = GameManager.Instance.getUnitPosXIndex(preEnemyObject.name);
     *  int enemyYindex = GameManager.Instance.getUnitPosYIndex(preEnemyObject.name);
     * }
     */

    //升级,最大血量和当前血量各加5
    public void addHealth()
    {
        if (selectedSoldier.GetComponent <Unit>() == null || selectedSoldier == null)
        {
            return;
        }
        if (selectedSoldier.GetComponent <Unit>().beenUpgraded == false)
        {
            if (GameManager.Instance.getTurn() == 0)
            {
                if (selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp() > m_player1.getXP())
                {
                    return;
                }
                else
                {
                    SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent <Unit>().m_pSoldier;
                    mySoldier.modifyMaxHP(5);
                    mySoldier.modifyHP(5);
                    selectedSoldier.GetComponent <Unit>().beenUpgraded = true;
                    GameObject popText = Instantiate(floatingText, selectedSoldier.transform.position, Quaternion.identity);
                    popText.GetComponent <TextMesh>().text  = "Max HP + 5";
                    popText.GetComponent <TextMesh>().color = Color.green;
                    SoundEffectManager.Instance.playAudio(2);
                    m_player1.modifyXP(-selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp());
                }
            }
            else if (GameManager.Instance.getTurn() == 1)
            {
                if (selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp() > m_player2.getXP())
                {
                    return;
                }
                else
                {
                    SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent <Unit>().m_pSoldier;
                    mySoldier.modifyMaxHP(5);
                    mySoldier.modifyHP(5);
                    selectedSoldier.GetComponent <Unit>().beenUpgraded = true;
                    GameObject popText = Instantiate(floatingText, selectedSoldier.transform.position, Quaternion.identity);
                    popText.GetComponent <TextMesh>().text  = "Max HP + 5";
                    popText.GetComponent <TextMesh>().color = Color.green;
                    SoundEffectManager.Instance.playAudio(2);
                    m_player2.modifyXP(-selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp());
                }
            }
        }
    }