PImage black_checker;
PImage white_checker;
int arrayfields[][] = new int[8][8];
int EMPTY = 0;
int COLGRAY = 2;
int IFields = 0;
int ZFields = 0;
void setup() {
size(500, 500);
black_checker = loadImage("black.png"); //изображение шашки 50x50
white_checker = loadImage("white.png");
for (int i = 0;i < 8;i++)
{
for (int z = 0; z < 8; z++)
{
arrayfields[i][z] = EMPTY;
}
}
for (int i = 0;i < 8;i++)
{
for (int z = 0; z < 8; z++)
{
fill(255,255,255);
if (i%2 == 0 && z%2 == 0 )
{
arrayfields[i][z] = 1;
fill(0,0,0);
}
if (i%2 == 1 && z%2 == 1)
{
arrayfields[i][z] = 1;
fill(0,0,0);
}
rect(i*50,z*50,50,50);
//if (z < 3 && arrayfields[i][z] == 1)
//image(white_checker,i*50+(25)/2,z*50+(25)/2,25,25);
//if (z > 4 && arrayfields[i][z] == 1)
//image(black_checker,i*50+(25)/2,z*50+(25)/2,25,25);
}
}
}
void draw() {
for (int i = 0;i < 8;i++)
{
for (int z = 0; z < 8; z++)
{
fill(255,255,255);
if (i%2 == 0 && z%2 == 0 && arrayfields[i][z] == 1)
{
fill(0,0,0);
}
if (i%2 == 1 && z%2 == 1 && arrayfields[i][z] == 1)
{
fill(0,0,0);
}
rect(i*50,z*50,50,50);
if (arrayfields[i][z] == 2){
fill(0,0,0);
rect(i*50,z*50,50,50);
image(white_checker,i*50+(25)/2,z*50+(25)/2,25,25);
}
}
}
}
void mousePressed()
{
for (int i = 0; i < 8; i++)
{
for (int z = 0; z < 8; z++)
{
if (mouseX > i*50 && mouseX < i*50 + 50 && mouseY > z*50 && mouseY < z*50+50 )
{
if (i%2 == 0 && z%2 == 0 )
{
//fill(122,122,122);
rect(i*50,z*50,50,50);
arrayfields[IFields][ZFields] = 1;
IFields = i;
ZFields = z;
arrayfields[i][z] = COLGRAY;
}
if (i%2 == 1 && z%2 == 1)
{
//fill(122,122,122);
rect(i*50,z*50,50,50);
arrayfields[IFields][ZFields] = 1;
IFields = i;
ZFields = z;
arrayfields[i][z] = COLGRAY;
}
}
}
}
}
|