关于一道游戏笔试题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于一道游戏笔试题相关的知识,希望对你有一定的参考价值。

如何出BOSS. 每两个小时要随机出一个BOSS
提供:
  随机函数unsigned int random(void), 返回值是一正随机整数,
  取当前时间函数unsigned int GetCurTime(void), 返回值是开机到当前的秒数
  出BOSS函数NewBoss(void).
  题目是,每两个小时必定出一个,但出现的时间随机,做题时间限制十五分钟

我的答案

int number=-1;
int count=0;

void start(){
}

void update(){

    if(number==-1){
        number=this.random % 7200;
    }
    else{
        count=count+Time.deltatime;
        if(count>=7200)
        {
            number=-1;
            count=0;
        }
    }

    if(this.GetCurTime() % 7200==number)
    {
        NewBoss();
    }
}

 

以上是关于关于一道游戏笔试题的主要内容,如果未能解决你的问题,请参考以下文章