From 1b1d4d95b4f2d9106df785b86f0b23b9230b60f8 Mon Sep 17 00:00:00 2001 From: Janos <janol55@zedat.fu-berlin.de> Date: Wed, 20 Mar 2024 20:22:05 +0100 Subject: [PATCH] =?UTF-8?q?Header=20aufgeteilt=20und=20Funktionsf=C3=A4hig?= =?UTF-8?q?=20gemacht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto.c | 10 ++----- auto.h | 31 ++++++++----------- charac.c | 9 ++---- charac.h | 23 +++++++++++++- file_own.c | 5 +--- file_own.h | 16 +++++++++- gameLoop.c | 5 ++-- gameLoop.h | 24 +++++++++++++-- header.h | 66 ++-------------------------------------- init.c | 3 +- init.h | 14 +++++++-- main.c | 11 ++----- main.h | 23 +++++++++++--- map.c | 7 +---- map.h | 20 +++++++++---- menu.c | 4 ++- menu2.c | 81 ++------------------------------------------------ menu2.h | 18 ++++++++++- output.c | 11 +------ output.h | 19 ++++++++++++ rows.c | 4 +-- rows.h | 37 ++++++++++------------- title_screen.c | 8 +---- title_screen.h | 17 +++++++++++ 24 files changed, 207 insertions(+), 259 deletions(-) diff --git a/auto.c b/auto.c index 4308d93..08d880b 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 3b32378..c443be7 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 6e23fbd..704ce89 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 696df49..8e09cb6 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 26b363b..b5c2c36 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 8b44c97..69a747a 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 c73dca7..8d11f28 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 3e2abbd..251c6ba 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 7574e8f..92ece71 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 66b5918..b64d8e7 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 89ffba6..56e6784 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 0e10c81..44d74e3 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 b397dea..a0d3564 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 9282676..728828f 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 8ad59b3..1a1aca8 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 74ce926..4d92883 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 35cb683..533009e 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 7a47f1d..e8c7420 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 79d7327..9960510 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 b6f3aa2..0c33479 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 ee929ec..b2bf239 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 2b6ab33..6a3ecbe 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 a0cc95b..758acdd 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 abc625e..63b2c9d 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 -- GitLab