diff --git a/tetris.cpp b/tetris.cpp index e3d6c46..74a4d3c 100644 --- a/tetris.cpp +++ b/tetris.cpp @@ -37,7 +37,7 @@ bool is_valid_move() { } void stack_piece() { - if (piece_pos.y==0) exit(0); + if (piece_pos.y==0) { state=STATE_ENNERYORNEIM; return; }; int x = piece_pos.x+3, y = piece_pos.y+3; Uint16 piece = tetromino[current_piece].figure; for (int i=0; i<16; i++) { @@ -128,7 +128,7 @@ void doGame() { void doMenu() { while(SDL_PollEvent(&sdlEvent)) { if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; } - if (sdlEvent.type == SDL_KEYDOWN) { + if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) { level=score=lines=0; current_piece = starting[rand()%7]; next_piece = starting[rand()%7]; @@ -162,6 +162,40 @@ void doMenu() { SDL_RenderPresent(sdlRenderer); } +char initials[4]={"AAA"}; +int pos =0; +void doEnd() { + while(SDL_PollEvent(&sdlEvent)) { + if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; } + if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) { + if (sdlEvent.key.keysym.scancode>=SDL_SCANCODE_A && sdlEvent.key.keysym.scancode<=SDL_SCANCODE_0) { + if (sdlEvent.key.keysym.scancode<=SDL_SCANCODE_Z) { + initials[pos] = sdlEvent.key.keysym.scancode+61; + } else if (sdlEvent.key.keysym.scancode0 && (jscore::getNumUsers()<10 || score>jscore::getPoints(jscore::getNumUsers()-1))) { + print(40, 150, "CONGRATULATIONS", 1); + print(40, 180, "ENTER YOU NAME", 2); + print(40, 250, initials, 3); + } + + SDL_RenderPresent(sdlRenderer); +} + int main(int argc, char* argv[]) { srand(time(NULL)); current_piece = starting[rand()%7]; @@ -181,6 +215,7 @@ int main(int argc, char* argv[]) { doGame(); break; case STATE_ENNERYORNEIM: + doEnd(); break; }; }