Commit 7a5b9d15 authored by william.hill1's avatar william.hill1

need to fix loop

parent 526d7841
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.Scene;
public class Main extends Application {
public void start(Stage stage) {
int Boardsize = 10;
int[][]PlayerShips = new int[Boardsize][Boardsize];
Rectangle[][] playerRects = new Rectangle[Boardsize][Boardsize];
Group group = new Group ();
{
for (int y = 0; y < 10; ++y)
{
for (int x = 0; x < 10; ++x)
{
Rectangle r = new Rectangle ();
r.setX(90 * x);
r.setY(90 * y);
r.setWidth(90);
r.setHeight(90);
r.setFill(Color.BLUE);
r.setStroke(Color.WHITE);
group.getChildren().add(r);
playerRects[x][y] = r;
final int xc = x;
final int yc = y;
r.setOnMouseClicked(event -> {
int legnth = 5;
System.out.println("click at " + xc + " " + yc);
for(int i = 0;i < legnth; i++) {
legnth--;
System.out.println(legnth);
playerRects[xc][yc].setFill(Color.GREEN);
playerRects[xc+i][yc].setFill(Color.GREEN);
}
});
}
}
Scene scene = new Scene(group, 900,900);
stage.setScene(scene);
stage.show();
}
}
public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Battleships"); launch(args);
System.out.println("Hello world");
System.out.println("Hello world again");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment