本文整理汇总了C++中Snake::createnode方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::createnode方法的具体用法?C++ Snake::createnode怎么用?C++ Snake::createnode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::createnode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fun_snake_game
void fun_snake_game(void) {
srand((unsigned int)time(NULL));
Uint8 r=(rand()%0xFF);
Uint8 g=(rand()%0xFF);
Uint8 b=(rand()%0xFF);
Snake S;
int d=-1;
SDL_Event e;
Uint32 ticks;
while(1) {
ticks=SDL_GetTicks();
SDL_RenderClear(gRenderer);
SDL_SetRenderDrawColor(gRenderer, r, g, b, 0xFF);
while(SDL_PollEvent(&e)) {
if(e.type==SDL_QUIT) {
exit(0);
}
else if(e.type==SDL_KEYDOWN && e.key.repeat==0) {
switch(e.key.keysym.sym) {
case SDLK_ESCAPE:
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
return;
case SDLK_UP:
d=UP;
break;
case SDLK_DOWN:
d=DOWN;
break;
case SDLK_RIGHT:
d=RIGHT;
break;
case SDLK_LEFT:
d=LEFT;
break;
}
if(diff(S.getfdir(), d)!=2 && d!=S.getfdir()) {
S.createnode(d);
}
}
}
S.movesnake();
S.render();
if(S.getcoll()) {
SDL_Delay(TIMEOUT_LONG);
SDL_RenderClear(gRenderer);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
wait();
return;
}
SDL_RenderPresent(gRenderer);
while(SDL_GetTicks()-ticks<16) {
SDL_Delay(1);
}
}
}