Skip to content

Commit

Permalink
fixing new bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-debbech authored Aug 19, 2019
1 parent ff8409e commit f4f57e0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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();
Expand Down
31 changes: 26 additions & 5 deletions store.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f4f57e0

Please sign in to comment.