diff --git a/auto.c b/auto.c index 4308d932b32129a8096048d3e6323597be7e4319..08d880bebc78796863767b6930551d7800cab73b 100644 --- a/auto.c +++ b/auto.c @@ -1,11 +1,5 @@ -#include <SDL.h> -#include "SDL_render.h" -#include <stdlib.h> -#include <stdbool.h> - -#include "output.h" -#include "map.h" -#include "rows-h" +#include "auto.h" + // Vorbedinung: // 0 < speed < 10, 0 < width < 500, 0 < height < 100, diff --git a/auto.h b/auto.h index 3b323785f20c53f62ba69e2f967b869bb765dcdd..c443be750936ff2c379c9f6f643f7f9d152bb58c 100644 --- a/auto.h +++ b/auto.h @@ -1,26 +1,18 @@ -enum vehicle{ - car, train,boat, coin, coin_gathered -}; +#ifndef AUTO_H +#define AUTO_H +#include <SDL.h> +#include <SDL_render.h> +#include <stdlib.h> +#include <stdbool.h> +#include "output.h" +#include "map.h" +#include "rows.h" +#include "gameLoop.h" +#include "header.h" -enum color{ - red,blue,green, black -}; -//Declarations of structs -struct Car{ - enum color color; - enum vehicle type ; - int x_pos; - int width; - int height; - struct Car *next; -}; - -struct LinkedList_car{ - struct Car *head; -}; //Declarations of functions struct LinkedList_car* init_car_list( int, int,int,int,enum vehicle); @@ -33,3 +25,4 @@ void free_car(struct Row*); bool kollision(int,int); +#endif \ No newline at end of file diff --git a/charac.c b/charac.c index 6e23fbd24370b3e28e185d30f3b4f670de64fd4c..704ce89e1b430ca5692440bcef2bfd51d2d5e131 100644 --- a/charac.c +++ b/charac.c @@ -1,10 +1,5 @@ -#include <SDL.h> -#include <SDL_error.h> -#include <SDL_render.h> -#include <SDL_video.h> -#include <stdbool.h> -#include <stdio.h> -#include "header.h" + +#include "charac.h" /* Vorbedingung: Es wurde eine Taste gedrückt diff --git a/charac.h b/charac.h index 696df49b919e0f7b1174401f05e4906a550d9dfa..8e09cb6c400b3ba3f0221bed9699829a9b1c4e49 100644 --- a/charac.h +++ b/charac.h @@ -1,5 +1,26 @@ +#ifndef CHARAC_H +#define CHARAC_H + +#include <SDL.h> +#include <SDL_error.h> +#include <SDL_render.h> +#include <SDL_video.h> +#include <stdbool.h> +#include <stdio.h> +#include <SDL_ttf.h> +#include "output.h" +#include "main.h" +#include "gameLoop.h" +#include "init.h" +#include "header.h" + + + + //Declaration of functions void jump(int); -int update_character(int,SDL_Renderer*); \ No newline at end of file +int update_character(int,SDL_Renderer*); + +#endif \ No newline at end of file diff --git a/file_own.c b/file_own.c index 26b363b877065712e20e7976ca9dd9eb7b94a6ef..b5c2c36633a6e0f5bb80080d91830068b9d96224 100644 --- a/file_own.c +++ b/file_own.c @@ -1,7 +1,4 @@ -#include "header.h" -#include <stdio.h> -#include <unistd.h> -#include <errno.h> +#include "file_own.h" //V: playerhighscore exists and score.txt exists //N if playerhighscore < current score; score gets written into score txt. Else score is rewritten into file diff --git a/file_own.h b/file_own.h index 8b44c97e666ce30f0e8a611b7a24ad6fcb81ae55..69a747af0467ecaa2f6067af2b032964784f89a2 100644 --- a/file_own.h +++ b/file_own.h @@ -1,4 +1,18 @@ +#ifndef FILE_OWN_H +#define FILE_OWN_H + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include "auto.h" +#include "header.h" + + + //Declaration of functions int write_table(enum vehicle); int read_table(enum vehicle); -int reset_table(void); \ No newline at end of file +int reset_table(void); + +#endif \ No newline at end of file diff --git a/gameLoop.c b/gameLoop.c index c73dca70781422e9bdde15601cad93f02c21a7a2..8d11f28e2a50dd0cab4283b172a4e4dc0498ad7b 100644 --- a/gameLoop.c +++ b/gameLoop.c @@ -1,6 +1,5 @@ -#include "header.h" -#include <time.h> -#include <stdbool.h> +#include "gameLoop.h" + SDL_Rect *player; int playerscore; diff --git a/gameLoop.h b/gameLoop.h index 3e2abbd111550bdf4b54ce0a840dfa99757d0a8a..251c6baf239a5e0afdeb4e5efbbf0bddbe12db6f 100644 --- a/gameLoop.h +++ b/gameLoop.h @@ -1,8 +1,26 @@ +#ifndef GAMELOOP_H +#define GAMELOOP_H + +#include <SDL.h> +#include <time.h> +#include <stdbool.h> +#include <SDL_rect.h> +#include <SDL_render.h> +#include "auto.h" +#include "map.h" +#include "main.h" +#include "file_own.h" +#include "header.h" +#include "charac.h" + + extern SDL_Rect *player; -int playerscore; -int playerhighscore; +extern int playerscore; +extern int playerhighscore; //Declaration of functions -void gameLoop(enum vehicle,SDL_Renderer*); \ No newline at end of file +void gameLoop(enum vehicle,SDL_Renderer*); + +#endif \ No newline at end of file diff --git a/header.h b/header.h index 7574e8faa7372e7cceba1d48eebe45be0b8f3b58..92ece71546002314dff57ea0b4e63e310db405ac 100644 --- a/header.h +++ b/header.h @@ -1,6 +1,5 @@ -#include <SDL.h> -#include <stdbool.h> -#include <SDL_ttf.h> +#ifndef HEADER_H +#define HEADER_H #define SCREEN_WIDTH 900 #define SCREEN_HEIGHT 1000 @@ -58,63 +57,4 @@ struct LinkedList_car{ struct Car *head; }; - -//Declarations of Functions -enum vehicle startscreen(SDL_Renderer*, enum vehicle); - -struct Row* init_row(struct Row*); -struct LinkedList* init_map(enum vehicle); -int move_map(enum vehicle,int,struct LinkedList*,SDL_Renderer*); -int paste_row(SDL_Renderer*, int , enum row); -void free_map(struct LinkedList*); -int paste_score (SDL_Renderer*); -//int charac_init(SDL_Renderer*); -struct LinkedList_car* init_car_list( int, int,int,int,enum vehicle); -struct Row* grass(bool,bool,int); -struct Row* street(bool,int); -struct Row* track(int); -struct Row* water(bool,bool,int); -int paste_car(SDL_Renderer*, int, int, int, int,int,struct Car*); -int move_car(SDL_Renderer* ,struct Row*); -void free_car(struct Row*); -bool kollision(int,int); -//SDL_Rect charac_init(SDL_Renderer*); -void jump(int); -int update_character(int,SDL_Renderer*); -bool end_screen(SDL_Renderer*,enum vehicle); -int init(SDL_Renderer*); -int exitGame(SDL_Renderer*,SDL_Window* window); -void gameLoop(enum vehicle,SDL_Renderer*); -int title_screen(SDL_Renderer*); -int write_table(enum vehicle); -int read_table(enum vehicle); -int reset_table(void); - -extern TTF_Font* font; - -extern SDL_Rect *player; - -extern int playerscore; -extern int playerhighscore; - -//Declaration of Images -extern SDL_Texture *img_grassDark; -extern SDL_Texture *img_grassBright; -extern SDL_Texture *img_streetSingle; -extern SDL_Texture *img_streetMultiple; -extern SDL_Texture *img_traintrack; -extern SDL_Texture *img_waterBrightSingle; -extern SDL_Texture *img_waterBrightMultiple; -extern SDL_Texture *img_waterDarkSingle; -extern SDL_Texture *img_waterDarkMultiple; -extern SDL_Texture *img_finishlineBright; -extern SDL_Texture *img_finishlineDark; -extern SDL_Texture *img_coin; -extern SDL_Texture *img_Spielanleitung; -extern SDL_Texture *img_car_trans; -extern SDL_Texture *img_carLeft_trans; -extern SDL_Texture *img_trainR; -extern SDL_Texture *img_trainL; -extern SDL_Texture *img_plank; -extern SDL_Texture *img_duck; -extern SDL_Texture *img_3D_Duck; +#endif \ No newline at end of file diff --git a/init.c b/init.c index 66b591861e845a957341f3953dfb131f27dafae8..b64d8e79739c022dc52ca0f88f96ecd217f0b65f 100644 --- a/init.c +++ b/init.c @@ -1,5 +1,4 @@ -#include <SDL_image.h> -#include <SDL_ttf.h> +#include "init.h" SDL_Texture *img_grassDark; SDL_Texture *img_grassBright; diff --git a/init.h b/init.h index 89ffba6a6ce80e1e86a462dff7a31dc43c51b5eb..56e6784acb8890842857354b765654e9b61ab83f 100644 --- a/init.h +++ b/init.h @@ -1,3 +1,12 @@ +#ifndef INIT_H +#define INIT_H + +#include <SDL.h> +#include <SDL_image.h> +#include <SDL_ttf.h> +#include "header.h" + + //Declaration of functions int init(SDL_Renderer*); int exitGame(SDL_Renderer*,SDL_Window* window); @@ -5,7 +14,6 @@ int exitGame(SDL_Renderer*,SDL_Window* window); //Declaration of Images and Fonts extern TTF_Font* font; - extern SDL_Texture *img_grassDark; extern SDL_Texture *img_grassBright; extern SDL_Texture *img_streetSingle; @@ -25,4 +33,6 @@ extern SDL_Texture *img_trainR; extern SDL_Texture *img_trainL; extern SDL_Texture *img_plank; extern SDL_Texture *img_duck; -extern SDL_Texture *img_3D_Duck; \ No newline at end of file +extern SDL_Texture *img_3D_Duck; + +#endif \ No newline at end of file diff --git a/main.c b/main.c index 0e10c818235a9f99b7c9042b877ce5f6743764ef..44d74e36a775799a2f920ad06518055af20a0ce6 100644 --- a/main.c +++ b/main.c @@ -1,12 +1,5 @@ -#include <SDL.h> -#include <stdbool.h> -#include <time.h> -#include <stdlib.h> +#include "main.h" -#include "auto.h" -#include "menu2.h" -#include "gameLoop.h" -#include "init.h" int main(void) { @@ -65,7 +58,7 @@ int main(void) { break; } gameLoop(theme,renderer); - change_Map = end_screen(renderer); + change_Map = end_screen(renderer,theme); } diff --git a/main.h b/main.h index b397dea0af466ceffe478a4c03784cb143bab5a4..a0d35645c410e1346c0dea2504f4c0a8dbd32612 100644 --- a/main.h +++ b/main.h @@ -1,5 +1,20 @@ -#define SCREEN_WIDTH 900 -#define SCREEN_HEIGHT 1000 -#define ROW_SIZE 100 +#ifndef MAIN_H +#define MAIN_H -int main(void); \ No newline at end of file +#include <SDL.h> +#include <stdbool.h> +#include <SDL_render.h> +#include <time.h> +#include <stdlib.h> +#include <SDL_ttf.h> +#include "auto.h" +#include "menu2.h" +#include "gameLoop.h" +#include "init.h" +#include "header.h" +#include "title_screen.h" + + +int main(void); + +#endif \ No newline at end of file diff --git a/map.c b/map.c index 9282676edd9b64bdd7a7ed24abc29110bebf129e..728828fa42b115feb1669989d21bc0b7936a2498 100644 --- a/map.c +++ b/map.c @@ -1,9 +1,4 @@ -#include <stdbool.h> -#include <stdlib.h> - -#include "main.h" -#include "rows.h" -#include "auto.h" +#include "map.h" // Vorbedingung: 0 <= player->y <= 1000, 0 <= player->x <= 900 diff --git a/map.h b/map.h index 8ad59b3562e5207de515dc6435c1d1982c1654e3..1a1aca80c2a968d187083680b96c4a89736e5792 100644 --- a/map.h +++ b/map.h @@ -1,12 +1,22 @@ -//Declarations of structs +#ifndef MAP_H +#define MAP_H -struct LinkedList{ - struct Row *head; -}; +#include <stdbool.h> +#include <stdlib.h> +#include <SDL.h> +#include <SDL_render.h> +#include "auto.h" +#include "rows.h" +#include "gameLoop.h" +#include "output.h" + +#include "header.h" //Declaration of functions struct LinkedList* init_map(enum vehicle); int move_map(enum vehicle,int,struct LinkedList*,SDL_Renderer*); -void free_map(struct LinkedList*); \ No newline at end of file +void free_map(struct LinkedList*); + +#endif \ No newline at end of file diff --git a/menu.c b/menu.c index 74ce92668261e1a52da4453d9294c50dcdd1b634..4d928832f4c6fdabc88ccd7b190eda450f581dca 100644 --- a/menu.c +++ b/menu.c @@ -6,10 +6,11 @@ # include <SDL_ttf.h> # include <SDL.h> # include <stdio.h> +#include <SDL_ttf.h> /* -*/ + bool end_screen(SDL_Renderer* renderer) { if (SDL_SetRenderDrawColor(renderer,255,255,255,0) !=0) { @@ -72,4 +73,5 @@ bool end_screen(SDL_Renderer* renderer) { } return(true); } +*/ diff --git a/menu2.c b/menu2.c index 35cb683e49328c80663e96229eb4b479ff3b3064..533009e332d6c3baab255cfcfc9bfb4538b88875 100644 --- a/menu2.c +++ b/menu2.c @@ -1,11 +1,4 @@ -#include <SDL.h> -//#include "SDL_render.h" -//#include "SDL_surface.h" -#include <SDL_ttf.h> - -#include "main.h" -#include "rows.h" -#include "auto.h" +#include "menu2.h" // Die Funktion zeigt die möglichen Reihen des Spiels // Wenn man auf eine Reihe klickt, dann wir das Spiel mit einer bestimmten @@ -216,7 +209,7 @@ bool end_screen(SDL_Renderer* renderer,enum vehicle theme) { //Schriftart, -farbe und -groesse festesetzen - TTF_Font *font = TTF_OpenFont("Go-Mono.ttf", 28); + TTF_Font *font = TTF_OpenFont("images/Go-Mono.ttf", 28); if (font == NULL) { SDL_Log("Schriftart konnte nicht geladen werden! SDL_ttf Error: %s\n", TTF_GetError()); @@ -250,74 +243,6 @@ bool end_screen(SDL_Renderer* renderer,enum vehicle theme) { SDL_RenderCopy(renderer, Message, NULL, &rect); - - // Ausgabe Highscore der entsprechenden Karte - - int map = theme; - FILE *my_file; - //FILE *my_wfile = fopen("Highscore2.txt","w"); - - switch(map) { // Öffne die entsprechende Datei für den Highscore der Karte theme - case coin: - my_file = fopen("HighscoreCoin.txt","r+"); - break; - case car: - my_file = fopen("HighscoreCar.txt","r+"); - break; - case boat: - my_file = fopen("HighscoreBoat.txt","r+"); - break; - case train: - my_file = fopen("HighscoreTrain.txt","r+"); - break; - } - - bool notEOF = true; - - while (notEOF) { // Lese bis Datei leer - - char buf[64]; // initialise buffer - - size_t n = fread(buf,sizeof buf[0], sizeof buf, my_file); - //printf("n = %zu\n",n); - - if (n == 0) { - - notEOF = false; - - } else { - - //printf("Read text: \n %s\n",buf); - //fwrite(buf,sizeof buf[0], n, my_file); - // Definiere rect - - // Erstelle Rechteck für das Schreiben des Highscores - SDL_Rect rect2 = { - .x = 0, - .y = 900, - .w = 600, - .h = 200 }; - - if (SDL_RenderFillRect(renderer,&rect2)!=0) { - SDL_Log("Malen des Rechtecks fehlgeschlagen! SDL_Error %s\n",SDL_GetError()); - return(-1); - } - - SDL_Surface* surfaceMessage2 = TTF_RenderText_Blended_Wrapped (font, buf, (SDL_Color) {255, 255, 255, 255}, 200); - - if (surfaceMessage2 == NULL) - printf("Text Surface loading failed: %s\n", TTF_GetError()); - - SDL_Texture* Message2 = SDL_CreateTextureFromSurface(renderer, surfaceMessage2); - - SDL_RenderCopy(renderer, Message2, NULL, &rect2); - - } - - } - - //fclose(my_file); - SDL_Event e; int input; bool quit = false; @@ -330,7 +255,6 @@ bool end_screen(SDL_Renderer* renderer,enum vehicle theme) { while (SDL_PollEvent(&e)) { switch (e.type) { - fclose(my_file); case SDL_QUIT: exit(0); case SDL_KEYDOWN: @@ -350,7 +274,6 @@ bool end_screen(SDL_Renderer* renderer,enum vehicle theme) { } } } - fclose(my_file); return(true); } diff --git a/menu2.h b/menu2.h index 7a47f1dd3871d79753070a80f38a5888fac47b05..e8c74203e9cf85666a2c917c4db4b08e7235159b 100644 --- a/menu2.h +++ b/menu2.h @@ -1,4 +1,20 @@ +#ifndef MENU2_H +#define MENU2_H + +#include <SDL.h> +#include "SDL_render.h" +#include "SDL_surface.h" +#include <SDL_ttf.h> + +#include "main.h" +#include "rows.h" +#include "auto.h" +#include "header.h" + + //Declaration of functions bool end_screen(SDL_Renderer*,enum vehicle); -enum vehicle startscreen(SDL_Renderer*, enum vehicle); \ No newline at end of file +enum vehicle startscreen(SDL_Renderer*); + +#endif \ No newline at end of file diff --git a/output.c b/output.c index 79d7327f75c498d9ebacb22e919d16664a19b636..9960510ca9d3e8d70c2f4ad5a019f3e4de940426 100644 --- a/output.c +++ b/output.c @@ -1,13 +1,4 @@ -#include <SDL.h> -#include <stdbool.h> -#include <SDL_ttf.h> -#include <SDL_image.h> - -#include "rows.h" -#include "auto.h" -#include "main.h" -#include "init.h" -#include "gameLoop.h" +#include "output.h" int paste_row(SDL_Renderer* renderer, int y, enum row row_type){ diff --git a/output.h b/output.h index b6f3aa29a8ed0d64e09877fbac3c1d0da78ea8ad..0c33479a8c564a996f08fdd75673f0ffc14d897e 100644 --- a/output.h +++ b/output.h @@ -1,3 +1,20 @@ +#ifndef OUTPUT_H +#define OUTPUT_H + +#include <SDL.h> +#include <stdbool.h> +#include <SDL_ttf.h> +#include <SDL_image.h> +#include <SDL_render.h> +#include <SDL_rect.h> +#include "rows.h" +#include "auto.h" +#include "init.h" +#include "gameLoop.h" +#include "header.h" + + + //Declaration of functions @@ -5,3 +22,5 @@ int paste_row(SDL_Renderer*, int , enum row); int paste_car(SDL_Renderer*, int, int, int, int,int,struct Car*); int paste_score (SDL_Renderer*); + +#endif diff --git a/rows.c b/rows.c index ee929ec59903e4aa67d607ebcf106070f34d2789..b2bf23970695c53876e746f317f89aff2f6a04e7 100644 --- a/rows.c +++ b/rows.c @@ -1,5 +1,5 @@ -#include <stdlib.h> -#include <stdbool.h> +#include "rows.h" + //Vorbedingung: -200<=y_pos<=1000 diff --git a/rows.h b/rows.h index 2b6ab33412c6afcedcf8a1516ced9e7c82cee92f..6a3ecbee6526006016ae7f0d49045fba9ef84a89 100644 --- a/rows.h +++ b/rows.h @@ -1,27 +1,18 @@ -enum row{ - grassBright, - grassDark, - finishlineBright, - finishlineDark, - streetSingle, - streetMultiple, - traintrack, - waterBrightSingle, - waterBrightMultiple, - waterDarkSingle, - waterDarkMultiple -}; +#ifndef ROWS_H +#define ROWS_H -//Declaration of Structs -struct Row{ - enum row row_type; - struct Row *next; - int y_pos; - int speed; - struct LinkedList_car *cars; - -}; +#include <stdlib.h> +#include <stdbool.h> +#include <SDL_rect.h> +#include <SDL_render.h> +#include "gameLoop.h" +#include "auto.h" +#include "main.h" +#define SCREEN_WIDTH 900 +#define SCREEN_HEIGHT 1000 +#define ROW_SIZE 100 +#include "header.h" //Declaration of functions @@ -31,3 +22,5 @@ struct Row* street(bool,int); struct Row* track(int); struct Row* water(bool,bool,int); + +#endif \ No newline at end of file diff --git a/title_screen.c b/title_screen.c index a0cc95b319547945d3f462eeb852f97153684a58..758acddc6dd2b0e28ef69b6ffff287aea5497883 100644 --- a/title_screen.c +++ b/title_screen.c @@ -1,10 +1,4 @@ -//#include "SDL_render.h" -//#include "SDL_surface.h" - -#include <SDL_ttf.h> -#include <SDL_image.h> -#include <stdbool.h> - +#include "title_screen.h" /* Vorbindung: Es existiert ein SDL_Renderer Nachbedingung: diff --git a/title_screen.h b/title_screen.h index abc625e0fbac79a8d0d58a900327b2182813dfc4..63b2c9d1a841c5f67c7282bff7066df1e1d44d86 100644 --- a/title_screen.h +++ b/title_screen.h @@ -1,2 +1,19 @@ +#ifndef TITLE_SCREEN_H +#define TITLE_SCREEN_H + +#include <SDL.h> +#include <SDL_render.h> +#include <SDL_surface.h> + +#include <SDL_ttf.h> +#include <SDL_image.h> +#include <stdbool.h> +#include "header.h" +#include "init.h" + + //Declaration of functions int title_screen(SDL_Renderer*); +extern TTF_Font* font; + +#endif \ No newline at end of file