Commit b31d67de authored by Mesbah Zacharia's avatar Mesbah Zacharia

add(Game Pane):piste de resolution blinking avec Image (vivement JavaFX)

parent f3ec16c5
......@@ -6,6 +6,7 @@ import org.lubrizoloffsprings.game.Robot;
import org.lubrizoloffsprings.interpreter.Environment;
import org.lubrizoloffsprings.interpreter.Interpreter;
import org.lubrizoloffsprings.util.CustomFileUtils;
import org.lubrizoloffsprings.util.ImageUtils;
import org.python.core.PyDictionary;
import org.python.core.PyInteger;
import org.python.core.PyObject;
......@@ -25,6 +26,7 @@ public class GamePane extends JPanel
public boolean gridDrawn;
private static final int gridSize = 10;
private Environment env;
public GamePane() {
super();
this.RobotList = new HashMap<>();
......@@ -67,17 +69,15 @@ public class GamePane extends JPanel
*/
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
//g2d.draw3DRect(1, 1, this.getWidth()/2, this.getHeight()/2, true);
//GamePane gamePane = new GamePane();
JFrame f = new JFrame ();
f.getContentPane().add(this);
System.out.println(f.getRootPane());
f.setSize (100, 200);
f.pack();
f.setVisible (true);
this.gridDrawn = false;
Graphics2D g2d = (Graphics2D) g;
//g2d.draw3DRect(1, 1, this.getWidth()/2, this.getHeight()/2, true);
//GamePane gamePane = new GamePane();
JFrame f = new JFrame();
f.getContentPane().add(this);
f.setSize(100, 200);
f.pack();
f.setVisible(true);
this.gridDrawn = false;
}
/**
......@@ -87,11 +87,12 @@ public class GamePane extends JPanel
public void paint(Graphics g) {
Grid gridToDraw = new Grid();
Robot robotToDraw = new Robot("placeholder", gridToDraw);
Image img = new ImageIcon(CustomFileUtils.getResource("background/background.png").getPath()).getImage();
System.out.println(this.getWidth());
System.out.println(this.getHeight());
img = img.getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_AREA_AVERAGING);
g.drawImage(img, 0, 0, null);
if (!this.gridDrawn) {
Image img = new ImageIcon(CustomFileUtils.getResource("background/background.png").getPath()).getImage();
img = img.getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_AREA_AVERAGING);
img = new ImageIcon(img).getImage();
g.drawImage(img, 0, 0, null);
}
for (String robot1name : this.RobotList.keySet())
{
robotToDraw = new Robot(robot1name, this.grid);
......@@ -110,11 +111,6 @@ public class GamePane extends JPanel
PyObject robot1 = this.env.getVar(robot1name);
g.drawImage(robotToDraw.icon, ((gridSize / 2) + ((PyInteger)this.env.getVar(robot1name+'X')).asInt()) * this.getWidth() / (gridSize+1), ((gridSize / 2) - ((PyInteger)this.env.getVar(robot1name+'Y')).asInt()) * this.getHeight() / (gridSize + 1), this.getWidth() / gridSize, this.getHeight() / gridSize, this);
}
/*for (int iWidth = 0; iWidth<gridSize+1; iWidth++) {
for (int iHeight = 0; iHeight<gridSize+1; iHeight++) {
g.draw3DRect(iWidth*this.getWidth()/(GamePane.gridSize + 1), iHeight*this.getHeight()/(GamePane.gridSize + 1), (iWidth+1)*this.getWidth()/(GamePane.gridSize + 1), (iHeight+1)*this.getHeight()/(GamePane.gridSize + 1), true);
}
}*/
}
......
package org.lubrizoloffsprings.util;
public class ImageUtils {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment