diff --git a/README.md b/README.md index bc2d133c85951c6670da2aba4f41cf684f303864..82267bb52b58d9b8148b4e654831d051512b5959 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Trello : https://trello.com/b/YGhNeYX3/projet-apprentissage-par-renforcement │ ├── Belkhiri │ │ ├── x_fenetre │ │ └── snakes -│ ├── Beret +│ ├── Beret +│ │ └── x_fenetre │ └── Meyer │ └── x_fenetre └── travail_de_groupe diff --git a/travail_individuel/Beret/snakes/Makefile b/travail_individuel/Beret/snakes/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8a82e304f1ceab181d7729d8f1e264013cc7eaf3 --- /dev/null +++ b/travail_individuel/Beret/snakes/Makefile @@ -0,0 +1,10 @@ +CC=gcc + +main:main.o + $(CC) -o main main.o -lm -lSDL2 + @echo "=> Lancer le programme avec ./main" + +main.o:main.c + $(CC) -c main.c -g -Wall -Wextra +clean: + rm -rf main main.o \ No newline at end of file diff --git a/travail_individuel/Beret/fichier.txt b/travail_individuel/Beret/snakes/main.c similarity index 100% rename from travail_individuel/Beret/fichier.txt rename to travail_individuel/Beret/snakes/main.c diff --git a/travail_individuel/Beret/1exercice/Makefile b/travail_individuel/Beret/x_fenetre/Makefile similarity index 100% rename from travail_individuel/Beret/1exercice/Makefile rename to travail_individuel/Beret/x_fenetre/Makefile diff --git a/travail_individuel/Beret/1exercice/main.c b/travail_individuel/Beret/x_fenetre/main.c similarity index 97% rename from travail_individuel/Beret/1exercice/main.c rename to travail_individuel/Beret/x_fenetre/main.c index d4d6373195912d3243d41e6d7a85981431d948df..c0b0f2e62db5b91406a06c46c8916f51e9fcf975 100644 --- a/travail_individuel/Beret/1exercice/main.c +++ b/travail_individuel/Beret/x_fenetre/main.c @@ -1,101 +1,101 @@ -#include <SDL2/SDL.h> -#include <math.h> -#include <stdio.h> -#include <string.h> - -int main(int argc, char **argv) { - (void)argc; - (void)argv; - int x=0; - - - - SDL_Window - *window_1 = NULL,*window_2=NULL, *window_3=NULL,*window_4=NULL; // Future fenêtre de gauche - - /* Initialisation de la SDL + gestion de l'échec possible */ - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - SDL_Log("Error : SDL initialisation - %s\n", - SDL_GetError()); // l'initialisation de la SDL a échoué - exit(EXIT_FAILURE); - } - - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); - int Width = DM.w; - - /* Création de la fenêtre de gauche */ - window_1 = SDL_CreateWindow( - "Vague", // codage en utf8, donc accents possibles - x,300 + 100*cos(x/10), - 100,100, - SDL_WINDOW_RESIZABLE); - - if (window_1 == NULL) { - SDL_Log("Error : SDL window 1 creation - %s\n", - SDL_GetError()); // échec de la création de la fenêtre - SDL_Quit(); // On referme la SDL - exit(EXIT_FAILURE); - } - window_2 = SDL_CreateWindow( - "vague2", // codage en utf8, donc accents possibles - x-10,300 + 110*cos((x-10)/10), // à droite de la fenêtre de gauche - 80, 80, // largeur = 500, hauteur = 300 - 0); - - if (window_2 == NULL) { - SDL_Log("Error : SDL window 2 creation - %s\n", - SDL_GetError()); // échec de la création de la deuxième fenêtre - SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite - SDL_Quit(); - exit(EXIT_FAILURE); - } - window_3 = SDL_CreateWindow( - "vague3", // codage en utf8, donc accents possibles - x-20,300 + 130*cos((x-20)/10), // à droite de la fenêtre de gauche - 60, 60, // largeur = 500, hauteur = 300 - 0); - - if (window_3 == NULL) { - SDL_Log("Error : SDL window 3 creation - %s\n", - SDL_GetError()); // échec de la création de la deuxième fenêtre - SDL_DestroyWindow(window_2); - SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite - SDL_Quit(); - exit(EXIT_FAILURE); - } - - window_4 = SDL_CreateWindow( - "vague4", // codage en utf8, donc accents possibles - x-30,300 + 150*cos((x-30)/10), // à droite de la fenêtre de gauche - 40, 40, // largeur = 500, hauteur = 300 - 0); - - if (window_4 == NULL) { - SDL_Log("Error : SDL window 4 creation - %s\n", - SDL_GetError()); // échec de la création de la deuxième fenêtre - SDL_DestroyWindow(window_3); - SDL_DestroyWindow(window_2); - SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite - SDL_Quit(); - exit(EXIT_FAILURE); - } - while (x<Width){ - SDL_SetWindowPosition(window_1,x,300 + 100*cos((x)/10)); - SDL_SetWindowPosition(window_2,x-10,300 + 100*cos((x-10)/10)); - SDL_SetWindowPosition(window_3,x-20,300 + 100*cos((x-20)/10)); - SDL_SetWindowPosition(window_4,x-30,300 + 100*cos((x-30)/10)); - x=x+10; - - SDL_Delay(150); // Pause exprimée en ms - } - - SDL_DestroyWindow(window_4); - SDL_DestroyWindow(window_3); - SDL_DestroyWindow(window_2); - SDL_DestroyWindow(window_1); - - SDL_Quit(); // la SDL - - return 0; +#include <SDL2/SDL.h> +#include <math.h> +#include <stdio.h> +#include <string.h> + +int main(int argc, char **argv) { + (void)argc; + (void)argv; + int x=0; + + + + SDL_Window + *window_1 = NULL,*window_2=NULL, *window_3=NULL,*window_4=NULL; // Future fenêtre de gauche + + /* Initialisation de la SDL + gestion de l'échec possible */ + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + SDL_Log("Error : SDL initialisation - %s\n", + SDL_GetError()); // l'initialisation de la SDL a échoué + exit(EXIT_FAILURE); + } + + SDL_DisplayMode DM; + SDL_GetCurrentDisplayMode(0, &DM); + int Width = DM.w; + + /* Création de la fenêtre de gauche */ + window_1 = SDL_CreateWindow( + "Vague", // codage en utf8, donc accents possibles + x,300 + 100*cos(x/10), + 100,100, + SDL_WINDOW_RESIZABLE); + + if (window_1 == NULL) { + SDL_Log("Error : SDL window 1 creation - %s\n", + SDL_GetError()); // échec de la création de la fenêtre + SDL_Quit(); // On referme la SDL + exit(EXIT_FAILURE); + } + window_2 = SDL_CreateWindow( + "vague2", // codage en utf8, donc accents possibles + x-10,300 + 110*cos((x-10)/10), // à droite de la fenêtre de gauche + 80, 80, // largeur = 500, hauteur = 300 + 0); + + if (window_2 == NULL) { + SDL_Log("Error : SDL window 2 creation - %s\n", + SDL_GetError()); // échec de la création de la deuxième fenêtre + SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite + SDL_Quit(); + exit(EXIT_FAILURE); + } + window_3 = SDL_CreateWindow( + "vague3", // codage en utf8, donc accents possibles + x-20,300 + 130*cos((x-20)/10), // à droite de la fenêtre de gauche + 60, 60, // largeur = 500, hauteur = 300 + 0); + + if (window_3 == NULL) { + SDL_Log("Error : SDL window 3 creation - %s\n", + SDL_GetError()); // échec de la création de la deuxième fenêtre + SDL_DestroyWindow(window_2); + SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite + SDL_Quit(); + exit(EXIT_FAILURE); + } + + window_4 = SDL_CreateWindow( + "vague4", // codage en utf8, donc accents possibles + x-30,300 + 150*cos((x-30)/10), // à droite de la fenêtre de gauche + 40, 40, // largeur = 500, hauteur = 300 + 0); + + if (window_4 == NULL) { + SDL_Log("Error : SDL window 4 creation - %s\n", + SDL_GetError()); // échec de la création de la deuxième fenêtre + SDL_DestroyWindow(window_3); + SDL_DestroyWindow(window_2); + SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite + SDL_Quit(); + exit(EXIT_FAILURE); + } + while (x<Width){ + SDL_SetWindowPosition(window_1,x,300 + 100*cos((x)/10)); + SDL_SetWindowPosition(window_2,x-10,300 + 100*cos((x-10)/10)); + SDL_SetWindowPosition(window_3,x-20,300 + 100*cos((x-20)/10)); + SDL_SetWindowPosition(window_4,x-30,300 + 100*cos((x-30)/10)); + x=x+10; + + SDL_Delay(150); // Pause exprimée en ms + } + + SDL_DestroyWindow(window_4); + SDL_DestroyWindow(window_3); + SDL_DestroyWindow(window_2); + SDL_DestroyWindow(window_1); + + SDL_Quit(); // la SDL + + return 0; } \ No newline at end of file