From f4f57e0c5744d1aeda0f257b55068d48aecbab0f Mon Sep 17 00:00:00 2001 From: Ahmed Debbech <31746542+ahmed-debbech@users.noreply.github.com> Date: Mon, 19 Aug 2019 18:51:20 +0100 Subject: [PATCH] fixing new bugs --- main.c | 13 ++++++++++--- store.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index d287511..49ad1a6 100644 --- a/main.c +++ b/main.c @@ -14,19 +14,23 @@ #include "store.h" #include "core.h" int main(int argc, char **argv){ +// this do-while loop is for checking if theme has been changed then the game should restart itself +int themeChanged = 0; +SDL_Surface *screen; +Mix_Music * music; + do{ //core initializations char m[3][3]; //main game table containing Xs and Os int td[3][3]; //defence table int ta[3][3]; // attack table computerEnteries ce; //graphics initializations -SDL_Surface *screen; -Mix_Music * music; SDL_Event event; menu mc; int scoreComputer=0, scorePlayer=0, whichMode = 0; int scorePlayer1 = 0, scorePlayer2=0; int played_once = 0; +themeChanged = 0; playgameScreen pgs; about ab; help hel; @@ -375,7 +379,8 @@ while(menuNotOver == 1){ SDL_BlitSurface(restart, NULL, screen, &rest); SDL_Flip(screen); SDL_FreeSurface(restart); - SDL_Delay(5000); + SDL_Delay(4000); + themeChanged = 1; game_isnot_going = 1; } } @@ -445,8 +450,10 @@ while(menuNotOver == 1){ game_isnot_going = 1; break; } + } //end game loop +}while(themeChanged == 1); SDL_FreeSurface(screen); Mix_FreeMusic(music); SDL_Quit(); diff --git a/store.c b/store.c index d232ff5..28d6893 100644 --- a/store.c +++ b/store.c @@ -237,7 +237,7 @@ SDL_BlitSurface(value, NULL, screen, &valuePos); * @param[in] soundFX sfx the sounds that will be generated. * @param[in] control c control flag of sounds * @param[in] SDL_Surface* screen the screen to print. - * @return It returns 0 if back button clicked or any number ordered by the store items starting from 1 or -1 if nothing is clicked. + * @return It returns 0 if back button is clicked or any number ordered by the store items starting from 1 or -1 if nothing is clicked. */ int storeClicks(SDL_Event event, buttons bu, soundFX sfx, control c){ //each new store item added you should add a new condition that returns a number. @@ -287,7 +287,28 @@ int buyingManger(int itemSelected, SDL_Surface * screen){ int counter, items[10]; int buffer; FILE *f = NULL; - if(itemSelected == 1){ + //This if-switch-like structure is just to verify if a theme is already applied to not reapply it again. + f = fopen("backup/general.toe", "rb"); + char name[256]; + int x; + fread(&name, sizeof(char)*256,1, f); + if(strcmp(name, "Resources/") == 0){ + x = 1; + }else{ + if(strcmp(name, "Resources/themes/black-metal/") == 0){ + x = 2; + }else{ + if(strcmp(name, "Resources/themes/sea/") == 0){ + x = 3; + }else{ + if(strcmp(name, "Resources/themes/woody/") == 0){ + x = 4; + } + } + } + } + fclose(f); + if((itemSelected == 1) && (itemSelected != x)){ f = fopen("backup/general.toe", "rb"); char themeName[256]; fread(&themeName, sizeof(char)*256,1, f); @@ -310,7 +331,7 @@ int buyingManger(int itemSelected, SDL_Surface * screen){ items[counter] = buffer; } fclose(f); - if(itemSelected == 2){ + if((itemSelected == 2) && (itemSelected != x)){ // the x varaible is for checking that theme is not already applied if(items[1] == 0){ f = fopen("backup/tics.toe", "rb"); fread(&buffer, sizeof(int), 1, f); @@ -364,7 +385,7 @@ int buyingManger(int itemSelected, SDL_Surface * screen){ } return 1; }else{ - if(itemSelected == 3){ + if((itemSelected == 3) && (itemSelected != x)){ if(items[2] == 0){ f = fopen("backup/tics.toe", "rb"); fread(&buffer, sizeof(int), 1, f); @@ -420,7 +441,7 @@ int buyingManger(int itemSelected, SDL_Surface * screen){ } return 1; }else{ - if(itemSelected == 4){ + if((itemSelected == 4) && (itemSelected != x)){ if(items[3] == 0){ f = fopen("backup/tics.toe", "rb"); fread(&buffer, sizeof(int), 1, f);