#include #include #include #include #define LARGEUR_FENETRE 1050 #define HAUTEUR_FENETRE 750 #define TAILLE_CASE 15 #define NBR_COLONNE 60 #define NBR_LIGNE 40 typedef struct { int x; int y; } Segment; /*Fonction permettant d'afficher le serpent*/ void afficherSerpent(Segment serpent[], int taille) { int i; couleur couleurSerpent = CouleurParNom("yellow"); ChoisirCouleurDessin(couleurSerpent); for (i = 0; i < 10; i++) { serpent[i].x = LARGEUR_FENETRE / 2 + i * TAILLE_CASE; serpent[i].y = HAUTEUR_FENETRE / 2; } for (i = 0; i < taille; i++) { RemplirRectangle(serpent[i].x , serpent[i].y, TAILLE_CASE, TAILLE_CASE); } } /*Fonction recursive permettant d'afficher au moment de l'initialisation un nombre donnée en parametre de pastille Rouge (oui j'en suis fiere meme si c'est pas incroyable)*/ void afficherPastilleAleatoire(int z) { int x,y,i; if(z>0){ couleur rouge = CouleurParNom("red"); x = rand() % 60 * TAILLE_CASE + 5*15; y = rand() % 40 * TAILLE_CASE + 5*15; ChoisirCouleurDessin(rouge); RemplirRectangle(x, y, TAILLE_CASE, TAILLE_CASE); afficherPastilleAleatoire(z-1); } } /*Fonction initialisant la fenetre de jeux en vert*/ void EcranJeu(){ int case_colone,case_ligne; couleur v; v = CouleurParNom("light green"); for (case_ligne = 2; case_ligne < NBR_LIGNE+5; case_ligne++) { for (case_colone = 5; case_colone < NBR_COLONNE+5; case_colone++) { ChoisirCouleurDessin(v); RemplirRectangle(case_colone * TAILLE_CASE, case_ligne * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE); } } } void deplacerSerpent(int longueurSerpent, Segment serpent[], int direction){ int i; couleur c; couleur v; couleur s; c = CouleurParNom("black"); s = CouleurParNom("yellow"); v = CouleurParNom("light green"); for(i=0;i0;i--){ serpent[i] = serpent[i-1]; } switch(direction){ case 1: serpent[0].x += TAILLE_CASE; break; case 2: serpent[0].x -= TAILLE_CASE; break; case 3: serpent[0].y -= TAILLE_CASE; break; case 4: serpent[0].y += TAILLE_CASE; break; } for(i=0;i