Skip to content
Snippets Groups Projects
Commit 81b5e6da authored by bosskkev's avatar bosskkev
Browse files

corection énorme bug

parent 8cd51e12
No related branches found
No related tags found
No related merge requests found
Pipeline #23945 failed
......@@ -45,6 +45,7 @@ public class Kernel {
this.update();
this.setKeysAndKeyReleasedListeners((JPanel) this.graphicEngine.getContentPane());
soundEngine = new SoundEngine();
start();
}
/**
......@@ -53,7 +54,7 @@ public class Kernel {
* @throws IOException
*/
public void start() throws IOException {
graphicEngine.update();
graphicEngine.start();
}
public void restart() throws IOException {
......@@ -69,8 +70,6 @@ public class Kernel {
* One step of the game. Update all objects positions and repaint the grid.
*/
public void update() {
//System.out.println("One step");
// Updating all objects positions
for (Engine engine: engines
) {
......
......@@ -39,8 +39,7 @@ public class GraphicEngine extends JFrame implements Engine {
getContentPane().add(ic);
}
@Override
public void update(){
public void start(){
for (PongObject po : Kernel.gameObjects
) {
try {
......@@ -49,16 +48,30 @@ public class GraphicEngine extends JFrame implements Engine {
throw new RuntimeException(e);
}
}
drawRect();
getContentPane().add(new ScoreComponent(new Coordinates2D(100, 100), new Coordinates2D(670, 100), PongApp.score1, PongApp.score2));
repaint();
revalidate();
}
@Override
public void update(){
//updateContentPane();
repaint();
revalidate();
}
@Override
public void restart() {
getContentPane().removeAll();
update();
drawRect(); //TODO: Trouver un moyen de ne pas avoir à redessiner le rectangle à chaque restart et rendre le restart plus générique
start();
//drawRect(); //TODO: Trouver un moyen de ne pas avoir à redessiner le rectangle à chaque restart et rendre le restart plus générique
}
public void drawRect(){
......@@ -69,4 +82,20 @@ public class GraphicEngine extends JFrame implements Engine {
this.getContentPane().add(new ScoreComponent(new Coordinates2D(100, 100), new Coordinates2D(500, 100), score1, score2));
}
public void updateContentPane() {
System.out.println(getContentPane().getComponents().length);
/*for (Component jc: getContentPane().getComponents()
) {
//System.out.println(jc.toString());
System.out.println(jc.getX() + " " + jc.getY());
jc.setLocation(0, 0);
getContentPane().getComponents()[0].setLocation(0, 0);
jc.repaint();
}
*/
getContentPane().repaint();
}
}
......@@ -33,6 +33,10 @@ public class ImageComponent extends JComponent {
return position;
}
public void setPosition(Coordinates2D position) {
this.position = position;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
......
......@@ -15,7 +15,7 @@ public class PongApp {
public static boolean isGoal = false;
public static ArrayList<PongObject> components = new ArrayList<PongObject>();
public static ArrayList<PongObject> components = new ArrayList<>();
public static int width = 800;
public static int height = 600;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment