void GameApplication::gameLoop(){
    loadStatsFile();
    musicVolumeControl();
    while (!quit) {
        while (SDL_PollEvent(&e) != 0) {
            if (e.type == SDL_QUIT) {
                quit = true;
            }
            if (e.type == SDL_KEYDOWN) {
                if (e.key.keysym.sym == SDLK_BACKSPACE) {
                    if (board.isStarted() && !endOfTheGame()) {
                        undo();
                    }
                }
            }
            for (int i = 0; i < NUMBER_OF_BUTTON; ++i) {
                if (lockButtons) {
                    temp[2] = button[2].handleEvent(e);
                    temp[3] = button[3].handleEvent(e);
                } else {
                    temp[i] = button[i].handleEvent(e);
                }
            }
            for (int i = 0; i < NUMBER_OF_TILE * 4; i++) {
                choice = tile[i].handleEvent(e, coordI, coordJ);
                if (choice == true) {
                    mark++;
                    if (!board.pile[coordI][coordJ].empty()) {
                        takePair();
                        break;
                    } else {
                        choice = false;
                    }
                }
            }
        }

        logicButtons(temp);
        logicBoard();

        drowGame(board);
    }
}
Example #2
0
int main(int argc, char* args[]) {

    bool temp[NUMBER_OF_BUTTON] = { false };
    bool quit = false;
    SDL_Event e;

    if (!init()) {
		printf("Failed to initialize!\n");
	} else {
		if (!loadMedia()) {
			printf("Failed to load media!\n");
		} else {
            loadStatsFile();

            musicVolumeControl();

			while (!quit) {
				while (SDL_PollEvent(&e) != 0) {
					if (e.type == SDL_QUIT) {
						quit = true;
					}
					if(e.type == SDL_KEYDOWN)
					{
					    if(e.key.keysym.sym == SDLK_BACKSPACE)
                        {
                            if(board.isStarted() && !endOfTheGame())
                            {
                                undo();
                            }
                        }
					}
					for (int i = 0; i < NUMBER_OF_BUTTON; ++i) {
                        if(lockButtons)
                        {
                            temp[2] = gButton[2].handleEvent(e);
                            temp[3] = gButton[3].handleEvent(e);
                        }
                        else
                        {
                            temp[i] = gButton[i].handleEvent(e);
                        }
					}
					for (int i = 0; i < NUMBER_OF_TILE * 4; i++) {
						choice = gTile[i].handleEvent(e, coordI, coordJ);
						if (choice == true) {
                            mark++;
							if (!board.pile[coordI][coordJ].empty()) {
                                takePair();
								break;
							} else {
								choice = false;
							}
						}
					}

                }

				logicButtons(temp);
				logicBoard();

                drowGame(board);
			}
		}
	}
	close();
	return 0;
}
Example #3
0
int main(int argc, char* args[])
{

    if (!init())
    {
        printf("Failed to initialize!\n");
    }
    else
    {
        if (!loadMedia())
        {
            printf("Failed to load media!\n");
        }
        else
        {
            bool quit = false;
            SDL_Event e;
            LTexture word;
            SDL_Color textColor = { 0, 0, 0, 255 };
            std::stringstream timeText;
            LButton* ptrButton[NUMBER_OF_BUTTON];
            for (int i = 0; i < NUMBER_OF_BUTTON; ++i)
            {
                ptrButton[i] = &gButton[i];
            }

            bool temp[NUMBER_OF_BUTTON] = { false };

            while (!quit)
            {
                while (SDL_PollEvent(&e) != 0)
                {
                    if (e.type == SDL_QUIT)
                    {
                        quit = true;
                    }
                    for (int i = 0; i < NUMBER_OF_BUTTON; ++i)
                    {
                        temp[i] = ptrButton[i]->handleEvent(e);
                    }

                    for (int i = 0; i < NUMBER_OF_TILE * 4; i++)
                    {
                        gTile[i].handleEvent(e);
                    }

                    //Handle window events
                    gWindow.handleEvent(e);
                    if (gWindow.isMinimized())
                    {
                        gTimer.pause();
                    }
                    else
                    {
                        gTimer.unpause();
                    }
                }

                logicButtons(temp);



//                for (int i = 0; i < 5; ++i){
//                    for (int g = 0; g < 6; ++g){
//                        board.unblock(i, g);
//                    }
//                }
//                for (int i = 0; i < 5; ++i){
//                    for (int g = 0; g < 6; ++g){
//                        board.unblock(i, g);
//                    }
//                }

                if (!gWindow.isMinimized())
                {
                    SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
                    SDL_RenderClear(gRenderer);
                    renderTexture(&gSceneTexture, 0, 0, gWindow.getWidth(),
                                  gWindow.getHeight());

                    for (int i = 0; i < NUMBER_OF_BUTTON; ++i)
                    {
                        ptrButton[i]->setPosition(650, 50 + 40 * i);
                        ptrButton[i]->renderButton();
                    }
                    timeText.str("");
                    timeText << "Time: " << std::fixed << std::setprecision(1)
                             << (gTimer.getTicks() / 1000.f);
                    //Render text
                    if (!word.loadFromRenderedText(timeText.str().c_str(),
                                                   textColor))
                    {
                        printf("Unable to render time texture!\n");
                    }
                    word.render(20, 550);



                    if (gPtrHelp == NULL)
                    {
                        if (board.isStarted())
                        {
                            drowGame(board);
                        }

                    }

                    else
                    {
                        gPtrHelp->render(25, 50);
                    }

                    SDL_RenderPresent(gRenderer);
                }
            }
        }
    }
    close();
    return 0;
}