54 lines
1.8 KiB
C
54 lines
1.8 KiB
C
|
|
#include <stdlib.h>
|
||
|
|
#include <graph.h>
|
||
|
|
#include <time.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include "pastille.h"
|
||
|
|
#include "menu_terrain.h"
|
||
|
|
#include "serpent.h"
|
||
|
|
|
||
|
|
/*Fonction permettant l'initialisation d'un nombre donnée en parametre de pastille*/
|
||
|
|
void Creation_Pastille(int z, Pastille pomme[], int longueurSerpent, Segment serpent[])
|
||
|
|
{
|
||
|
|
int i;
|
||
|
|
for (i = 0; i < z; i++)
|
||
|
|
{
|
||
|
|
pomme[i].x = rand() % (COLONNES) * TAILLE_CASE + CONTOURE_L * TAILLE_CASE;
|
||
|
|
pomme[i].y = rand() % (LIGNES) * TAILLE_CASE + (CONTOURE_H * TAILLE_CASE);
|
||
|
|
Validation_Coordonne( i, pomme, longueurSerpent, serpent, &pomme[i]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*Fonction validant les coordonnées des pastilles*/
|
||
|
|
void Validation_Coordonne(int z, Pastille pomme[], int longueurSerpent, Segment serpent[], Pastille* indice_pomme){
|
||
|
|
int coordonee_ok, j;
|
||
|
|
Pastille nouv_pomme;
|
||
|
|
do{
|
||
|
|
coordonee_ok = 0;
|
||
|
|
nouv_pomme.x = (rand() % COLONNES) * TAILLE_CASE + (CONTOURE_L * TAILLE_CASE);
|
||
|
|
nouv_pomme.y = (rand() % LIGNES) * TAILLE_CASE + (CONTOURE_H * TAILLE_CASE);
|
||
|
|
for (j = 0; j < longueurSerpent; j++){
|
||
|
|
if (nouv_pomme.x == serpent[j].x && nouv_pomme.y == serpent[j].y){
|
||
|
|
coordonee_ok = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (coordonee_ok == 0){
|
||
|
|
for (j = 0; j < z; j++){
|
||
|
|
if (nouv_pomme.x == pomme[j].x && nouv_pomme.y == pomme[j].y){
|
||
|
|
coordonee_ok = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}while (coordonee_ok);
|
||
|
|
indice_pomme->x = nouv_pomme.x;
|
||
|
|
indice_pomme->y = nouv_pomme.y;
|
||
|
|
}
|
||
|
|
|
||
|
|
/*Fonction permettant l'affichage d'un nombre donnée de pastilles*/
|
||
|
|
void Afficher_Pastille(int z, Pastille pomme[]){
|
||
|
|
int i;
|
||
|
|
for (i = 0; i < z; i++){
|
||
|
|
ChargerImage("Image/Pomme.png", pomme[i].x, pomme[i].y, 0, 0, TAILLE_CASE, TAILLE_CASE);
|
||
|
|
}
|
||
|
|
}
|