本文整理汇总了C++中Queue::ClearQ方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::ClearQ方法的具体用法?C++ Queue::ClearQ怎么用?C++ Queue::ClearQ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::ClearQ方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc ,char* argv[]){
// freopen( "CON", "wt", stdout );
// SelfMadeBlocks(0);
GameInitial();
Sint32 key;
SDL_Event gameEvent;
MultThread = SDL_CreateThread(ThreadFunc,NULL);
AIThread = SDL_CreateThread(AIMain,NULL);
while( gameOver == false ){
//press ESC or click X to quit.
while( SDL_PollEvent(&gameEvent) != 0 ){
if ( gameEvent.type == SDL_QUIT ){
gameOver = true;
}
if ( gameEvent.type == SDL_KEYDOWN ){
if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
gameOver = true;
return 0;
}
key = gameEvent.key.keysym.sym;
if( key==SDLK_BACKSPACE ){
AIMode ^= 1;
Operation.ClearQ();
if( AIMode ){
Search();
}
}
// if( AIMode ){
// continue;
// }
switch( key ){
case SDLK_DOWN: AIPlayer.Operation.AddQ(MOVEDOWN);
break;
case SDLK_LEFT: AIPlayer.Operation.AddQ(MOVELEFT);
break;
case SDLK_RIGHT:AIPlayer.Operation.AddQ(MOVERIGHT);
break;
case SDLK_UP : AIPlayer.Operation.AddQ(ROTATE);
break;
case SDLK_TAB : AIPlayer.Operation.AddQ(TURNNEXT);
break;
}
}
}
// key = SDL_GetKeyState(NULL); //实现长按效果的第一个方法
// if( key[SDLK_DOWN] ) Operation.AddQ(MOVEDOWN);
// if( key[SDLK_LEFT] ) Operation.AddQ(MOVELEFT);
// if( key[SDLK_RIGHT] ) Operation.AddQ(MOVERIGHT);
// if( key[SDLK_UP] ) Operation.AddQ(ROTATE);
SDL_Delay(1); //减轻CPU负担
}
SDL_KillThread(MultThread);
SDL_KillThread(AIThread);
pressESCtoQuit();
return 0;
}
示例2: ThreadFunc
int ThreadFunc(void * unused){
int old_time,cur_time,x,y;
old_time = cur_time = SDL_GetTicks();
while( !gameOver ){
while( alive ){
while( !Operation.isEmpty() && alive){
EnterCriticalSection(&cs);
Operation.DeleteQ(command);
curblk.ClearCube();
switch( command ){
case MOVEDOWN: curblk.MoveDown();
break;
case MOVELEFT: curblk.MoveLeft();
break;
case MOVERIGHT:curblk.MoveRight();
break;
case ROTATE : curblk.Rotate();
break;
}
if( command == TURNNEXT ){ //有的特殊命令最好特殊处理
curblk.TurnNext();
break;
}
curblk.DrawCube();
Screen.flip();
LeaveCriticalSection(&cs);
}
cur_time = SDL_GetTicks();
SDL_Delay(1);
if( !AIMode ){
if( cur_time - old_time < 500 ) continue;
old_time = cur_time;
Operation.AddQ(MOVEDOWN);
}else{
if( cur_time - old_time < 50 ) continue;
old_time = cur_time;
x = curblk.x;
y = curblk.y;
if( BestRotate>0 ){
Operation.AddQ(ROTATE);
BestRotate -= 1;
continue;
}
if( BestPath[x][y+1] ){
Operation.AddQ(MOVEDOWN);
BestPath[x][y+1] = 0;
y += 1;
continue;
}else if( BestPath[x+1][y] ){
Operation.AddQ(MOVERIGHT);
BestPath[x+1][y] = 0;
x += 1;
continue;
}else if( BestPath[x-1][y] ){
Operation.AddQ(MOVELEFT);
BestPath[x-1][y] = 0;
x -= 1;
continue;
}
alive = 0;
}
}
while(DelLine());
Operation.ClearQ();
ShowCube();
ShowScore();
if( AIMode ) Search();
alive = 1;
}
return 0;
}