Esempio n. 1
0
// Extraction du plus petit élément d'un tas
Elem *extraire_min(Tas *tas) {
  Elem *stock=tas->elem[0];
  tas->elem[0]=tas->elem[--tas->nb_elt];
  tas->elem[tas->nb_elt]=NULL;
  descendre(tas,0);
  return stock;
}
Esempio n. 2
0
/**
 * \brief Fait avancer le personnage 
 * 
 * La fonction fait appelle à différentes sous-fonctions qui testent si le personnage monte, descend, est bloqué, ...
 * \param pposperso La position du personnage sur le terrain 
 * \param terrain Le terrain sur lequel évolue le personnage
 * \param selecNiveau La position relative actuelle de l'écran de visualisation par rapport au niveau
 * \return un \e int qui correspond à l'état du déplacement (le personnage est bloqué, chutte, avance librement)
 */
int avancer ( SDL_Rect* pposperso, SDL_Surface* terrain, SDL_Rect selecNiveau) {
    //La fontion teste les différents cas de déplacement possibles
    if (sortir(pposperso, terrain, selecNiveau))
            return 0; // game over
    if(finir(pposperso) == -1)
        return -1; // Victoire
    if (solsouspieds(pposperso, terrain) == -1)
        return 0; // game over
    if (solsouspieds(pposperso, terrain) == 0) {
        tomber(pposperso, terrain);
        return 2; // tomber
    }
    if (monter(pposperso, terrain) == 1) {
        tomber(pposperso, terrain);
        tomber(pposperso, terrain);
    }
    else {
        if ( plater(pposperso, terrain) == 1 ) {
            tomber(pposperso, terrain);
        }
        else {
            descendre(pposperso, terrain);
        }
        if (monter(pposperso, terrain) == -1)
            return 0; // game over
    }
    return 1; // avancer
}
Esempio n. 3
0
void delEl(Tas *t, int i) 
{
  int iTas=t->indiceNoeud[i+1];
  swap(t, iTas, t->nbEl);
  t->nbEl--;
  monter(t, iTas);
  descendre(t, iTas);
}
Esempio n. 4
0
void descendre(Tas *t, int i)
{
  if (isLeaf(t, i)) return; 
  int son = miniSon(t,i);
  if (t->tab[i] > t->tab[son]) {
    swap(t, son, i); 
    descendre(t, son);
  }
}
Esempio n. 5
0
// Suppresion d'un elt 
void supprimer_elem(Tas *tas, int n) {
  int i, index=0;
  for(i=0;i<tas->nb_elt;i++)
    if(tas->elem[i]->num==n) {
      index=i;
      i=tas->nb_elt;
    }
  tas->elem[index]=tas->elem[--tas->nb_elt];
  monter(tas, index);
  descendre(tas, index);
}
Esempio n. 6
0
// Fct pour descendre un elt dans le tas
void descendre(Tas *tas, int i){
  if(i*2+2 < tas->nb_elt) {
    if((tas->elem[i*2+1]->c < tas->elem[i*2+2]->c) && (tas->elem[i]->c > tas->elem[i*2+1]->c)) {
      echanger(tas, i, i*2+1);
      descendre(tas, i*2+1);
      return;
    }	
    
    if((tas->elem[i*2+1]->c >= tas->elem[i*2+2]->c) && (tas->elem[i]->c > tas->elem[i*2+2]->c)){
      echanger(tas, i, i*2+2);
      descendre(tas, i*2+2);
      return;
    }
  }
  
  if((i*2+1 < tas->nb_elt) && (tas->elem[i]->c > tas->elem[i*2+1]->c)) {
    echanger(tas, i, i*2+1);
    descendre(tas, i*2+1);
    return;
  }
}
Esempio n. 7
0
Element * delMin(Tas *t) 
{
  if (t == NULL) perror("Tas NULL!\n");
  if (t->nbEl==0) {
    printf("Tas empty\n");
    perror("[delMin] Not possible\n");
  }
  Element * ret = t->tab[1];
  t->indiceNoeud[t->tab[0]->num]=-1;
  swap(t, t->nbEl, 1);
  t->nbEl--;
  descendre(t, 1);
  return ret;
}