/* 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

int** plateau_init(void) {

  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));

  }


  /* positionnement du serpent */

  for (i = 0; i < TAILLE_SERPENT; i++)  {

    tableau[((LIGNES/2)-5)+i][COLONNES/2] = 1;

  }
    



  /* 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 */
    
    while (tableau[ligne_pomme][colonne_pomme] == 2)  {

      ligne_pomme = rand() % 40;
      colonne_pomme = rand() % 60;

    }

    
    /* le chiffre "2" definit une pomme */
    
    tableau[ligne_pomme][colonne_pomme] = 2;

  }

 
 

      
  return tableau; 
}