0
JavaFX game
Im making a game in java fx as a project assignment. The game is about moving a ball from a start point to an end point if there is an appropriate path. The user is supposed to form a path using pipes as sliding tiles. I printed and move the tile images of the game. But i have some problems i cant get any further , can anyone help me ? I cant send the detailed code here :(
5 Respostas
0
Where exactly are you stuck at? Could you explain properly?
0
// Create a scanner to read files
Scanner input = new Scanner(file);
Tile[] tiles = new Tile[16];
int i = 0;
//Read file input
while(input.hasNext()) {
String line = input.nextLine();
if (!line.equals("")) {
String[] parsedStr = line.split(",");
int id = Integer.parseInt(parsedStr[0]);
tiles[i] = new Tile(id, parsedStr[1], parsedStr[2]);
i++;
}
}
input.close();
Level level = new Level(1,tiles);
GridPane pane = new GridPane();
// Add tiles to the grid pane
ArrayList<ImageView> imageView = new ArrayList<>();
for (int j = 0; j < level.getTiles().length ; j++) {
ImageView imgView = new ImageView(level.getTile(j).getImage());
imgView.setX(100);
imgView.setY(100);
pane.add(imgView , j%4 , j/4);
imageView.add(imgView);
}
for (i = 0; i < imageView.size(); i++) {
ImageView source = (ImageView) imageView.get(i);
ImageView target = (ImageView) imageView.get(i);
if(tiles[i].getType().equals("Starter") || tiles[i].getType().equals("End") || tiles[i].getType().equals("Static")) {
}
else {
source.setOnDragDetected((MouseEvent event) -> {
db = source.startDragAndDrop(TransferMode.MOVE);
clipboard = new ClipboardContent();
clipboard.putImage(source.getImage());
db.setContent(clipboard);
event.consume();
});
target.setOnDragOver((DragEvent event) -> {
if (event.getGestureSource() != target && event.getDragboard().hasImage()) {
event.acceptTransferModes(TransferMode.MOVE);
}
event.consume();
});
target.setOnDragEntered((DragEvent event) -> {
if (event.getGestureSource() != target && event.getDragboard().hasImage()) {
}
event.consume();
});
target.setOnDragExited((DragEvent event) -> {
target.setStyle("");
event.consume();
});
continues...
0
target.setOnDragDropped((DragEvent event) -> {
cb = new ClipboardContent();
cb.putImage(target.getImage());
boolean success = false;
if (db.hasImage()) {
target.setImage(db.getImage());
success = true;
}
event.setDropCompleted(success);
event.consume();
});
source.setOnDragDone((DragEvent event) -> {
if (event.getTransferMode() == TransferMode.MOVE)
source.setImage(cb.getImage());
});
}
}
This part is for moving tiles. How do we find out which tile images have been moved so that we can make win status after moving the tiles?
0
Is there a way to get the pixel coordinates of the image you click on? If yes, then you could think checking each images' coordinates in array with the one clicked. Then you can store the indices of the images clicked in an array.
0
i can get the images’ coordinates but i dont know how to write. Fotoğrafın arraydeki yerini bulmakla ilgili problemler yaşıyorum.