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 :(

4th May 2020, 11:07 PM
Jongin
Jongin - avatar
5 Respuestas
0
Where exactly are you stuck at? Could you explain properly?
4th May 2020, 11:22 PM
Mustafa K.
Mustafa K. - avatar
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...
4th May 2020, 11:39 PM
Jongin
Jongin - avatar
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?
4th May 2020, 11:44 PM
Jongin
Jongin - avatar
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.
5th May 2020, 1:37 AM
Mustafa K.
Mustafa K. - avatar
0
i can get the images’ coordinates but i dont know how to write. Fotoğrafın arraydeki yerini bulmakla ilgili problemler yaşıyorum.
5th May 2020, 10:33 PM
Jongin
Jongin - avatar