package graphics;

import engine.Entity;
import engine.EntityManager;
import engine.EntityView;
import engine.Level;

import javax.swing.*;
import java.awt.*;
import java.util.Collection;
import java.util.Observable;
import java.util.Observer;

public class BoardView extends JPanel implements Observer {

    private Board board;

    public BoardView(Board board) {
        super();
        this.board = board;
    }

    @Override
    public void update(Observable o, Object arg) {
        this.repaint();
        System.out.println("Board view: update()");
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        System.out.println("repaint");

        Graphics2D graphics2D = (Graphics2D)g;

        EntityManager manager = board.getLevel().getEntityManager();

        EntityView gluttonView = manager.getGluttonView();
        Entity glutton = gluttonView.getEntity();
        graphics2D.drawImage(gluttonView.getCurrentDrawing(), null,
                glutton.getX(), glutton.getY());

        Collection<EntityView> nutritionists = manager.getNutritionistsView();
        for (EntityView e : nutritionists) {
            Entity entity = e.getEntity();
            graphics2D.drawImage(e.getCurrentDrawing(), null,
                    entity.getX(), entity.getY());
        }

        Collection<EntityView> others = manager.getOthersView();
        for (EntityView e : others) {
            Entity entity = e.getEntity();
            graphics2D.drawImage(e.getCurrentDrawing(), null,
                    entity.getX(), entity.getY());
        }
    }
}

@@ -92,29 +92,8 @@
 iew;
-%0Aimport engine.Level;
 %0A%0Aim
@@ -127,24 +127,62 @@
 java.awt.*;%0A
+import java.awt.geom.AffineTransform;%0A
 import java.
@@ -677,48 +677,8 @@
 g);%0A
-        System.out.println(%22repaint%22);%0A%0A
     
@@ -900,24 +900,25 @@
 tity();%0A
+%0A
         
 graphics
@@ -913,114 +913,197 @@
     
-graphics2D.drawImage(gluttonView.getCurrentDrawing(), null,%0A                glutton.getX(), glutton.getY()
+AffineTransform t = new AffineTransform();%0A        t.translate(glutton.getX(), glutton.getY());%0A        t.scale(1, 1);%0A%0A        graphics2D.drawImage(gluttonView.getCurrentDrawing(), t, null
 );%0A%0A
@@ -1261,32 +1261,33 @@
  e.getEntity();%0A
+%0A
             grap
@@ -1286,106 +1286,201 @@
     
-graphics2D.drawImage(e.getCurrentDrawing(), null,%0A                    entity.getX(), entity.getY()
+AffineTransform nt = new AffineTransform();%0A            nt.translate(entity.getX(), entity.getY());%0A            nt.scale(1, 1);%0A%0A            graphics2D.drawImage(e.getCurrentDrawing(), nt, null
 );%0A 
@@ -1631,24 +1631,25 @@
 etEntity();%0A
+%0A
             
@@ -1652,106 +1652,201 @@
     
-graphics2D.drawImage(e.getCurrentDrawing(), null,%0A                    entity.getX(), entity.getY()
+AffineTransform ot = new AffineTransform();%0A            ot.translate(entity.getX(), entity.getY());%0A            ot.scale(1, 1);%0A%0A            graphics2D.drawImage(e.getCurrentDrawing(), ot, null
 );%0A 

use AffineTransform to get better performance drawing images.