Hallo Leute,
ich habe ein kleines Spiel, das ich gerade zu programmieren versuche, leider klappt es nicht mit dem Aufruf von getX() un getY() der super Klasse Objekt. kann jemandem mir verratet,
was ich falsches mache, der Kompiler schlagt vor, ich muss die getter X und getter Y in den Klassen TuyauRouge und Bloc anlegen.
Das Problem liegt an den Beiden letzten Zeilen der Klasse scene.java
so sieht das Ergebnis aus, die Objkte(Bloc und TuyauRouge) liegen Oben Links
https://picload.org/view/dgpargia/2017-10-1610_12_59-themaerstel.png.html
1-Klasse scene
2-Klasse Objet
3-Klasse Tuyaurouge
4-Klasse Bloc
ich habe ein kleines Spiel, das ich gerade zu programmieren versuche, leider klappt es nicht mit dem Aufruf von getX() un getY() der super Klasse Objekt. kann jemandem mir verratet,
was ich falsches mache, der Kompiler schlagt vor, ich muss die getter X und getter Y in den Klassen TuyauRouge und Bloc anlegen.
Das Problem liegt an den Beiden letzten Zeilen der Klasse scene.java
so sieht das Ergebnis aus, die Objkte(Bloc und TuyauRouge) liegen Oben Links
https://picload.org/view/dgpargia/2017-10-1610_12_59-themaerstel.png.html
1-Klasse scene
Java:
package mathmaurer.jeu;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import mathmaurer.objets.Bloc;
import mathmaurer.objets.TuyauRouge;
import mathmaurer.personnages.Mario;
@SuppressWarnings("serial")
public class Scene extends JPanel {
private ImageIcon icoFond;
private Image imgFond1;
private Image imgFond2;
private ImageIcon icoChateau1;
private Image imagChateau1;
private ImageIcon icoDepart;
private Image imgDepart;
// private ImageIcon icoMario; // provisoire
// private Image imgMario; // provisoire
private int xFond1;
private int xFond2;
private int dx; // permet de deplacer l'ecran Horizontalement
private int xPos;
public Mario mario;
public TuyauRouge tuyauRouge1;
public Bloc bloc1;
// Constructeur
public Scene() {
super();
this.xFond1 = -50;
this.xFond2 = 750;
this.dx = 0;
this.xPos = -1;
icoFond = new ImageIcon(getClass().getResource("/images/fondEcran.png"));
this.imgFond1 = this.icoFond.getImage();
this.imgFond2 = this.icoFond.getImage();
// icoMario = new ImageIcon(getClass().getResource("/images/marioMarcheDroite.png")); //provisoire
// this.imgMario = this.icoMario.getImage(); // provisoire
icoChateau1 = new ImageIcon(getClass().getResource("/images/chateau1.png"));
this.imagChateau1 = this.icoChateau1.getImage();
icoDepart = new ImageIcon(getClass().getResource("/images/depart.png"));
this.imgDepart = this.icoDepart.getImage();
mario = new Mario(300, 245);
tuyauRouge1 = new TuyauRouge(600, 230);
bloc1 = new Bloc(400,180);
this.setFocusable(true); // ecourter l'ecran
this.requestFocusInWindow(); // pour etre certain de recuperer le Focus
this.addKeyListener(new Clavier()); //lecteur de clavier gere par la classe Clavier
Thread ChronoEcran = new Thread(new Chrono());
ChronoEcran.start();
}
public int getDx() {
return dx;
} // acceder a la valeur de dx
public void setDx(int dx) {
this.dx = dx;
} // modifier la valeur de dx de l'exterieur de la classe
public int getxPos() {
return xPos;
}
public void setxPos(int xPos) {
this.xPos = xPos;
}
public void setxFond1(int xFond1) {
this.xFond1 = xFond1;
}
public void setxFond2(int xFond2) {
this.xFond2 = xFond2;
}
public void deplacementFond() {
if(this.xPos >= 0){
this.xPos = this.xPos + this.dx;
this.xFond1 = this.xFond1 - this.dx;// remettre a jour la position de notre Fond
this.xFond2 = this.xFond2 - this.dx;
}
//permanence de Fond de l'ecran
if(this.xFond1 == -800){this.xFond1 = 800;}
else if(this.xFond2 == -800){this.xFond2 = 800;}
else if(this.xFond1 == 800){this.xFond1 = -800;}
else if(this.xFond2 == 800){this.xFond2 = -800;}
}
public void paintComponent(Graphics g) {
super.paintComponent(g); // paintComponent est une methode herité on
// fait appel a Super
Graphics g2 = (Graphics2D) g; // pour avoir un meilleur angle des
// Graphics, ainsi il faut caste
// Graphics a Graphics 2D
this.deplacementFond(); // a chaque fois qu'on va remettre l'ecan, on
// va faire appel a cette methode
g2.drawImage(this.imgFond1, this.xFond1, 0, null);
g2.drawImage(this.imgFond2, this.xFond2, 0, null);
g2.drawImage(this.mario.marche("mario", 25), 300, 245, null);
g2.drawImage(this.imagChateau1, 10 - this.xPos, 95, null);
g2.drawImage(this.imgDepart, 220 - this.xPos, 234, null);
// die beiden Zeilen haben ein Problem mit
g2.drawImage(this.tuyauRouge1.getimgTuyauRouge(), this.tuyauRouge1.getX()-this.xPos, this.tuyauRouge1.getY(), null);
g2.drawImage(this.bloc1.getimgBloc(), this.bloc1.getX()-this.xPos, this.bloc1.getY(), null);
}
}
2-Klasse Objet
Java:
package mathmaurer.objets;
public class Objet {
private int Largeur, hauteur; // Dimensions de l'objet
private int x,y; // position de l'objet
public Objet(int x, int y,int largeur, int hauteur) {
this.x = x;
this.y = y;
this.Largeur = largeur;
this.hauteur = hauteur;
}
// Getters
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getLargeur() {
return Largeur;
}
public int getHauteur() {
return hauteur;
}
// Setters
public void setLargeur(int largeur) {
Largeur = largeur;
}
public void setHauteur(int hauteur) {
this.hauteur = hauteur;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
}
3-Klasse Tuyaurouge
Java:
package mathmaurer.objets;
import java.awt.Image;
import javax.swing.ImageIcon;
public class TuyauRouge extends Object {
// variables
private Image imgTuyauRouge;
private ImageIcon icoTuyauRouge;
public TuyauRouge(int x, int y) {
super();
this.icoTuyauRouge = new ImageIcon(getClass().getResource("/images/tuyauRouge.png"));
this.imgTuyauRouge = this.icoTuyauRouge.getImage();
}
public Image getimgTuyauRouge(){
return imgTuyauRouge;
}
public int getX() {
// TODO Auto-generated method stub
return 0;
}
public int getY() {
// TODO Auto-generated method stub
return 0;
}
}
4-Klasse Bloc
Java:
package mathmaurer.objets;
import java.awt.Image;
import javax.swing.ImageIcon;
public class Bloc extends Object {
// variables
private Image imgBloc;
private ImageIcon icoBloc;
public Bloc(int x, int y) {
super();
this.icoBloc = new ImageIcon(getClass().getResource("/images/bloc.png"));
this.imgBloc = this.icoBloc.getImage();
}
public Image getimgBloc(){
return imgBloc;
}
public int getY() {
// TODO Auto-generated method stub
return 0;
}
public int getX() {
// TODO Auto-generated method stub
return 0;
}
}