package sk.paz1a.practicals.task4;
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 boolean lastWasBlue = false;
public void drawGrid() {
// zozeniem niekoho kto bude kreslit
Turtle someone = new Turtle();
this.add(someone);
// niekto nakresli zvisle ciary
for (int i = 0; i <= this.getWidth() / 50; i++) {
someone.setPosition(i * 50, 0);
someone.moveTo(i * 50, this.getHeight());
}
// niekto nakresli vodorovne ciary
for (int y = 0; y < this.getHeight(); y = y + 50) {
someone.setPosition(0, y);
someone.moveTo(this.getWidth(), y);
}
// podakujem sa a poslem ho prec
this.remove(someone);
}
public void drawDot(int column, int row, Color dotColor) {
Turtle someone = new Turtle();
this.add(someone);
someone.setPosition(column * 50 + 25, row * 50 + 25);
someone.setFillColor(dotColor);
someone.dot(20);
this.remove(someone);
}
protected void onMouseClicked(int x, int y, MouseEvent detail) {
if (this.lastWasBlue) {
this.drawDot(x / 50, y / 50, Color.RED);
} else {
this.drawDot(x / 50, y / 50, Color.BLUE);
}
this.lastWasBlue = !this.lastWasBlue;
}
}