From d320410bf6a6a5d6c9b3a46312690e170cab5ecb Mon Sep 17 00:00:00 2001 From: Lyanis Souidi Date: Sat, 26 Nov 2022 21:08:24 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20du=20fichier=20game.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Création d'une fonction game permettant de générer un tableau en fonction du nombre de colonnes et de lignes fournies en argument et en fonction de la taille de la fenêtre. --- include/game.h | 6 ++++++ src/game.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 include/game.h create mode 100644 src/game.c diff --git a/include/game.h b/include/game.h new file mode 100644 index 0000000..6711c31 --- /dev/null +++ b/include/game.h @@ -0,0 +1,6 @@ +#ifndef GAME_H +#define GAME_H + +void game(int colonnes, int lignes); + +#endif \ No newline at end of file diff --git a/src/game.c b/src/game.c new file mode 100644 index 0000000..44af72b --- /dev/null +++ b/src/game.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include"../include/main.h" + +#define GAME_MARGIN_RIGHT 20 +#define GAME_MARGIN_LEFT 20 +#define GAME_MARGIN_TOP 35 +#define GAME_MARGIN_BOTTOM 20 + +void game(int colonnes, int lignes) { + EffacerEcran(CouleurParComposante(54, 57, 63)); + ChoisirCouleurDessin(CouleurParNom("white")); + + unsigned int case_max_width = (WINDOW_WIDTH - (GAME_MARGIN_RIGHT + GAME_MARGIN_LEFT)) / colonnes; + unsigned int case_max_height = (WINDOW_HEIGHT - (GAME_MARGIN_TOP + GAME_MARGIN_BOTTOM)) / lignes; + unsigned int case_max_dimensions; + + if (case_max_height < case_max_width) { + case_max_dimensions = case_max_height; + } else { + case_max_dimensions = case_max_width; + } + + unsigned int case_margin = case_max_dimensions * 0.05; + + for (unsigned int l = 0; l < lignes; l += 1) { + for (unsigned int c = 0; c < colonnes; c += 1) { + DessinerRectangle(GAME_MARGIN_RIGHT + (c * case_max_dimensions), GAME_MARGIN_TOP + (l * case_max_dimensions), case_max_dimensions - (2 * case_margin), case_max_dimensions - (2 * case_margin)); + } + } + + Touche(); +}