salut a tous !
voilà j'ai un probleme , j'affiche une map(quadrillage avec des chiffres) et quand j'appuie sur une touche , je veux que les chiffres changent (je change les chiffres de mon tableau en fait) , le probleme c'est que quand je lance le programme , rien ne se passe quand j'appuie sur les touches
le code est là (en partie) :
ma fonction qui gere les touches clavier
ma fonction qui gere l'affichage
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 void Terrain::pressEvent( QKeyEvent * event ) { int x; int y; switch(event->key()) { case Qt::Key_Up : event->accept(); y = liste->getY(); x = liste->getX(); terrain[(x*longueur)+y] = 0; y--; liste->setY(y); terrain[(x*longueur)+y] = 3; salut++; break; case Qt::Key_Down : event->accept(); y = liste->getY(); x = liste->getX(); terrain[(x*longueur)+y] = 0; y++; liste->setY(y); terrain[(x*longueur)+y] = 3; salut--; break; case Qt::Key_Left : event->accept(); y = liste->getY(); x = liste->getX(); terrain[(x*longueur)+y] = 0; x--; liste->setX(x); terrain[(x*longueur)+y] = 3; break; case Qt::Key_Right : event->accept(); y = liste->getY(); x = liste->getX(); terrain[(x*longueur)+y] = 0; x++; liste->setX(x); terrain[(x*longueur)+y] = 3; break; } update(); }
si quelqu'un sait quoi faire , dites le moi s'il vous plait , parce que je peux plus avancer là
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 void Terrain::paintEvent(QPaintEvent *) { QPainter paint(this); paint.setPen( QColor(Qt::transparent)); for (int i = 0 ; i < largeur ; i++) { for (int j = 0 ; j < longueur ; j++) { switch(terrain[(i*longueur)+j]) { case 0: { QImage image1("images/terrain_vide.bmp"); paint.drawImage( QPoint( i*60,j*60 ), image1); } break; case 1: { QImage image2("images/arbre.bmp"); paint.drawImage( QPoint( i*60,j*60 ), image2); } break; case 2: { QImage image3("images/rocher.bmp"); paint.drawImage( QPoint( i*60,j*60 ), image3); } break; case 3: { QImage image4("images/tank.bmp"); paint.drawImage( QPoint( i*60,j*60 ), image4); } break; } } } QPen pen( QColor(Qt::red)); QFont font; font.setStyleHint(QFont::Serif); font.setPointSize(16); pen.setWidth(50); paint.setPen( pen); paint.setFont(font); paint.drawText(10, 650, "Y = " + QString::number( liste->getY()+1 ) ); paint.drawText(10, 630, "X = " + QString::number( liste->getX()+1 ) ); paint.drawText(10, 670, "Salut = " + QString::number( salut ) ); for (int i = 0 ; i < largeur ; i++) { for (int j = 0 ; j < longueur ; j++) { paint.drawText(30+(j*60) , 30+(i*60),QString::number(terrain[j*longueur+i])); } } update(); }j'ai tout essayé !
Partager