PlantsVsZombies_v2.0_2

接上。

bool plantsVsZombies(int curTime)
{
    int timeDif = curTime - sysBaseInfo.endTime;
    for(int i = 0; i < timeDif; i++)
    {
        sysBaseInfo.endTime++;
        collectSun();
        generateZombie();//优化
        attackZombie();//bug_fix
        moveZombie();
        
        if(gameOver())
        {
            return true;
        }
    }

    return false;
}

void plantSunFlower(int x, int y, int curTime)
{
    if(curTime < 0 || curTime > 40)
    {
        api_defendsys_ret(OP_E_TIME);
        return;
    }

    if(x < 0 || x > 1 || y < 0 || y > 9)
    {
        api_defendsys_ret(OP_E_INVALID_FILD_NUM);
        return;
    }

    if(plantsVsZombies(curTime))
    {
        return;
    }

    if(sysBaseInfo.sysSun < SUNFLOWER_SUN)
    {
        api_defendsys_ret(OP_E_INSUFFICIENT_SUN);
        return;
    }

    if(y == 9 || grassArray[x][y] != 0 || sysBaseInfo.sysSun < SUNFLOWER_SUN)
    {
        api_defendsys_ret(OP_E_INVALID_FILD);
        return;
    }
    else
    {
        grassArray[x][y] = SUN_FLOWER;
        sysBaseInfo.sysSun -= SUNFLOWER_SUN;//种植一颗向日葵需要花费25个阳光
        sysBaseInfo.sunflowerNum += 1;
    }
    
    api_defendsys_ret(OP_E_OP_SUCCESS);
    return;
}

void plantBeanShooter(int x, int y, int curTime)
{        
    if(curTime < 0 || curTime > 40)
    {
        api_defendsys_ret(OP_E_TIME);
        return;
    }


    if(x < 0 || x > 1 || y < 0 || y > 9)
    {
        api_defendsys_ret(OP_E_INVALID_FILD_NUM);
        return;
    }

    if(plantsVsZombies(curTime))
    {
        return;
    }

    if(sysBaseInfo.sysSun < BEANSHOOTER_SUN)
    {
        api_defendsys_ret(OP_E_INSUFFICIENT_SUN);
        return;
    }

    if(y == 9 || grassArray[x][y] != 0 || sysBaseInfo.sysSun < BEANSHOOTER_SUN)
    {
        api_defendsys_ret(OP_E_INVALID_FILD);
        return;
    }
    else
    {
        grassArray[x][y] = BEAN_SHOOTER;
        sysBaseInfo.sysSun -= BEANSHOOTER_SUN;//种植一颗豌豆射手需要花费100个阳光
        sysBaseInfo.beanshooterNum += 1;
    }
    
    api_defendsys_ret(OP_E_OP_SUCCESS);
    return;
}

void ListFildDetail(int x, int y, int curTime)
{
    if(curTime < 0 || curTime > 40)
    {
        api_defendsys_ret(OP_E_TIME);
        return;
    }

    if(x < 0 || x > 1 || y < 0 || y > 9)
    {
        api_defendsys_ret(OP_E_INVALID_FILD_NUM);
        return;
    }
    
    if(plantsVsZombies(curTime))
    {
        return;
    }
    api_defendsys_fild_info((LifeType)grassArray[x][y]);
    return;
}

void CmdLst(int lstType, int curTime)
{ 
    if(curTime < 0 || curTime > 40)
    {
        api_defendsys_ret(OP_E_TIME);
        return;
    }

    if(lstType < 0 || lstType > 3)
    {
        api_defendsys_ret(OP_E_LIST_TYPE);
        return;
    }
    
    if(plantsVsZombies(curTime))//要先于显示调用
    {
        return;
    }

    switch(lstType)
    {
        case 0:
            api_defendsys_zombie_info(sysBaseInfo.commonZombieNum, sysBaseInfo.diedCommonZombieNum, sysBaseInfo.ironZombieNum, sysBaseInfo.diedIronZombieNum);
            break;
        case 1:
            api_defendsys_beanshooter_info(sysBaseInfo.beanshooterNum, sysBaseInfo.diedBeanshooterNum);
            break;
        case 2:
            api_defendsys_sunflower_info(sysBaseInfo.sunflowerNum, sysBaseInfo.diedSunflowerNum);
            break;
        case 3:
            api_defendsys_sys_info(sysBaseInfo.sysSun, sysBaseInfo.sysGold);
            break;
        default:
            break;
    }

    return;
}
原文地址:https://www.cnblogs.com/liuzc/p/6532915.html