本文整理汇总了C++中Snake::displWelcome方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::displWelcome方法的具体用法?C++ Snake::displWelcome怎么用?C++ Snake::displWelcome使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::displWelcome方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
time_t t1, t2;
double dur;
dir_t dir, tempDir;
bool receivedDir = false;
int speed = 100; //default speed
if (argc >= 2) //if user gives a more preferred speed (as command-libne arg), we use that.
{
if (isdigit(argv[1][0])) //but only if it is a digit
speed = atoi(argv[1]);
}
Snake* pSnake = new Snake(speed);
time(&t1); //get current time
while (true) //show welcome message for 5 seconds
{
time(&t2);
dur = difftime(t2, t1); //calculate difference
if (dur >= 5) // <-- that is the magic 5 :D
break;
pSnake->displWelcome((int)5-dur); //display welcome message with remaining time
}
pSnake->displ(); //display the (inital)snake
time(&t1);
while (true) //the main game loop
{
receivedDir = false;
// we get <pSnake->speed> milliseconds of frametime (ncurses timeout is set to 1ms)
for (int i = 0; i < pSnake->speed; i++) // this might seem weird ("Why not just a simple time delay? wtf..")
{ // but I had problems with <sys/time>::gettimeofday()
// so its curses' delay doing the job..
tempDir = pSnake->getdir(); //get input
if (tempDir != DIR_VOID) //if no input was received, we keep the previous direction.
{
receivedDir = true; //we have received input, so DIR_VOID has no power anymore
dir = tempDir; //
}
}
if (receivedDir) //if we received input..
pSnake->curDir = dir; //..we set the new direction as the current one
//time to move the snake and do other thingys!
if (pSnake->move(dir) == INTERSECT) //interscetion -> game over
{
pSnake->gameOver();
delete pSnake;
return 0;
}
pSnake->displ(); //re-render the snake
}
return 0;
}