import javax.swing.*;
import java.awt.*;

public class MapJPanel extends JPanel{

	private Graphics buffer;
	private Image image;
	//private Image imageTile;
	//private Toolkit toolkit = Toolkit.getDefaultToolkit();
	
	int mapGrid[][]=new int[100][100];
	
	public MapJPanel(){
		
		remplissageMapGrid();
	
	}
	
	
	public void remplissageMapGrid(){
		for(int x=0;x<100;x++){
			for(int y=0;y<100;y++){
        	
	        	mapGrid[x][y]=9;
	        	
		 	}
		 }
	}
	
	
	
	
	public void update(Graphics g){	
		paint(g);
	}
	
	
	
	public void paint (Graphics g){
		//création du buffer s'il n'existe pas
 		if(buffer == null){
 			
 			image = createImage(200 ,200 );
 			buffer = image.getGraphics();
 		}
		
	
		// on dessine le terrain noir.
 		buffer.setColor(Color.black);
        buffer.fillRect(0,0,200,200);
        
        //0 rien, 1 obstacle 2 perso 3 escalier 4 creature
        
        for(int x=0;x<100;x++){
        	for(int y=0;y<100;y++){
        		
        		
    			if(mapGrid[x][y]==0){
    				buffer.setColor(Color.black);
    				buffer.fillRect(x*2,y*2,2,2);
    			}
    			
    			if(mapGrid[x][y]==1){
    				buffer.setColor(Color.red);
    				buffer.fillRect(x*2,y*2,2,2);
    			}
        		
        		if(mapGrid[x][y]==2){
    				buffer.setColor(Color.white);
    				buffer.fillRect(x*2,y*2,2,2);
    			}
    			
    			if(mapGrid[x][y]==3){
    				buffer.setColor(Color.green);
    				buffer.fillRect(x*2,y*2,2,2);
    			}
    			
    			if(mapGrid[x][y]==4){
    				buffer.setColor(Color.yellow);
    				buffer.fillRect(x*2,y*2,2,2);
    			}
    			
    			
    			if(mapGrid[x][y]==9){
    				buffer.setColor(Color.blue);
    				buffer.fillRect(x*2,y*2,2,2);
    			}
	 			
		 		
        	}
        	
        }
        
        
        g.drawImage(image,0,0,this);
		
	}
	
	
	
	
}