import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.GridPane; import javafx.scene.shape.Rectangle; import javafx.scene.paint.Color; import java.util.ArrayList; public class EnkelMinesveiper extends Application{ private final int STORRELSE = 10; @Override public void start(Stage stage){ GridPane root = new GridPane(); Scene scene = new Scene(root); Rute[][] ruter = settOppBrett(); //i = rad, j = kolonne for (int i = 0; i < STORRELSE; i++) { for (int j = 0; j < STORRELSE; j++) { root.add(ruter[i][j], j, i); } } stage.setScene(scene); stage.setTitle("(Enkel) Minesveiper"); stage.show(); } private Rute[][] settOppBrett(){ Rute [][] ruter = new Rute[STORRELSE][STORRELSE]; for (int i = 0; i < STORRELSE; i++) { for (int j = 0; j < STORRELSE; j++) { ruter[i][j] = new Rute(); } } for (int i = 0; i < STORRELSE; i++) { for (int j = 0; j < STORRELSE; j++) { ArrayList naboer = hentNaboer(i, j, ruter); ruter[i][j].settNaboer(naboer); } } return ruter; } private ArrayList hentNaboer(int rad, int kol, Rute[][] ruter){ ArrayList naboer = new ArrayList<>(); for(int i = rad-1; i <= rad+1; i++){ for (int j = kol-1; j <= kol+1 ; j++) { boolean gyldig = true; //N?v?rende rute - skal ikke telles if(i == rad && j == kol) gyldig = false; //Kantruter venstre/oppe if(i < 0 || j < 0) gyldig = false; //Kantruter h?yre/nede if(i >= STORRELSE || j >= STORRELSE) gyldig = false; if(gyldig) naboer.add(ruter[i][j]); } } return naboer; } public static void main(String[] args) { launch(args); } }