1
0

Création du fichier game.c

- 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.
This commit is contained in:
Lyanis SOUIDI 2022-11-26 21:08:24 +01:00
parent 6ceec39679
commit d320410bf6
2 changed files with 40 additions and 0 deletions

6
include/game.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef GAME_H
#define GAME_H
void game(int colonnes, int lignes);
#endif

34
src/game.c Normal file
View File

@ -0,0 +1,34 @@
#include<stdio.h>
#include<stdlib.h>
#include<graph.h>
#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();
}