September 2018
Intermediate to advanced
328 pages
9h 10m
English
The first section of code defines the actions to perform when the class instance is loaded (constructor) and unloaded (destructor):
#include <cstdlib>#include <iostream>#include <stdexcept>#include "game.h"using namespace std;using namespace Constants;Game::Game() : // Create a new random piece: piece_{ static_cast<Piece::Kind>(rand() % 7) }, moveTime_(SDL_GetTicks()){ if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw runtime_error( "SDL_Init(SDL_INIT_VIDEO): " + string(SDL_GetError())); } SDL_CreateWindowAndRenderer( BoardWidth, ScreenHeight, SDL_WINDOW_OPENGL, &window_, &renderer_); SDL_SetWindowPosition( window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_SetWindowTitle(window_, "Tetris"); if (TTF_Init() ...Read now
Unlock full access