1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
   | void    QtAff::AffMap(int **tab, int size, QGraphicsScene *scene)
{
  QPixmap image;
  int   width = 0;
  int   heigth = 0;
 
  for (int i = 0; i < size; i++)
    {
      for (int j = 0; j < size; j++)
        {
          if (tab[i][j] == 1)
            {
              image.load("./res/mur.png", 0, Qt::AutoColor);
              _mur = scene->addPixmap(image);
              _mur->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 4)
            {
              image.load("./res/tete.png", 0, Qt::AutoColor);
              _tete = scene->addPixmap(image);
              _tete->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 2)
            {
              image.load("./res/queue.png", 0, Qt::AutoColor);
              _queue = scene->addPixmap(image);
              _queue->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 3)
            {
              image.load("./res/corps.png", 0, Qt::AutoColor);
              _corps = scene->addPixmap(image);
              _corps->setPos(width, heigth);
              width += 20;
}
          if (tab[i][j] == 4)
            {
              image.load("./res/tete.png", 0, Qt::AutoColor);
              _tete = scene->addPixmap(image);
              _tete->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 2)
            {
              image.load("./res/queue.png", 0, Qt::AutoColor);
              _queue = scene->addPixmap(image);
              _queue->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 3)
            {
              image.load("./res/corps.png", 0, Qt::AutoColor);
              _corps = scene->addPixmap(image);
              _corps->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 7)
            {
              image.load("./res/apple.jpg", 0, Qt::AutoColor);
              _apple = scene->addPixmap(image);
              _apple->setPos(width, heigth);
              width += 20;
            }
          if (tab[i][j] == 0)
            width += 20;
        }
      heigth += 20;
      width = 0;
    }
}
 
int     main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  QGraphicsScene *scene = new QGraphicsScene;
  QtAff Aff;
  int size = 25;
  int **tab = Aff.creat_tab(size);
  int dir = UP;
  int cpt = 0;
 
  Aff.setWidth(520);
  Aff.setHeigth(520);
  while (1)
    {
      scene->clear();
      Aff.AffMap(tab, size, scene);
      QGraphicsView vue(scene);
      vue.setFixedSize(Aff.getWidth(), Aff.getHeigth());
      vue.setWindowTitle("Snake");
      vue.show();
      return app.exec();
      Aff.decal(tab, size, dir); // sert a decaler le serpent dans mon tableau d'entiers
   }
} | 
Partager