package sk.paz1a.practicals.task04;
import java.awt.Color;
import java.awt.event.MouseEvent;
import sk.upjs.jpaz2.Turtle;
import sk.upjs.jpaz2.WinPane;
public class GridPane extends WinPane {
private int counter;
public void drawGrid() {
int x = 0;
int y = 0;
int height = this.getHeight();
int width = this.getWidth();
Turtle kreslic = new Turtle();
this.add(kreslic);
while (x < width) {
kreslic.setPosition(x, 0);
kreslic.moveTo(x, height);
x = x + 50;
}
while (y < height) {
kreslic.setPosition(0, y);
kreslic.moveTo(width, y);
y = y + 50;
}
this.remove(kreslic);
}
public void drawDot(int column, int row, Color dotColor) {
Turtle kreslic = new Turtle();
this.add(kreslic);
kreslic.setFillColor(dotColor);
int x = 25 + column * 50;
int y = 25 + row * 50;
kreslic.setPosition(x, y);
kreslic.dot(20);
this.remove(kreslic);
}
protected void onMouseClicked(int x, int y, MouseEvent detail) {
if (counter % 2 == 0) {
drawDot(x / 50, y / 50, Color.RED);
} else {
drawDot(x / 50, y / 50, Color.BLUE);
}
counter++;
}
}