Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaenprolog;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Application;
- import static javafx.application.Application.launch;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.GridPane;
- import javafx.scene.text.Text;
- import javafx.scene.control.TextField;
- import javafx.scene.shape.Box;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- import javax.swing.JOptionPane;
- import org.jpl7.Query;
- public class JavaEnProlog extends Application {
- @Override
- public void start(Stage stage) {
- //Creating a Grid Pane
- GridPane gridPane = new GridPane();
- //Setting size for the pane
- gridPane.setMinSize(100, 100);
- //Setting the padding
- gridPane.setPadding(new Insets(10, 10, 10, 10));
- //Setting the vertical and horizontal gaps between the columns
- gridPane.setVgap(5);
- gridPane.setHgap(5);
- //Setting the Grid alignment
- gridPane.setAlignment(Pos.CENTER);
- //Arranging all the nodes in the grid
- try{
- String t1 = "consult('mazmorra.pl')";
- Query q1 = new Query(t1);
- System.out.println(t1+""+(q1.hasSolution()?": Consulta Aceptada":": Consulta Fallida"));
- String t2 = "consult('imprimeMazmorra.pl')";
- Query q2 = new Query(t2);
- System.out.println(t2+""+(q2.hasSolution()?": Consulta Aceptada":": Consulta Fallida"));
- String t3 = "consult('resuelveMazmorra.pl')";
- Query q3 = new Query(t3);
- System.out.println(t3+""+(q3.hasSolution()?": Consulta Aceptada":": Consulta Fallida"));
- String eX, eY, sX, sY;
- int x1, x2, y1, y2;
- eX = JOptionPane.showInputDialog(null,"Escribe el número en X de tus coordenadas de entrada.");
- eY = JOptionPane.showInputDialog(null,"Escribe el número en Y de tus coordenadas de entrada.");
- sX = JOptionPane.showInputDialog(null,"Escribe el número en X de tus coordenadas de salida.");
- sY = JOptionPane.showInputDialog(null,"Escribe el número en Y de tus coordenadas de salida.");
- String t4 = "resuelve(["+eX+","+eY+"],["+sX+","+sY+"],Camino)";
- Query q4 = new Query(t4);
- //System.out.println(t4+""+(q4.nextSolution()?": Consulta Aceptada":": Consulta Fallida"));
- q4.hasSolution();
- x1 = Integer.parseInt(eX);
- y1 = Integer.parseInt(eY);
- x2 = Integer.parseInt(sX);
- y2 = Integer.parseInt(sY);
- String cadena;
- FileReader f = new FileReader("E:/Prolog/JavaEnProlog/mazmorraArchivo.txt");
- BufferedReader b = new BufferedReader(f);
- int fila = 0;
- while((cadena = b.readLine())!=null) {
- System.out.println(cadena);
- for(int columna = 0; columna < cadena.length(); columna++){
- if(fila == x1 && columna == y1){
- Rectangle rec3 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec3.setFill(javafx.scene.paint.Color.BLUE);
- gridPane.add(rec3, columna, fila);
- } else if(fila == x2 && columna == y2){
- Rectangle rec3 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec3.setFill(javafx.scene.paint.Color.PURPLE);
- gridPane.add(rec3, columna, fila);
- } else if(cadena.charAt(columna) == 'u') {
- Rectangle rec3 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec3.setFill(javafx.scene.paint.Color.RED);
- gridPane.add(rec3, columna, fila);
- } else if(cadena.charAt(columna) == '+') {
- Rectangle rec3 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec3.setFill(javafx.scene.paint.Color.RED);
- gridPane.add(rec3, columna, fila);
- } else if(cadena.charAt(columna) == 'x') {
- Rectangle rec1 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec1.setFill(javafx.scene.paint.Color.RED);
- gridPane.add(rec1, columna, fila);
- } else if(cadena.charAt(columna) == 'o') {
- Rectangle rec2 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec2.setFill(javafx.scene.paint.Color.GREEN);
- gridPane.add(rec2, columna, fila);
- } else if(cadena.charAt(columna) == '.') {
- Rectangle rec3 = new Rectangle(0, 0, 20.0f, 20.0f);
- rec3.setFill(javafx.scene.paint.Color.WHITE);
- gridPane.add(rec3, columna, fila);
- }
- }
- fila++;
- }
- b.close();
- } catch (IOException ex) {
- Logger.getLogger(JavaEnProlog.class.getName()).log(Level.SEVERE, null, ex);
- }
- //Creating a scene object
- Scene scene = new Scene(gridPane);
- //Setting title to the Stage
- stage.setTitle("Laberinto");
- //Adding scene to the stage
- stage.setScene(scene);
- //Displaying the contents of the stage
- stage.show();
- }
- public static void main(String args[]){
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement