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

corection énorme bug

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