Maze
2016-07-01 08:25:07 0 举报
AI智能生成
Maze,一个充满神秘与挑战的地方。它是由无数错综复杂的通道和死胡同组成的迷宫,让人在其中迷失方向,寻找出路。每一条通道都充满了未知,每一步都可能引领你走向新的迷宫深处或者回到原点。Maze是一个考验智慧和耐心的地方,只有通过不断的尝试和错误,才能找到通往出口的道路。然而,即使在最困难的时候,Maze也总能给人带来惊喜和乐趣。当你终于找到出口的那一刻,你会感受到从未有过的成就感和满足感。Maze,一个让人既感到困惑又充满期待的地方。
作者其他创作
大纲/内容
package cn.cqut.edu.test;
import java.io.File;
//import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;
import javafx.application.Application;
//import javafx.event.ActionEvent;
//import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
//import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class Maze extends Application
{
public static void main(String[] args) throws Exception
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
//�Թ��Ľ���
LinePane LinePane=new LinePane();//���Թ����ࣻ
BorderPane bPane=new BorderPane();
StackPane sPane=new StackPane();
sPane.getChildren().add(LinePane);//���Թ���ͼ��������ϣ�
VBox vbox=new VBox(80);
vbox.setPadding(new Insets(100));
vbox.setSpacing(25);
HBox hbox = new HBox();
hbox.setPadding(new Insets(100));//��������������ҵļ�ࣻ
Button bt2=new Button("Ѱ��·��");
//Button bt3=new Button("�����Թ�");
Button bt4=new Button("���·��");
Button bt5=new Button("��ʼ���Թ�");
vbox.getChildren().addAll(bt2,bt4,bt5);//�Ѱ�ť���ڴ�ֱ����У�
bPane.setRight(vbox);
bPane.setCenter(sPane);
bt2.setOnMouseClicked(e->{
try
{
getPath getpath=new getPath();//���·�����ࣻ
sPane.getChildren().add(getpath);
} catch (Exception e1)
{
e1.printStackTrace();
}
});//�Ѹ÷������ӵ���ť�±ߣ�
bt5.setOnMouseClicked(e->{
try
{
Innitional innitional=new Innitional();
sPane.getChildren().add(innitional);
} catch (Exception e1)
{
e1.printStackTrace();
}
});
bt2.setFont(Font.font("Times New Rooman",FontWeight.BOLD,FontPosture.ITALIC,20));//���õ��ֵĴ�С�����ͣ�
//bt3.setFont(Font.font("Times New Rooman",FontWeight.BOLD,FontPosture.ITALIC,20));
bt4.setFont(Font.font("Times New Rooman",FontWeight.BOLD,FontPosture.ITALIC,20));
bt5.setFont(Font.font("Times New Rooman",FontWeight.BOLD,FontPosture.ITALIC,20));
bt2.setStyle("-fx-border-color:blue;-fx-border-width:4");//���ð�ť�ı�Ե�ߵ���ɫ�Ϳ�ȣ�
//bt3.setStyle("-fx-border-color:red;-fx-border-width:4");
bt4.setStyle("-fx-border-color:pink;-fx-border-width:4");
bt5.setStyle("-fx-border-color:yellow;-fx-border-width:4");
Scene scene=new Scene(bPane,1400,600);//���ý���Ĵ�С��
primaryStage.setScene(scene);
primaryStage.show();
}
}
class getMaze
{
String[][] a=new String[8][8];//����һ�����ļ��е��ַ��������飻
public getMaze()throws Exception
{
File file=new File("F:/����ѧ��/�Թ��������ʾversion2/maze.txt");//����һ�����ļ���
try(Scanner input=new Scanner(file))//���ļ����룻
{
while (input.hasNext())
{
for(int j=0;j<8;j++)
{
for(int k=0;k<8;k++)
{
a[j][k]=input.next();//���ļ��е��ַ������Ұ�����������a��
}
}
}
}
}
}
class LinePane extends Pane
{
public LinePane() throws Exception
{
BorderPane pane=new BorderPane();
getMaze getmaze=new getMaze();//�����ϱߵĺ�����
for(int j=0;j<8;j++)//��
{
for(int k=0;k<8;k++)//��
{
for(int n=0;n<4;n++)//�ַ����ij��ȣ�
{
char c=getmaze.a[j][k].charAt(n);//ȡij���ַ������ض�λ�õ��ַ���
Line l;
Line l1;
Line l2;
Line l3;
if(n==0&&c=='1')//�ض�λ�õ��ַ��������ַ��ıȽϣ�
{
l=new Line(60 + 50 * k, 50 + 50 * j, 60 + 50 * (k + 1), 50 + 50 * j);//������Ӧ�������ߣ�
pane.getChildren().add(l);
l.setStrokeWidth(2);//�����ߵĿ�ȣ�
}
if(n==1&&c=='1')
{
l1=new Line(60 + 50 * (k + 1), 50 + 50 * j, 60 + 50 * (k + 1), 50 + 50 * (j + 1));
pane.getChildren().add(l1);
l1.setStrokeWidth(2);
}
if(n==2&&c=='1')
{
l2=new Line(60 + 50 * (k + 1), 50 + 50 * (j + 1), 60 + 50 * k, 50 + 50 * (j + 1));
pane.getChildren().add(l2);
l2.setStrokeWidth(2);
}
if(n==3&&c=='1')
{
l3=new Line(60 + 50 * k, 50 + 50 * (j + 1), 60 + 50 * k, 50 + 50 * j);
pane.getChildren().add(l3);
l3.setStrokeWidth(2);
}
}
}
}
getChildren().add(pane);
VBox box = new VBox(12);// �����������ľ���
Label label1 = new Label(" 0");
Label label2 = new Label(" 1");
Label label3 = new Label(" 2");
Label label4 = new Label(" 3");
Label label5 = new Label(" 4");
Label label6 = new Label(" 5");
Label label7 = new Label(" 6");
Label label8 = new Label(" 7");
Label label0 = new Label("");// ʹ����0���ӵ�һ�ſ�ʼ
Label label01 = new Label("");// ʹ����0���ӵ�һ�п�ʼ
label1.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label2.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label3.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label4.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label5.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label6.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label7.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label8.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
Label label = new Label(" 0 1 2 3 4 5 6 7 ");// �����������
label.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));// ���ú�����������
label.setAlignment(Pos.BOTTOM_CENTER);
Circle circle=new Circle(75,75,10);//�ڳ�ʼλ�÷���һ��С��
Circle circle1=new Circle(430,430,10);//��ĩλ�÷���һ��С��
circle1.setFill(Color.RED);//����С�����ɫ��
circle.setFill(Color.RED);
// ���������ּ���ҳ����;
box.getChildren().addAll(label0, label01, label1, label2, label3, label4, label5, label6, label7, label8);
getChildren().addAll(label,circle,circle1, box);
}
}
class getPath extends Pane
{
public getPath() throws Exception
{
getMaze getmaze=new getMaze();
int startx=0;
int starty=0;
int endx=7;
int endy=7;
ArrayList list = new ArrayList<>();//�����淽��
char[] change=new char[4];//��������ַ�0,1,2,3�ֱ��ʾ�ϣ��ң��£���
Stack stack=new Stack<>();//������λ�ã�
while(true)
{
if(startx==endx&&starty==endy)
break;
else
{
if(startx+1<8&&getmaze.a[starty][startx].charAt(1)=='0')//��������
{
list.add(1);
change=getmaze.a[starty][startx].toCharArray();//���ַ���ת��Ϊһ���ַ����飻
change[1]='1';//�������·�߹��������Ϊ��ǽ��·��
getmaze.a[starty][startx]=String.valueOf(change);//���Ĺ����·�������ԭ����·��λ�ã�
startx++;
stack.push(new Point2D(startx, starty));//��ջ�м����߹���·�����б���бꣻ
}
else if(starty+1<8&&getmaze.a[starty][startx].charAt(2)=='0')//������
{
list.add(2);
change=getmaze.a[starty][startx].toCharArray();//���ַ���ת��Ϊһ���ַ����飻
change[2]='1';//�������·�߹��������Ϊ��ǽ��·��
getmaze.a[starty][startx]=String.valueOf(change);//���Ĺ����·�������ԭ����·��λ�ã�
starty++;
stack.push(new Point2D(startx, starty));//��ջ�м����߹���·�����б���бꣻ
}
else if(startx-1>0&&getmaze.a[starty][startx].charAt(3)=='0')//�����ߣ�
{
list.add(3);
change=getmaze.a[starty][startx].toCharArray();//���ַ���ת��Ϊһ���ַ����飻
change[3]='1';//�������·�߹��������Ϊ��ǽ��·��
getmaze.a[starty][startx]=String.valueOf(change);//���Ĺ����·�������ԭ����·��λ�ã�
startx--;
stack.push(new Point2D(startx, starty));
}
else if(starty-1>0&&getmaze.a[starty][startx].charAt(0)=='0')//�����ߣ�
{
list.add(0);
change=getmaze.a[starty][startx].toCharArray();//���ַ���ת��Ϊһ���ַ����飻
change[0]='1';//�������·�߹��������Ϊ��ǽ��·��
getmaze.a[starty][startx]=String.valueOf(change);//���Ĺ����·�������ԭ����·��λ�ã�
starty--;
stack.push(new Point2D(startx, starty));
}
else
{
stack.pop();//�Ѳ����ߵ�·��Ԫ���Ƴ���
if(list.get(list.size()-1)==1)//�б�ij��ȼ�һ��Ϊ���߹��ķ���
{
startx--;//�����߷���ʱ��������һ��
}
if(list.get(list.size()-1)==2)
{
starty++;//�����߷���ʱ�������һ��
}
if(list.get(list.size()-1)==3)
{
startx++;//�����߷���ʱ�������һ��
}
if(list.get(list.size()-1)==0)
{
starty--;//�����߷���ʱ�������һ��
}
}
}
}
for(int i=0;i
{
//���߹�������֮����������
Line line=new Line(50*stack.get(i).getX()+80,50*stack.get(i).getY()+70,80+50*stack.get(i+1).getX(),50*stack.get(i+1).getY()+70);//������ҿ����ߵĻ��������1��
line.setStroke(Color.GREEN);
line.setStrokeWidth(4);
getChildren().add(line);
}
}
}
class Innitional extends Pane
{
Innitional() throws Exception
{
BorderPane pane=new BorderPane();
getMaze getmaze=new getMaze();
for(int j=0;j<8;j++)
{
for(int k=0;k<8;k++)
{
for(int n=0;n<4;n++)
{
char c=getmaze.a[j][k].charAt(n);
Line l;
Line l1;
Line l2;
Line l3;
if(n==0&&c=='1')
{
l=new Line(60 + 50 * k, 50 + 50 * j, 60 + 50 * (k + 1), 50 + 50 * j);
pane.getChildren().add(l);
l.setStrokeWidth(2);
}
if(n==1&&c=='1')
{
l1=new Line(60 + 50 * (k + 1), 50 + 50 * j, 60 + 50 * (k + 1), 50 + 50 * (j + 1));
pane.getChildren().add(l1);
l1.setStrokeWidth(2);
}
if(n==2&&c=='1')
{
l2=new Line(60 + 50 * (k + 1), 50 + 50 * (j + 1), 60 + 50 * k, 50 + 50 * (j + 1));
pane.getChildren().add(l2);
l2.setStrokeWidth(2);
}
if(n==3&&c=='1')
{
l3=new Line(60 + 50 * k, 50 + 50 * (j + 1), 60 + 50 * k, 50 + 50 * j);
pane.getChildren().add(l3);
l3.setStrokeWidth(2);
}
}
}
}
getChildren().add(pane);
VBox box = new VBox(12);// �����������ľ���
Label label1 = new Label(" 0");
Label label2 = new Label(" 1");
Label label3 = new Label(" 2");
Label label4 = new Label(" 3");
Label label5 = new Label(" 4");
Label label6 = new Label(" 5");
Label label7 = new Label(" 6");
Label label8 = new Label(" 7");
Label label0 = new Label("");// ʹ����0���ӵ�һ�ſ�ʼ
Label label01 = new Label("");// ʹ����0���ӵ�һ�п�ʼ
label1.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label2.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label3.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label4.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label5.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label6.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label7.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
label8.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));
Label label = new Label(" 0 1 2 3 4 5 6 7 ");// �����������
label.setFont(Font.font("Times New Roman", FontWeight.THIN, FontPosture.REGULAR, 35));// ���ú�����������
label.setAlignment(Pos.BOTTOM_CENTER);
Circle circle=new Circle(75,75,10);//�ڳ�ʼλ�÷���һ��С��
Circle circle1=new Circle(430,430,10);//��ĩλ�÷���һ��С��
circle1.setFill(Color.RED);
circle.setFill(Color.RED);
// ���������ּ���ҳ����;
box.getChildren().addAll(label0, label01, label1, label2, label3, label4, label5, label6, label7, label8);
getChildren().addAll(label,circle,circle1, box);
}
}
0 条评论
下一页

图形选择
思维导图
主题
补充说明
AI生成

提示
关闭后当前内容将不会保存,是否继续?
取消
确定