102Fermer104
SasumeLe 07/05/2008 à 00:40
Ouais à mon tour de montrer mon code.
Voici comment j'indente mon Python trigni
    def on_action_export_triggered(self):
        file_name = KFileDialog.getSaveFileName(KUrl(), "*.png", self)
        if not file_name.isNull():
          file = QFile(file_name)
          file.open(QIODevice.WriteOnly)
          self.image.save(file, "PNG")
        
    def on_action_color_triggered(self):
        color = QColorDialog.getColor(self.pen.color(), self)
        if color.isValid():
          self.pen.setColor(color)
        
    def on_action_pen_thin_triggered(self):
        self.pen.setWidth(1)
        
    def on_action_pen_normal_triggered(self):
        self.pen.setWidth(2)


Et voici un bout de code en C pour montrer quand même que je sais personnaliser mon style, mon art :
void Game_play(Game *this, Joypad *joypad, Graphics *graphics)
{
  unsigned short current_level = 0;

  Hero hero;
  Hero_init(&hero, 5);

  do
  {
    Level_init(&(this->memory->level), FileGame_getLevelData(this->file_game, current_level), &(this->memory->level_memory));
    Level_play(&(this->memory->level), &hero, graphics, joypad);

    if(!hero.character.alive)
      hero.nb_lives--, hero.character.alive = true;
    else if(!joypad->keys.quit)
      current_level++;

  }while(!joypad->keys.quit && current_level < this->file_game->nb_level && hero.nb_lives > 0);
}

void Level_play(Level *this, Hero *hero, Graphics *graphics, Joypad *joypad)
{
  this->hero = hero;
  Hero_initLevel(hero, &(this->hero_start_pos));

  // On attend que le joueur soit prêt.
  Joypad_waitNoKey(joypad);
  unsigned short clignote = 0;
  do
  {
    hero->visible = (clignote <= 3);
    clignote = (clignote + 1) & 0x07;
    Level_draw(this, graphics);
  }while(!Joypad_isKeyPressed(joypad));
  hero->visible = true;

  // Boucle principale
  do
  {
    Level_update(this, joypad);
    Level_draw(this, graphics);
  } while(hero->character.alive && !hero->escaped && !joypad->keys.quit);
}

void Level_update(Level *this, Joypad *joypad)
{
  // Joypad
  Joypad_update(joypad);

  // Hero
  Hero_update(this->hero, joypad, this);

  // Holes
  unsigned short i = 0;
  while(i < List_count(&(this->holes)))
  {
    Hole *hole = List_get(&(this->holes), i);
    Hole_update(hole, this);
    if(hole->state == Hole_FREE)
      List_remove(&(this->holes), i); // On vire le trou
    else
      i++;
  }

  // Enemies
  Iterator it;
  Iterator_init(&it, &(this->enemies));
  while(Iterator_hasElement(&it))
  {
    Enemy_update(Iterator_get(&it), this, this->hero);
    Iterator_next(&it);
  }
}

On se délecte devant ces « & » occasionnels qui ponctuent agréablement mon code.