本文整理汇总了C++中Tetris::play方法的典型用法代码示例。如果您正苦于以下问题:C++ Tetris::play方法的具体用法?C++ Tetris::play怎么用?C++ Tetris::play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tetris
的用法示例。
在下文中一共展示了Tetris::play方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]){
try {
setWorkdir();
Tetris tetris;
tetris.play();
}
catch (TetrisException& e) {
std::cerr << "Tetris exception occured:\n" << e.what();
}
catch (std::exception& e){
std::cerr << "Standard exception occured: \n" << e.what();
}
}
示例2: main
int main() {
stringstream score;
SDL_Surface * screen = 0;
bool running = true;
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE | SDL_DOUBLEBUF);
TTF_Font * font = TTF_OpenFont("Bandal.ttf", 28);
if(font == NULL){
cout << "Impossibile caricare il font : "<<SDL_GetError()<<endl;
exit(1);
}
Tetris * game = new Tetris();
SDL_Surface * bg = loadbg("black_background.bmp");
SDL_Event * event = new SDL_Event();
while(!game->getEnd() && running){
while(SDL_PollEvent(event)){
if(event->type == SDL_QUIT)
running = false;
if(event->type == SDL_KEYDOWN){
if(event->key.keysym.sym == SDLK_SPACE){
game->setDirection(4);
}
if(event->key.keysym.sym == SDLK_RIGHT){
game->setDirection(1);
}
if(event->key.keysym.sym == SDLK_LEFT){
game->setDirection(2);
}
if(event->key.keysym.sym == SDLK_DOWN){
game->setDirection(3);
}
}
if(event->type == SDL_KEYUP){
if(event->key.keysym.sym == SDLK_DOWN){
game->setDirection(3);
}
}
}
SDL_BlitSurface(bg, NULL, screen, NULL);
game->play();
game->draw(screen);
score.str("");
score << "Score : "<<game->getPoints();
putstring(screen, font, score.str().c_str(), 0,0,0xff,0xff,0xff);
if(SDL_Flip(screen) == -1)
return 1;
SDL_Delay(10);
}
delete game;
TTF_CloseFont(font);
TTF_Quit();
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}