Move the colors array to before the for loops and move the image creation line to inside the loops.
Basically, switch lines 30 and 40; and remove line 31.
Also, brown is not a recognized color of the Color class.
int[][]
import java.awt.*;
import java.awt.Color;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Map here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Map extends World
{
private int tabColors [][];
/**
* Constructor for objects of class Map.
*
*/
public Map()
{
super(100, 60, 15);
fillArray();
drawPolygon();
}
private void drawPolygon()
{
int size = getCellSize()*2; // Dimension de l'hexagone // Création d'un hexagone
int i = 0;
int j = 0;
int[] xs = { 0, 0, size/2, size, size, size/2 };
int[] ys = { size/4, size*3/4, size, size*3/4, size/4, 0 };
Color[] colors = { Color.black, Color.blue, Color.yellow, Color.black, Color.green, Color.green, Color.pink, Color.white };
for (i=0; i<20; i++) for (j=0; j<20; j++)
{
image.setColor(colors[tabColors[i][j]]);
image.drawPolygon(xs, ys, 6);
getBackground().drawImage(image, i*size/2, j*size*3/4);
}
GreenfootImage image = new GreenfootImage(size+1, size+1);
// Remplir le fond d'écran avec des hexagones
for (int i=0; i<20; i++)
{
for (int j=0; j<20; j++)
{
if ((i+j)%2 == 0) // Indique l'espacement entre les hexagones
{
GreenfootImage image = new GreenfootImage(size+1, size+1);
switch (tabColors[i][j]) //Attribuer une couleur à chaque valeur du tableau
{
case 0:
setColor(Color.black);
break;
case 1:
setColor(Color.blue);
break;
case 2:
setColor(Color.yellow);
break;
case 3:
setColor(Color.black);
break;
case 4:
setColor(Color.green);
break;
case 5:
setColor(Color.green);
break;
case 6:
setColor(Color.pink);
break;
case 7:
setColor(Color.white);
}
image.drawPolygon(xs, ys, 6);
getBackground().drawImage(image, i*size/2, j*size*3/4);
}
}
}
}
private int fillArray ()
{
int [][] tabColors = {{ { 2, 2, 3, 1, 1, 4, 4, 4, 5, 5, 5, 5, 5, 4, 4, 4, 1, 3, 3, 2 },
{ 2, 7, 3, 1, 4, 4, 4, 3, 5, 5, 5, 5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 7, 3, 5, 3, 7, 4, 4, 1, 3, 7, 6, 2 },
{ 6, 6, 0, 3, 3, 3, 1, 4, 4, 3, 3, 3, 3, 4, 4, 5, 1, 3, 3, 6 },
{ 6, 6, 3, 0, 0, 1, 0, 0, 3, 0, 0, 0, 4, 4, 5, 5, 7, 6, 1, 1 },
{ 6, 6, 6, 2, 0, 1, 0, 0, 3, 0, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6 },
{ 6, 7, 2, 2, 1, 0, 0, 3, 0, 0, 3, 3, 3, 0, 0, 2, 2, 2, 6, 6 },
{ 2, 2, 2, 2, 1, 2, 2, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 2, 2, 6 },
{ 2, 2, 3, 1, 1, 4, 4, 4, 5, 5, 5, 5, 5, 4, 4, 4, 1, 3, 3, 2 }}; import greenfoot.*;
import java.awt.Color;
public class Map extends World
{
private int tabColors [][];
public Map()
{
super(100, 60, 15);
fillArray();
drawPolygons();
}
private void drawPolygons()
{
int size = getCellSize()*2; // Dimension de l'hexagone // Création d'un hexagone
int[] xs = { 0, 0, size/2, size, size, size/2 };
int[] ys = { size/4, size*3/4, size, size*3/4, size/4, 0 };
Color[] colors = { Color.black, Color.blue, Color.yellow, Color.darkGray, Color.green, Color.green, Color.pink, Color.lightGray };
for (i=0; i<20; i++) for (j=0; j<20; j++)
{
GreenfootImage image = new GreenfootImage(size+1, size+1);
image.setColor(colors[tabColors[i][j]]);
image.fillPolygon(xs, ys, 6);
image.setColor(Color.white);
image.drawPolygon(xs, ys, 6);
getBackground().drawImage(image, i*size/2, j*size*3/4);
}
}
private void fillArray()
{
tabColors = { { 2, 2, 3, 1, 1, 4, 4, 4, 5, 5, 5, 5, 5, 4, 4, 4, 1, 3, 3, 2 },
{ 2, 7, 3, 1, 4, 4, 4, 3, 5, 5, 5, 5, 6, 4, 4, 1, 1, 1, 3, 2 },
{ 3, 3, 3, 6, 6, 6, 4, 3, 6, 6, 5, 5, 6, 6, 6, 1, 2, 3, 3,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7, 6, 2 },
{ 6, 6, 0, 3, 3, 3, 1, 4, 4, 3, 3, 3, 3, 4, 4, 5, 1, 3, 3, 6 },
{ 6, 6, 3, 0, 0, 1, 0, 0, 3, 0, 0, 0, 4, 4, 5, 5, 7, 6, 1, 1 },
{ 6, 6, 6, 2, 0, 1, 0, 0, 3, 0, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6 },
{ 6, 7, 2, 2, 1, 0, 0, 3, 0, 0, 3, 3, 3, 0, 0, 2, 2, 2, 6, 6 },
{ 2, 2, 2, 2, 1, 2, 2, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 2, 2, 6 },
{ 2, 2, 3, 1, 1, 4, 4, 4, 5, 5, 5, 5, 5, 4, 4, 4, 1, 3, 3, 2 }};
public Map()
{
super(100, 60, 15);
drawPolygons();
}
private void drawPolygons()
{
int size = getCellSize()*2; // Dimension de l'hexagone // Création d'un hexagone
int[] xs = { 0, 0, size/2, size, size, size/2 };
int[] ys = { size/4, size*3/4, size, size*3/4, size/4, 0 };
Color[] colors = { Color.black, Color.blue, Color.yellow, Color.darkGray, Color.green, Color.green, Color.pink, Color.lightGray };
for (int i=0; i<20; i++) for (int j=0; j<20; j++)
{
GreenfootImage image = new GreenfootImage(size+1, size+1);
image.setColor(colors[tabColors[i][j]]);
image.fillPolygon(xs, ys, 6);
image.setColor(Color.white);
image.drawPolygon(xs, ys, 6);
getBackground().drawImage(image, i*size/2, j*size*3/4);
}
}
}getBackground().drawImage(image, i*size+(j%2)*size/2, j*size*3/4);
int [][] tabColors = ...
tabColors = new int[][] { { 2, 2, .... int i = 20;
int j = 20;for (int i=0; i<20; i++) for (int j=0; j<20; j++)