• 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;
    }
  • 相关阅读:
    Codefroces 920F SUM and REPLACE(线段树)
    POJ 2155 Matrix (2维树状数组)
    POJ 3067 Japan (树状数组求逆序对)
    Codeforces 919D Substring (拓扑排序+树形dp)
    拓扑排序
    Codeforces 889F Letters Removing(二分 + 线段树 || 树状数组)
    线段树扫描线(2---算矩形的相交面积)
    线段树扫描线(1---算矩形的总面积)
    hdu 6168 Numbers
    Educational Codeforces Round 27 A B C
  • 原文地址:https://www.cnblogs.com/liuzc/p/6532915.html
Copyright © 2020-2023  润新知