2023-11-30 14:48:19 +01:00
|
|
|
/* Création du plateau de jeu avec les pastilles et le serpent
|
|
|
|
|
|
|
|
written by Yann KERAUDREN and Titouan LERICHE*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#define LIGNES 40
|
|
|
|
#define COLONNES 60
|
|
|
|
#define NBR_POMME 5
|
|
|
|
#define TAILLE_SERPENT 10
|
|
|
|
|
2023-12-07 16:16:15 +01:00
|
|
|
|
|
|
|
|
2023-12-07 22:04:47 +01:00
|
|
|
int** plateau_init(void) {
|
2023-11-30 14:48:19 +01:00
|
|
|
|
|
|
|
int ligne_pomme, colonne_pomme, i;
|
|
|
|
|
|
|
|
int** tableau = NULL;
|
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
|
|
|
|
|
|
/* allocation du tableau dans le tas */
|
|
|
|
|
|
|
|
tableau = calloc(LIGNES, sizeof(double));
|
|
|
|
|
|
|
|
for ( i = 0; i < LIGNES; i++) {
|
|
|
|
|
|
|
|
tableau[i] = calloc(COLONNES, sizeof(int));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-07 22:04:47 +01:00
|
|
|
|
|
|
|
|
2023-11-30 14:48:19 +01:00
|
|
|
|
2023-12-07 22:04:47 +01:00
|
|
|
/* positionnement du serpent et marquage de la tete et la queue */
|
2023-11-30 14:48:19 +01:00
|
|
|
|
2023-12-07 22:04:47 +01:00
|
|
|
tableau[(LIGNES/2)-5][COLONNES/2] = -2;
|
|
|
|
|
|
|
|
tableau[((LIGNES/2)-5)+TAILLE_SERPENT-1][COLONNES/2] = -1;
|
|
|
|
|
|
|
|
for (i = 1; i < TAILLE_SERPENT - 1; i++) {
|
2023-11-30 14:48:19 +01:00
|
|
|
|
|
|
|
tableau[((LIGNES/2)-5)+i][COLONNES/2] = 1;
|
|
|
|
|
|
|
|
|
2023-12-07 22:04:47 +01:00
|
|
|
}
|
2023-11-30 14:48:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* positionnement alétoire des pommes */
|
|
|
|
|
|
|
|
for ( i = 0; i < NBR_POMME; i++) {
|
|
|
|
|
|
|
|
|
|
|
|
ligne_pomme = rand() % 40;
|
|
|
|
colonne_pomme = rand() % 60;
|
|
|
|
|
|
|
|
|
|
|
|
/* teste pour faire apparaitre exactement 5 pommes */
|
|
|
|
|
2023-11-30 20:50:39 +01:00
|
|
|
while (tableau[ligne_pomme][colonne_pomme] == 2 || tableau[ligne_pomme][colonne_pomme] == 1) {
|
2023-11-30 14:48:19 +01:00
|
|
|
|
|
|
|
ligne_pomme = rand() % 40;
|
|
|
|
colonne_pomme = rand() % 60;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* le chiffre "2" definit une pomme */
|
|
|
|
|
|
|
|
tableau[ligne_pomme][colonne_pomme] = 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-07 22:04:47 +01:00
|
|
|
return tableau;
|
2023-11-30 14:48:19 +01:00
|
|
|
}
|