JavaFX项目游戏—完整的推箱子程序–包含各个功能

JavaFX项目游戏—推箱子程序



前言

本项目包含基本的推箱子程序,并实现了选择关卡、排行榜、设置功能。
在游戏界面实现上下关、重置、提示功能。撤销功能暂未解决。并实现了在各个界面之间切换。
博主文笔不好就直接贴上源代码。如果看不懂或者有什么想法都欢迎私聊或者评论,共同进步


Element基类

package Game;
/*
 * 图片基础类
 * 定义:
 * 1.图片的x、y坐标
 * 2.图片宽高
 * 3.图片类型
 * */

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;

public class Element extends Pane {
    public static int cell = 30;
    static int imageCell = 50;
    private int x = 0;
    private int y = 0;
    private Image image;
    private ImageView imageView;

    public Element() {
    }

    public int getCell() {
        return cell;
    }

    public void setCell(int cell) {
        Element.cell = cell;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public void setImageView() {
        this.imageView = new ImageView(image);
        this.imageView.setFitWidth(cell);
        this.imageView.setFitHeight(cell);
        this.imageView.setY(y);
        this.imageView.setX(x);
    }

    public ImageView getImageView() {
        return imageView;
    }
}

Map类–关卡地图类,继承自Element

package Game;
/*
 * 关卡地图类
 * 绘制关卡
 * 作为主Pane
 * */


import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class Map extends Element {
    static int width = 380;
    private Element element = new Element();
    public static int cell  = 30;
    private int height = 320;
    private int[][] list;

    public static void setCell() {
        if(PlayGame.listNumber < 5){
            cell = 30;
        }else{
            cell = 20;
        }
        Element.cell = cell;
    }
    public static int getMapCell(){
        return cell;
    }

    public void setList(int[][] list) {
        this.list = list;
    }

    public ImageView getImagePlayer(int[] playerList) {
        return drawImagePlayer(playerList[0], playerList[1]);
    }

    public ImageView[] getImageBox(int boxNumber, int[][] boxList) {
        ImageView[] imageBox = new ImageView[boxNumber];
        for (int i = 0; i < boxNumber; i++) {
            imageBox[i] = drawImageBox(boxList[i][0], boxList[i][1]);
        }
        return imageBox;
    }


    public void drawMap() {
        Image image;
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                if (list[i][j] == 1) {
                    image = new Image("/image/qiang.jpg");
                    drawElement(i, j, image);
                } else if (list[i][j] == 2) {
                    image = new Image("/image/beijing.jpg");
                    drawElement(i, j, image);
                } else if (list[i][j] < 0) {
                    image = new Image("/image/beijing.jpg");
                    drawElement(i, j, image);
                } else if (list[i][j] == 4) {
                    image = new Image("/image/mubiaotu.jpg");
                    drawElement(i, j, image);
                } else if (list[i][j] == 5) {
                    image = new Image("/image/beijing.jpg");
                    drawElement(i, j, image);
                }
            }
        }
    }

    public void drawElement(int i, int j, Image image) {
        element.setX(cell * j);
        element.setY(cell * i);
        element.setImage(image);
        element.setImageView();
        getChildren().add(element.getImageView());
    }

    public ImageView drawImagePlayer(int i, int j) {
        element.setX(j * cell);
        element.setY(i * cell);
        element.setImage(new Image("/image/dongman.png"));
        element.setImageView();
        getChildren().add(element.getImageView());
        return element.getImageView();
    }

    public ImageView drawImageBox(int i, int j) {
        element.setX(j * cell);
        element.setY(i * cell);
        element.setImage(new Image("/image/xiangzi.jpg"));
        element.setImageView();
        System.out.println(cell);
        getChildren().add(element.getImageView());
        return element.getImageView();
    }

}

Lists类—生成关卡地图列表

package Game;
/*
* 关卡列表
* 用以输出关卡的列表表示
* */

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Lists {
    public int[][][] list;
    private int listNumber = 0;

    private int boxNumber = 0;
    private int[][] boxIndexList ;
    private int[] playerList = new int[2];
    private int[] boxList;
    private int[][] mubiaoList;

    public int[][][] getAllList(){
        return list;
    }

    public void initList(int[][] list){
        boxIndexList = new int[boxNumber][2];
        boxList = new int[boxNumber];
        mubiaoList = new int[boxNumber][2];
        int num = 0;
        int mubiaonumber = 0;
        for(int i=0;i<list.length;i++){
            for(int j=0;j<list[0].length;j++){
                if(list[i][j] < 0){
                    boxIndexList[num][0] = i;
                    boxIndexList[num][1] = j;
                    boxList[num] = list[i][j];
                    num++;
                }else if(list[i][j] == 5){
                    playerList[0] = i;
                    playerList[1] = j;
                }else if(list[i][j] == 4){
                    mubiaoList[mubiaonumber][0] = i;
                    mubiaoList[mubiaonumber][1] = j;
                    mubiaonumber++;
                }

            }
        }
    }

    public void setBoxNumber(int[][] list){
        boxNumber = 0;
        for(int[] row:list){
            for(int column : row){
                if(column < 0){
                    boxNumber++;
                }
            }
        }
    }
    public int getBoxNumber(){
        return boxNumber;
    }
    public int[] getPlayerList(){
        return playerList;
    }
    public int[][] getBoxIndexList(){
        return boxIndexList;
    }
    public int[] getBoxList(){
        return boxList;
    }
    public int[][] getMubiaoList(){
        return mubiaoList;
    }
    public int[][] getList(){
        return list[listNumber];
    }

    public boolean isSetBox(int i,int j){
        for(int[] row : mubiaoList){
            if(row[0] == i && row[1] == j){
                return true;
            }
        }
        return false;
    }
    public void setListNumber(int listNumber){
        this.listNumber = listNumber;
    }
    public int getListNumber(){
        return listNumber;
    }
    public int[][] setrowList(String str){
        int[][] strlists;
        int row = 0;
        int column = 0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i) != 'n'){
                column++;
            }else{
                row++;
            }
        }
        row++;
        column = column / row ;
        strlists = new int[row][column];
        int box = -1;
        for(int i=0;i<row;i++){
            for(int j=0;j<column;j++){
                char charat = str.charAt((column + 1) * i + j);
                if(charat == '_'){
                    strlists[i][j] = 0;
                } else if(charat == '#'){
                    strlists[i][j] = 1;
                }else if(charat == '-'){
                    strlists[i][j] = 2;
                }else if(charat == '.'){
                    strlists[i][j] = 4;
                }else if(charat == '@'){
                    strlists[i][j] = 5;
                }else if(charat == '$'){
                    strlists[i][j] = box;
                    box--;
                }
            }
        }
        return strlists;
    }
    public void setList(){
        int[][][] listqianwu = {
                {
                        {0, 0, 1, 1, 1, 1, 0, 0, 0},
                        {1, 1, 1, 2, 2, 1, 1, 1, 1},
                        {1, 2, 2, 2, 2, 2, -1, 2, 1},
                        {1, 2, 1, 2, 2, 1, -2, 2, 1},
                        {1, 2, 4, 2, 4, 1, 5, 2, 1},
                        {1, 1, 1, 1, 1, 1, 1, 1, 1}
                },
                {
                        {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
                        {1, 1, 1, 1, 2, 2, 2, 1, 0, 0, 0, 0},
                        {1, 4, 4, 1, -1, -2, 2, 1, 0, 0, 0, 0},
                        {1, 2, 4, 4, -3, 2, 2, 1, 1, 1, 1, 1},
                        {1, 2, 5, 1, 2, 1, 2, 1, 2, 2, 2, 1},
                        {1, 2, 2, -4, 2, 2, 2, 2, 2, -5, 2, 1},
                        {1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4, 1},
                        {1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1}
                },
                {
                        {0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
                        {0, 0, 1, 1, 2, 1, 0, 1, 1, 1, 1},
                        {0, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1},
                        {1, 1, 2, -1, 2, 2, 2, 2, 2, 2, 1},
                        {1, 2, 2, 2, 5, -2, 2, 1, 2, 2, 1},
                        {1, 1, 1, 2, -3, 1, 1, 1, 2, 2, 1},
                        {0, 0, 1, 2, 2, 1, 4, 4, 2, 2, 1},
                        {0, 1, 1, 2, 1, 1, 4, 1, 2, 1, 1},
                        {0, 1, 2, 2, 2, 2, 2, 2, 1, 1, 0},
                        {0, 1, 2, 2, 2, 2, 2, 1, 1, 0, 0},
                        {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}
                },
                {
                        {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
                        {0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 1},
                        {1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1},
                        {1, 2, -1, 2, -2, 2, 4, 4, 1, 2, 1},
                        {1, 2, 1, 2, 2, 4, 1, 2, 1, 2, 1},
                        {1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 1},
                        {1, 2, 1, 4, 1, 2, -3, 2, 2, 2, 1},
                        {1, 2, 1, 4, -5, 5, -4, 2, 2, 1, 1},
                        {1, 2, 1, -6, 1, 1, 1, 2, 2, 1, 0},
                        {1, 2, 2, 4, 2, 2, 2, 2, 2, 1, 0},
                        {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}
                },
                {
                        {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
                        {1, 2, 2, 2, 2, 2, 2, 2, 2, 1},
                        {1, 2, 2, -1, 2, -2, 2, -3, 2, 1},
                        {1, 1, 5, 1, 1, 1, 1, 1, 2, 1},
                        {1, 2, 2, 2, 4, 2, 4, 2, 4, 1},
                        {1, 2, 2, 2, 2, 2, 2, 2, 2, 1},
                        {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
                }
        };
        list = new int[25][][];
        for(int i=0;i<5;i++){
            list[i] = listqianwu[i];
        }
        int[][][] strlist = new int[0][][];
        try {
            strlist = changeStrToList();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        int i = 5;
        for(int[][] row : strlist){
            list[i] = row;
            i++;
        }
    }
    public void printlist(int[][] list) {
        for (int[] row : list) {
            for (int column : row) {
                System.out.print(column + " ");
            }
            System.out.println();
        }
    }
    public int[][][] changeStrToList() throws FileNotFoundException {
        int[][][] strlists = new int[20][][];
        File filestr = new File("E:\IDEAproject\推箱子游戏---java基础大作业\src\FileText\str.txt");
        File fileList = new File("E:\IDEAproject\推箱子游戏---java基础大作业\src\FileText\list.txt");
        try(
                Scanner input = new Scanner(filestr);
        ){
            for(int i=0;i<20;i++){
                String str1;
                int strNumber;
                String string = "";
                while(true) {
                    if(input.hasNextInt()){
                        strNumber = input.nextInt();
                        if(strNumber == i + 2){
                            break;
                        }
                    }else{
                        str1 = input.next();
                        string += str1 + "n";
                    }
                }
                string = string.substring(0,string.length() - 1);
                strlists[i] = setrowList(string);

            }
        }
        return strlists;
    }
}

CheckPonitAlert类—实现关卡通关后的Alert界面

package Game;

import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.stage.StageStyle;

import java.util.Optional;

public class CheckPointAlert {
    private Alert alert;

    public Alert getAlert() {
        return alert;
    }

    public void setALert(Alert.AlertType alertType, String title, String headText, String contentText, StageStyle stageStyle, Node graphic) {
        alert = new Alert(alertType);
        if (title != null) {
            alert.setTitle(title);
        }
        if (headText != null) {
            alert.setHeaderText(headText);
        }
        if (contentText != null) {
            alert.setContentText(contentText);
        }
        if (stageStyle != null) {
            alert.initStyle(stageStyle);
        }
        if (graphic != null) {
            alert.setGraphic(graphic);
        }

    }

    // xiayiguan
    public ButtonType setXiayiguanAlert() {
        alert.getButtonTypes().add(ButtonType.CANCEL);
        alert.getButtonTypes().add(ButtonType.NEXT);
        Optional<ButtonType> result = alert.showAndWait();
        ButtonType buttonType = result.get();
        return buttonType;
    }

}

PlayGame类—实现游戏功能

package Game;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class PlayGame {
    public static Lists lists = new Lists();
    public static ImageView imagePlayer;
    public static ImageView[] imageBox;
    public static int[][] list;
    public static int[] boxList;
    public static int listNumber = 0;
    public static int stepNumber = 0;
    public static Text textguanqia = new Text();
    public static Text textStep = new Text();
    Map map = new Map();
    CheckPointAlert checkPointAlert = new CheckPointAlert();
    BorderPane pane = new BorderPane();
    PlayButton playButton;
    HBox hBoxTop = new HBox(20);


    public BorderPane getPane() {
        return pane;
    }

    public ImageView getImagePlayer() {
        return imagePlayer;
    }

    public ImageView[] getImageBox() {
        return imageBox;
    }

    public int[][] getList() {
        return list;
    }

    public Lists getLists() {
        return lists;
    }

    public int[] getBoxList() {
        return boxList;
    }

    public PlayButton getPlayButton() {
        return playButton;
    }

    // 初始化关卡图
    public void initmap() {
        initList();
        map = new Map();
//        map.setPadding(new Insets(10, 0, 0, 0));
//        map.setMaxWidth(Map.width);
//        map.setMaxHeight(Map.width);
        stepNumber = 0;
        map.setList(list);
        // map.setCell();
        map.drawMap();
        imageBox = map.getImageBox(lists.getBoxNumber(), lists.getBoxIndexList());
        imagePlayer = map.getImagePlayer(lists.getPlayerList());

        pane.setCenter(map);
        pane.setTop(hBoxTop);
    }

    public void initText() {
        textguanqia.setText("第" + (listNumber + 1) + "关");
        textStep.setText(stepNumber + "步");
    }

    public void initTop() {
        initText();
        textguanqia.setFont(Font.font("Times", 30));
        textStep.setFont(Font.font("Times", 30));
        hBoxTop.setPadding(new Insets(10,10,10,10));
        hBoxTop.getChildren().addAll(textStep, textguanqia);
        hBoxTop.setAlignment(Pos.CENTER);
    }

    // initList
    public void initList() {
        lists = new Lists();
        lists.setListNumber(listNumber);
        lists.setList();
        list = lists.getList();
        lists.setBoxNumber(list);
        lists.initList(list);
        boxList = lists.getBoxList();
    }

    // background
    public void setBackGround() {
        ImageView imageView = new ImageView("/image/background.png");
        pane.getChildren().add(imageView);
        imageView.fitWidthProperty().bind(pane.widthProperty());
        imageView.fitHeightProperty().bind(pane.heightProperty());
    }

    //
    public void setPlayButton() {
        playButton = new PlayButton();
        pane.getChildren().add(playButton.getExit());
        pane.setBottom(playButton.getvBox());
    }

    // 判断玩家是否闯关成功
    public boolean isWin() {
        for (int[] row : list) {
            for (int column : row) {
                if (column == 4) {
                    return false;
                }
            }
        }
        return true;
    }

    // 闯关成功则生成Alert,并指向下一关
    public void createStage() {
        String title = "闯关成功";
        // String headText = "恭喜!成功闯过第 "+(listNumber+1)+" 关!";
        //String contentText = "恭喜!成功闯过第 "+(listNumber+1)+" 关! ";
        Text contentText = new Text("恭喜!成功闯过第 " + (listNumber + 1) + " 关! ");
        if (stepNumber < imageBox.length * 50) {
            contentText.setText(contentText.getText() + "完美通关");
        }
        contentText.setFont(Font.font("Times", 20));
        VBox vBox = new VBox(10);
        vBox.getChildren().add(new ImageView("/image/sanxing.gif"));
        vBox.getChildren().add(contentText);
        checkPointAlert.setALert(Alert.AlertType.NONE, title, null, null, null, vBox);
        ButtonType buttonType = checkPointAlert.setXiayiguanAlert();
        if (buttonType == ButtonType.NEXT) {
            if (listNumber < lists.getAllList().length - 1) {
                listNumber++;
            } else if (listNumber == lists.getAllList().length - 1) {
                checkPointAlert.setALert(Alert.AlertType.NONE, title, "恭喜!成功闯过所有的关卡", null, null, new ImageView("/image/guzhang.gif"));
                buttonType = checkPointAlert.setXiayiguanAlert();
            }
        }
        System.out.println("Win!"+(listNumber));
    }

    // 写闯关记录
    public void setrecord() {
        File fileRrcord = new File("E:\IDEAproject\推箱子游戏---java基础大作业\src\FileText\chuangguanjilu.txt");
        try (PrintWriter output = new PrintWriter(fileRrcord)) {
            output.println(listNumber + 1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    // 读取闯关记录
    public void sethuifurecord() {
        File fileRrcord = new File("E:\IDEAproject\推箱子游戏---java基础大作业\src\FileText\chuangguanjilu.txt");
        try (Scanner input = new Scanner(fileRrcord)) {
            listNumber = input.nextInt() - 1;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void printlist(int[][] list) {
        for (int[] row : list) {
            for (int column : row) {
                System.out.print(column + " ");
            }
            System.out.println();
        }
    }
}

Move类—操作移动

package Controller;

import Game.Element;
import Game.Map;
import Game.PlayButton;
import Game.PlayGame;
import javafx.scene.image.ImageView;

import java.util.ArrayList;

public class Move {
    public static ArrayList<Integer> listNumber = new ArrayList<>();
    ArrayList<Integer> direction = new ArrayList<>();
    PlayGame playGame;
    PlayButton playButton;
    private int cell = 30;

    public Move(PlayGame playGame) {
        this.playGame = playGame;
    }

    // 获取人物的I
    public int getI(ImageView imageView) {
        return (int) (imageView.getY() / cell);
    }

    // 获取人物的J
    public int getJ(ImageView imageView) {
        return (int) (imageView.getX() / cell);
    }

    public void playerMove() {
        playButton = playGame.getPlayButton();
        turnUP();
        turnDOWN();
        turnLEFT();
        turnRIGHT();
//        turnTuiyibu();
    }

    public void IsWin() {
        if (playGame.isWin()) {
            listNumber.add(PlayGame.listNumber);
            listNumber.add(PlayGame.stepNumber);
            playGame.createStage();
            playGame.initmap();
            if(PlayGame.listNumber < 5){
                cell = 30;
            }else{
                cell = 20;
            }
        }
        System.out.println(PlayGame.listNumber+" "+cell);
    }

    // UP
    public void turnUP() {
        playButton.getUp().setOnAction(e -> {
            up(1);
        });
    }

    public void up(int flag) {
        int i = getI(PlayGame.imagePlayer);
        int j = getJ(PlayGame.imagePlayer);
        if (PlayGame.list[i - 1][j] != 1) {
            if (PlayGame.list[i - 1][j] == 2 || PlayGame.list[i - 1][j] == 5 || PlayGame.list[i - 1][j] == 4) {
                PlayGame.imagePlayer.setY(PlayGame.imagePlayer.getY() - cell);
                PlayGame.stepNumber++;
                playGame.initText();
                direction.add(1);
            }
            for (int k = 0; k < PlayGame.boxList.length; k++) {
                if (PlayGame.list[i - flag][j] == PlayGame.boxList[k]) {
                    if (PlayGame.list[getI(PlayGame.imageBox[k]) - flag][getJ(PlayGame.imageBox[k])] > 1) {
                        PlayGame.list[i - flag][j] = 2;
                        PlayGame.list[i - 2 * flag][j] = PlayGame.boxList[k];
                        if (PlayGame.lists.isSetBox(i - flag, j)) {
                            PlayGame.list[i - flag][j] = 4;
                        }
                        PlayGame.imageBox[k].setY(PlayGame.imageBox[k].getY() - cell);
                        PlayGame.imagePlayer.setY(PlayGame.imagePlayer.getY() - cell);
                        PlayGame.stepNumber++;
                        playGame.initText();
                        direction.add(1);
                    }
                }
            }
            System.out.println("UP");
            IsWin();
            printlist(PlayGame.list);
        }
    }

    // DOWN
    public void turnDOWN() {
        playButton.getDown().setOnAction(e -> {
            down(1);
        });

    }

    public void down(int flag) {
        int i = getI(PlayGame.imagePlayer);
        int j = getJ(PlayGame.imagePlayer);
        if (PlayGame.list[i + 1][j] != 1) {
            if (PlayGame.list[i + 1][j] == 2 || PlayGame.list[i + 1][j] == 5 || PlayGame.list[i + 1][j] == 4) {
                PlayGame.imagePlayer.setY(PlayGame.imagePlayer.getY() + cell);
                PlayGame.stepNumber++;
                playGame.initText();
                direction.add(2);
            }
            for (int k = 0; k < PlayGame.boxList.length; k++) {
                if (PlayGame.list[i + flag][j] == PlayGame.boxList[k]) {
                    if (PlayGame.list[getI(PlayGame.imageBox[k]) + flag][getJ(PlayGame.imageBox[k])] > 1) {
                        PlayGame.list[i + flag][j] = 2;
                        PlayGame.list[i + flag * 2][j] = PlayGame.boxList[k];
                        if (PlayGame.lists.isSetBox(i + flag, j)) {
                            PlayGame.list[i + flag][j] = 4;
                        }
                        PlayGame.imageBox[k].setY(PlayGame.imageBox[k].getY() + cell);
                        PlayGame.imagePlayer.setY(PlayGame.imagePlayer.getY() + cell);
                        PlayGame.stepNumber++;
                        playGame.initText();
                        direction.add(2);
                    }
                }
            }
            System.out.println("DOWN");
            IsWin();
            printlist(PlayGame.list);
        }
    }

    // Left
    public void turnLEFT() {
        playButton.getLeft().setOnAction(e -> {
            left(1);
        });
    }

    public void left(int flag) {
        int i = getI(PlayGame.imagePlayer);
        int j = getJ(PlayGame.imagePlayer);
        if (PlayGame.list[i][j - 1] != 1) {
            if (PlayGame.list[i][j - 1] == 2 || PlayGame.list[i][j - 1] == 5 || PlayGame.list[i][j - 1] == 4) {
                PlayGame.imagePlayer.setX(PlayGame.imagePlayer.getX() - cell);
                PlayGame.stepNumber++;
                playGame.initText();
                direction.add(3);
            }
            for (int k = 0; k < PlayGame.boxList.length; k++) {
                if (PlayGame.list[i][j - flag] == PlayGame.boxList[k]) {
                    if (PlayGame.list[getI(PlayGame.imageBox[k])][getJ(PlayGame.imageBox[k]) - flag] > 1) {
                        PlayGame.list[i][j - flag] = 2;
                        PlayGame.list[i][j - 2 * flag] = PlayGame.boxList[k];
                        if (PlayGame.lists.isSetBox(i, j - flag)) {
                            PlayGame.list[i][flag - 1] = 4;
                        }
                        PlayGame.imageBox[k].setX(PlayGame.imageBox[k].getX() - cell);
                        PlayGame.imagePlayer.setX(PlayGame.imagePlayer.getX() - cell);
                        PlayGame.stepNumber++;
                        playGame.initText();
                        direction.add(3);
                    }
                }
            }
            IsWin();
            System.out.println("LEFT");
            printlist(PlayGame.list);
        }
    }

    // RIGHT
    public void turnRIGHT() {
        playButton.getRight().setOnAction(e -> {
            right(1);
        });
    }

    public void right(int flag) {
        int i = getI(PlayGame.imagePlayer);
        int j = getJ(PlayGame.imagePlayer);
        if (PlayGame.list[i][j + 1] != 1) {
            if (PlayGame.list[i][j + 1] == 2 || PlayGame.list[i][j + 1] == 5 || PlayGame.list[i][j + 1] == 4) {
                PlayGame.imagePlayer.setX(PlayGame.imagePlayer.getX() + cell);
                PlayGame.stepNumber++;
                playGame.initText();
                direction.add(4);
            }
            for (int k = 0; k < PlayGame.boxList.length; k++) {
                if (PlayGame.list[i][j + flag] == PlayGame.boxList[k]) {
                    if (PlayGame.list[getI(PlayGame.imageBox[k])][getJ(PlayGame.imageBox[k]) + flag] > 1) {
                        PlayGame.list[i][j + flag] = 2;
                        PlayGame.list[i][j + 2 * flag] = PlayGame.boxList[k];
                        if (PlayGame.lists.isSetBox(i, j + flag)) {
                            PlayGame.list[i][j + flag] = 4;
                        }
                        PlayGame.imageBox[k].setX(PlayGame.imageBox[k].getX() + cell);
                        PlayGame.imagePlayer.setX(PlayGame.imagePlayer.getX() + cell);
                        PlayGame.stepNumber++;
                        playGame.initText();
                        direction.add(4);
                    }
                }
            }
            IsWin();
            System.out.println("RIGHT");
            printlist(PlayGame.list);
        }
    }

    public void printlist(int[][] list) {
        for (int[] row : list) {
            for (int column : row) {
                System.out.print(column + " ");
            }
            System.out.println();
        }
    }

    public void printlist(int[] list) {
        for (int row : list) {
            System.out.println(row + " ");
        }
    }
}

package Game;

import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.stage.StageStyle;

import java.util.Optional;

public class CheckPointAlert {
    private Alert alert;

    public Alert getAlert() {
        return alert;
    }

    public void setALert(Alert.AlertType alertType, String title, String headText, String contentText, StageStyle stageStyle, Node graphic) {
        alert = new Alert(alertType);
        if (title != null) {
            alert.setTitle(title);
        }
        if (headText != null) {
            alert.setHeaderText(headText);
        }
        if (contentText != null) {
            alert.setContentText(contentText);
        }
        if (stageStyle != null) {
            alert.initStyle(stageStyle);
        }
        if (graphic != null) {
            alert.setGraphic(graphic);
        }

    }

    // xiayiguan
    public ButtonType setXiayiguanAlert() {
        alert.getButtonTypes().add(ButtonType.CANCEL);
        alert.getButtonTypes().add(ButtonType.NEXT);
        Optional<ButtonType> result = alert.showAndWait();
        ButtonType buttonType = result.get();
        return buttonType;
    }

}

PlayAction—程序的主类

package Game;

import Controller.Function;
import Controller.Move;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class PlayAction extends Application {
    PlayGame playGame = new PlayGame();
    StartScreen startScreen = new StartScreen();
    GuanqiaScreen guanqiaScreen = new GuanqiaScreen();
    SettingScreen settingScreen = new SettingScreen();
    PaihangScreen paihangScreen = new PaihangScreen();
    Move move;
    Function function;
    Scene sceneStartGame;
    Scene scenePlay = new Scene(playGame.getPane());


    @Override
    public void start(Stage primaryStage){
        playGame.setBackGround();
        startScreen.setScene();
        sceneStartGame = startScreen.getScene();
        playGame.sethuifurecord();
        playGame.initmap();
        playGame.initTop();
        playGame.setPlayButton();
        move = new Move(playGame);
        function = new Function(playGame,startScreen);
        move.playerMove();
        function.turnChongzhi();
        function.turnStartGame(primaryStage);
        function.turnXiayiguan();
        function.turnTishi();
        function.turnShangyiguan();
        primaryStage.setScene(sceneStartGame);
        StartToGame(primaryStage);
        StartToChoose(primaryStage);
        ChoosereturnStart(primaryStage);
        StartToSetting(primaryStage);
        ExitSetting(primaryStage);
        StartToPaihang(primaryStage);
        ExitPaihang(primaryStage);
        paihangScreen.initFile();
        // paihangScreen.setGridPane();
        guanqiaScreen.gridPaneOnAction(playGame,primaryStage,scenePlay);
        primaryStage.setWidth(playGame.map.getWidth());
        primaryStage.setTitle("推箱子游戏");
        // primaryStage.setResizable(false);
        primaryStage.show();
        // move = new Move(playGame);
        playGame.setrecord();
        playGame.getImagePlayer().requestFocus();
    }

    public void StartToGame(Stage stage){
        startScreen.getStartGame().setOnMousePressed(e -> {
            stage.setScene(scenePlay);
            System.out.println("StartToGame");
        });
    }

    public void StartToChoose(Stage stage){
        startScreen.getChooseCheckPoint().setOnMouseClicked(e -> {
            stage.setScene(guanqiaScreen.getScene());
            System.out.println("StartToChoose");
        });
    }

    public void ChoosereturnStart(Stage stage){
        guanqiaScreen.getExit().setOnMouseClicked(e -> {
            stage.setScene(startScreen.getScene());
            System.out.println("ExitGuanqiaScreen");
        });
    }

    public void StartToSetting(Stage stage){
        startScreen.getSetting().setOnMouseClicked(e -> {
            stage.setScene(settingScreen.getSceneSetting());
            System.out.println("StartToSetting");
        });
    }

    public void ExitSetting(Stage stage){
        settingScreen.getExit().setOnMouseClicked(e -> {
            stage.setScene(startScreen.getScene());
        });
    }

    public void StartToPaihang(Stage stage){
        startScreen.getPaiHangPK().setOnMouseClicked(e -> {
            stage.setScene(paihangScreen.getScenePaihang());
            paihangScreen.setGridPane();
            System.out.println("StartToPaihang");
        });
    }

    public void ExitPaihang(Stage stage){
        paihangScreen.getExit().setOnMouseClicked(e -> {
            stage.setScene(startScreen.getScene());
        });
    }



    public static void main(String[] args){
        Application.launch(args);
    }
}

Function类—实现游戏界面的各个功能

package Controller;
/*
* Function 类
* 1、exit功能
* 2、下一关功能
* 3、上一关功能
* 4、提示功能
* 5、重置关卡功能
* */

import Game.*;
import javafx.scene.control.Alert;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class Function {
    PlayGame playGame;
    PlayButton playButton;
    StartScreen startScreen;
    private int cell = new Element().getCell();

    public Function(PlayGame playGame, StartScreen startScreen) {
        this.playGame = playGame;
        playButton = playGame.getPlayButton();
        this.startScreen = startScreen;
    }

    // exit
    public void turnStartGame(Stage primaryStage) {
        playButton.getExit().setOnMouseClicked(e -> {
            primaryStage.setScene(startScreen.getScene());
        });
    }

    // xiayiguan
    public void turnXiayiguan() {
        playButton.getXiayiguan().setOnMouseClicked(e -> {
            if (PlayGame.listNumber >= 24) {
                PlayGame.listNumber = 24;
            } else {
                PlayGame.listNumber++;
            }
            playGame.initmap();
            playGame.initText();
            if(PlayGame.listNumber < 5){
                cell = 30;
            }else{
                cell = 20;
            }
        });
    }

    // chongzhi
    public void turnChongzhi() {
        playButton.getChongzhi().setOnMouseClicked(e -> {
            playGame.initmap();
        });
    }

    // 提示
    public void turnTishi() {
        playButton.getTishi().setOnMouseClicked(e -> {
            CheckPointAlert checkPointAlert = new CheckPointAlert();
            String title = "提示信息";
            String headText = "抱歉!作者也不会这一关的通关方法!";
            ImageView imageView = new ImageView("/image/sikao.gif");
            if (PlayGame.listNumber < 5) {
                imageView = new ImageView("/image/tishihui.gif");
                headText = "先这样,再那样,然后那样,就可以通过了![Doge]";
            }
            imageView.setFitWidth(100);
            imageView.setFitHeight(100);
            checkPointAlert.setALert(Alert.AlertType.NONE, title, headText, null, null, imageView);
            checkPointAlert.setXiayiguanAlert();
        });
    }

		// 上一关
    public void turnShangyiguan() {
        playButton.getShangyiguan().setOnMouseClicked(e -> {
            if (PlayGame.listNumber < 0) {
                PlayGame.listNumber = 0;
            } else {
                PlayGame.listNumber--;
            }
            playGame.initmap();
            playGame.initText();
        });
    }
}

StartScreen类—程序开始界面

package Game;
/*
 * 游戏的开始界面
 * 1. 游戏名字
 * 2. 四个按钮 ->
 * 2.1 开始游戏
 * 2.2 选择关卡
 * 2.3 排行PK
 * 2.4 设置
 * */

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

public class StartScreen {
    VBox vBox = new VBox(20);
    StackPane pane = new StackPane();
    ImageView startGame;
    ImageView chooseCheckPoint;
    ImageView paiHangPK;
    ImageView setting;
    Scene scene;
    private int cell = 50;

    public StartScreen() {

    }

    public void setGameName() {
        ImageView imageView = new ImageView("/image/gamename.png");
        vBox.getChildren().add(imageView);
    }

    public void setStartGame() {
        startGame = new ImageView("/image/start.png");
        startGame.setFitWidth(cell * 6);
        startGame.setFitHeight(cell * 1.5);
        vBox.getChildren().add(startGame);
    }

    public void setChooseCheckPoint() {
        chooseCheckPoint = new ImageView("/image/xuanzeguanqia.png");
        chooseCheckPoint.setFitWidth(cell * 6);
        chooseCheckPoint.setFitHeight(cell * 1.5);
        vBox.getChildren().add(chooseCheckPoint);
    }

    public void setPaiHangPK() {
        paiHangPK = new ImageView("/image/paihangbutton.png");
        paiHangPK.setFitWidth(cell * 6);
        paiHangPK.setFitHeight(cell * 1.5);
        vBox.getChildren().add(paiHangPK);
    }

    public void setSetting() {
        setting = new ImageView("/image/shezhi.png");
        setting.setFitWidth(cell * 6);
        setting.setFitHeight(cell * 1.5);
        vBox.getChildren().add(setting);
    }

    public ImageView getStartGame() {
        System.out.println(startGame);
        return startGame;
    }

    public ImageView getChooseCheckPoint() {
        return chooseCheckPoint;
    }

    public ImageView getPaiHangPK() {
        return paiHangPK;
    }

    public ImageView getSetting() {
        return setting;
    }

    public void setvBox() {
        setGameName();
        setStartGame();
        setChooseCheckPoint();
        ;
        setPaiHangPK();
        setSetting();
        vBox.setPadding(new Insets(10, 10, 10, 10));
        vBox.setAlignment(Pos.CENTER);
    }

    public void setBackGroundImage() {
        ImageView imageView = new ImageView("/image/background.png");
        pane.getChildren().add(imageView);
        imageView.fitWidthProperty().bind(pane.widthProperty());
        imageView.fitHeightProperty().bind(pane.heightProperty());
    }

    public void setScene() {
        setBackGroundImage();
        setvBox();
        pane.getChildren().add(vBox);
        scene = new Scene(pane);
    }

    public Scene getScene() {
        return scene;
    }

    public Pane getPane() {
        return pane;
    }
}

GuanqiaScreen — 实现游戏界面

package Game;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class GuanqiaScreen{
    private int cell = 50;
    private int width = 70;
    private int space = 20;

    Scene scene;
    HBox hBoxTop = new HBox();
    HBox hBoxBottom = new HBox(20);
    BorderPane borderPane = new BorderPane();
    GridPane gridPane = new GridPane();
    ImageView exit;
    Button left;
    Button right;

    public GuanqiaScreen() {
        setScene();
    }

    public void setExit() {
        exit = new ImageView("/image/exit.png");
        exit.setFitWidth(cell);
        exit.setFitHeight(cell);
        hBoxTop.getChildren().add(exit);
    }

    public ImageView getExit() {
        return exit;
    }

    public void setLeft() {
        ImageView imageView = new ImageView("/image/left.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        left = new Button("", imageView);
        hBoxBottom.getChildren().add(left);
    }

    public Button getLeft() {
        return left;
    }

    public void setRight() {
        ImageView imageView = new ImageView("/image/right.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        right = new Button("", imageView);
        hBoxBottom.getChildren().add(right);
    }

    public Button getRight() {
        return left;
    }

    public void setGridPane() {
        gridPane.setPadding(new Insets(space,0,0,space));
        gridPane.setHgap(space);
        gridPane.setVgap(space);
        for (int i = 0; i < 6; i++) {
            for (int j = 1; j < 5; j++) {
                String url = "/image/" + (i * 4 + j) + ".png";
                ImageView imageView = new ImageView(url);
                imageView.setFitHeight(width);
                imageView.setFitWidth(width);
                gridPane.add(imageView, j, i);
                System.out.println(imageView.getX()+" "+ imageView.getY());
            }
        }
    }
    public GridPane getGridPane(){
        return gridPane;
    }

    public void gridPaneOnAction(PlayGame playGame,Stage stage,Scene scenePlay){
        gridPane.setOnMouseClicked(e -> {
            int j = (int)((e.getX() - space ) / (width + space));
            int i = (int)(e.getY() / (width + space));
            PlayGame.listNumber = i * 4 + j;
            System.out.println(i+" "+j+" "+PlayGame.listNumber);
            playGame.initmap();
            playGame.initText();
            stage.setScene(scenePlay);
        });
    }

    public void sethBoxTop() {
        setExit();
        hBoxTop.getChildren().add(new ImageView("/image/xuanzeguanqiaming.gif"));
        hBoxTop.setSpacing(cell * 0.6);
    }

    public void sethBoxBottom() {
        setLeft();
        setRight();
        hBoxBottom.setPadding(new Insets(25,25,25,25));
        hBoxBottom.setSpacing(cell * 4.3);
        // hBoxBottom.setAlignment(Pos.CENTER);
    }

    public void setBorderPane() {
        setGridPane();
        sethBoxBottom();
        sethBoxTop();
        ImageView imageView = new ImageView("/image/background.png");
        imageView.fitHeightProperty().bind(borderPane.heightProperty());
        imageView.fitWidthProperty().bind(gridPane.widthProperty());
        borderPane.getChildren().add(imageView);
        borderPane.setTop(hBoxTop);
        borderPane.setCenter(gridPane);
        borderPane.setBottom(hBoxBottom);
    }

    public void setScene() {
        setBorderPane();
        scene = new Scene(borderPane);
    }

    public Scene getScene() {
        return scene;
    }

    public void setGuanqia(){
    }
}

PaihangScreen—排行榜界面—功能有bug

package Game;

import Controller.Move;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class PaihangScreen {
    private int cell = 50;
    HBox hBoxTop = new HBox();
    Scene scenePaihang;
    BorderPane borderPane = new BorderPane();
    GridPane gridPane = new GridPane();
    ImageView exit;
    File file = new File("E:\IDEAproject\推箱子游戏---java基础大作业\src\FileText\paihang.txt");
    public static ArrayList<Integer> listNumberCopy = new ArrayList<>();

    public void setExit() {
        exit = new ImageView("/image/exit.png");
        exit.setFitWidth(cell);
        exit.setFitHeight(cell);
        hBoxTop.getChildren().add(exit);
    }
    public ImageView getExit() {
        return exit;
    }

    public void sethBoxTop() {
        setExit();
        hBoxTop.getChildren().add(new ImageView("/image/paihangname.png"));
        hBoxTop.setSpacing(cell * 0.6);
        borderPane.setTop(hBoxTop);
    }

    public void setScenePaihang(){
        ImageView imageView = new ImageView("/image/background.png");
        imageView.fitHeightProperty().bind(borderPane.heightProperty());
        imageView.fitWidthProperty().bind(borderPane.widthProperty());
        borderPane.getChildren().add(imageView);
        sethBoxTop();
        scenePaihang = new Scene(borderPane);
    }
    public Scene getScenePaihang(){
        return scenePaihang;
    }
    public PaihangScreen(){
        setScenePaihang();
    }

    public void initFile(){
        try(
                PrintWriter printWriter = new PrintWriter(file);
                ) {
            printWriter.println("");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void inputNumber(){
        try(
                Scanner scanner = new Scanner(file);
                ) {
            while(scanner.hasNextInt()){
                listNumberCopy.add(scanner.nextInt());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void outputNumber(){
        try(
                PrintWriter printWriter = new PrintWriter(file);
                ) {
            for(int i=0;i<listNumberCopy.size();i++){
                printWriter.println(listNumberCopy.get(i));
            }
            if(Move.listNumber.size() > 0){
                printWriter.println(Move.listNumber.get(Move.listNumber.size() - 2) + 1);
                printWriter.println(Move.listNumber.get(Move.listNumber.size() - 1));
                for(int i=0;i<listNumberCopy.size();i++){
                    System.out.println(listNumberCopy.get(i));
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void setGridPane(){
        inputNumber();
        outputNumber();
        Text textguanqia = new Text("关卡");
        textguanqia.setFont(Font.font("Times", 20));
        gridPane.add(textguanqia,0,0);
        Text textStepNumber = new Text("步数");
        textStepNumber.setFont(Font.font("Times", 20));
        gridPane.add(textStepNumber,1,0);
        int num = 1;
        for(int i=0;i<listNumberCopy.size();i+=2){
            gridPane.add(new Text(String.valueOf(listNumberCopy.get(i))),0,num);
            gridPane.add(new Text(String.valueOf(listNumberCopy.get(i + 1))),1,num);
            num++;
        }
        gridPane.setAlignment(Pos.CENTER);
        gridPane.setVgap(20);
        gridPane.setHgap(20);
        borderPane.setCenter(gridPane);
    }
}

PlayButton类— 定义游戏界面的各个功能键

package Game;

import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

public class PlayButton {
    HBox hBoxTop = new HBox(30);
    HBox hBoxBottom = new HBox(20);
    HBox hBoxBottom1 = new HBox(20);
    VBox vBox = new VBox(10);
    ImageView exit;
    ImageView xiayiguan;
    ImageView shangyiguan;
    ImageView tishi;
    ImageView tuiyibu;
    ImageView chongzhi;
    Button up;
    Button down;
    Button left;
    Button right;
    Text text;
    Text guanqia;
    private int cell = Element.imageCell;

    public PlayButton() {
        setExit();
        sethBoxBottom();
    }

    public void setExit() {
        exit = new ImageView("/image/exit.png");
        exit.setFitWidth(cell);
        exit.setFitHeight(cell);
        // hBoxTop.getChildren().add(exit);
    }

    public ImageView getExit() {
        return exit;
    }

    public void setShangyiguan() {
        shangyiguan = new ImageView("/image/shangyiguan.png");
        shangyiguan.setFitWidth(cell);
        shangyiguan.setFitHeight(cell);
        hBoxBottom1.getChildren().add(shangyiguan);
    }

    public ImageView getShangyiguan() {
        return shangyiguan;
    }

    public void setXiayiguan() {
        xiayiguan = new ImageView("/image/xiayiguan.png");
        xiayiguan.setFitHeight(cell);
        xiayiguan.setFitWidth(cell);
        hBoxBottom1.getChildren().add(xiayiguan);
    }

    public ImageView getXiayiguan() {
        return xiayiguan;
    }

    public void setTishi() {
        tishi = new ImageView("/image/tishi.png");
        tishi.setFitWidth(cell);
        tishi.setFitHeight(cell);
        hBoxBottom1.getChildren().add(tishi);
    }

    public ImageView getTishi() {
        return tishi;
    }

    public void setTuiyibu() {
        tuiyibu = new ImageView("/image/return.png");
        tuiyibu.setFitHeight(cell);
        tuiyibu.setFitWidth(cell);
        hBoxBottom1.getChildren().add(tuiyibu);
    }

    public ImageView getTuiyibu() {
        return tuiyibu;
    }

    public void setChongzhi() {
        chongzhi = new ImageView("/image/chongzhi.png");
        chongzhi.setFitWidth(cell);
        chongzhi.setFitHeight(cell);
        hBoxBottom1.getChildren().add(chongzhi);
    }

    public ImageView getChongzhi() {
        return chongzhi;
    }

    public void sethBoxBottom() {
        setUp();
        setDown();
        setLeft();
        setRight();
        setShangyiguan();
        setXiayiguan();
        setTishi();
        setTuiyibu();
        setChongzhi();
        hBoxBottom.setAlignment(Pos.CENTER);
        hBoxBottom1.setAlignment(Pos.CENTER);
        vBox.getChildren().addAll(hBoxBottom, hBoxBottom1);
    }

    public void setUp() {
        ImageView imageView = new ImageView("/image/up.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        up = new Button("", imageView);
        hBoxBottom.getChildren().add(up);
    }

    public Button getUp() {
        return up;
    }

    public void setDown() {
        ImageView imageView = new ImageView("/image/down.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        down = new Button("", imageView);
        hBoxBottom.getChildren().add(down);
    }

    public Button getDown() {
        return down;
    }

    public void setLeft() {
        ImageView imageView = new ImageView("/image/left.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        left = new Button("", imageView);
        hBoxBottom.getChildren().add(left);
    }

    public Button getLeft() {
        return left;
    }

    public void setRight() {
        ImageView imageView = new ImageView("/image/right.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        right = new Button("", imageView);
        hBoxBottom.getChildren().add(right);
    }

    public Button getRight() {
        return right;
    }

    public VBox getvBox() {
        return vBox;
    }
}



SettingScreen—设置界面—功能暂未实现

package Game;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;

public class SettingScreen {
    private int cell = 50;
    HBox hBoxTop = new HBox();
    VBox vBox = new VBox(30);
    ImageView exit;
    StackPane stackPane = new StackPane();
    BorderPane borderPane = new BorderPane();
    Scene sceneSetting;
    RadioButton init = new RadioButton("初始化");
    RadioButton music ;

    public void setExit() {
        exit = new ImageView("/image/exit.png");
        exit.setFitWidth(cell);
        exit.setFitHeight(cell);
        hBoxTop.getChildren().add(exit);
    }
    public ImageView getExit() {
        return exit;
    }

    public void sethBoxTop() {
        setExit();
        hBoxTop.getChildren().add(new ImageView("/image/settingname.png"));
        hBoxTop.setSpacing(cell * 0.6);
        borderPane.setTop(hBoxTop);
    }

    public void setMusic(){
        ImageView imageView = new ImageView("/image/music.png");
        imageView.setFitHeight(cell);
        imageView.setFitWidth(cell);
        music = new RadioButton("音乐");
        music.setFont(Font.font("Times", 30));
        vBox.getChildren().add(music);
    }
    public RadioButton getMusic(){
        return music;
    }

    public RadioButton getInit(){
        return init;
    }

    public void setStackPane(){
        init.setFont(Font.font("Times", 30));
        setMusic();
        vBox.getChildren().add(init);
        vBox.setAlignment(Pos.CENTER);
        vBox.setPadding(new Insets(30,30,30,30));
        stackPane.getChildren().add(vBox);
        borderPane.setCenter(stackPane);
    }

    public void setBorderPane(){
        ImageView imageView = new ImageView("/image/background.png");
        imageView.fitHeightProperty().bind(borderPane.heightProperty());
        imageView.fitWidthProperty().bind(borderPane.widthProperty());
        borderPane.getChildren().add(imageView);
        sethBoxTop();
        setStackPane();
    }

    public void setSceneSetting(){
        setBorderPane();
        sceneSetting = new Scene(borderPane);
    }
    public Scene getSceneSetting(){
        return sceneSetting;
    }

    public SettingScreen(){
        setSceneSetting();
    }
}

游戏存储文件

str.txt

1
____#####__________
____#---#__________
____#$--#__________
__###--$##_________
__#--$-$-#_________
###-#-##-#___######
#---#-##-#####--..#
#-$--$----------..#
#####-###-#@##--..#
____#-----#########
____#######________
2
############__
#..--#-----###
#..--#-$--$--#
#..--#$####--#
#..----@-##--#
#..--#-#--$-##
######-##$-$-#
__#-$--$-$-$-#
__#----#-----#
__############
3
________########_
________#-----@#_
________#-$#$-##_
________#-$--$#__
________##$-$-#__
#########-$-#-###
#....--##-$--$--#
##...----$--$---#
#....--##########
########_________
4
___________########
___________#--....#
############--....#
#----#--$-$---....#
#-$$$#$--$-#--....#
#--$-----$-#--....#
#-$$-#$-$-$########
#--$-#-----#_______
##-#########_______
#----#----#________
#-----$---##_______
#--$$#$$--@#_______
#----#----##_______
###########________
5
________#####____
________#---#####
________#-#$##--#
________#-----$-#
#########-###---#
#....--##-$--$###
#....----$-$$-##_
#....--##$--$-@#_
#########--$--##_
________#-$-$--#_
________###-##-#_
__________#----#_
__________######_
6
######__###_
#..--#_##@##
#..--###---#
#..-----$$-#
#..--#-#-$-#
#..###-#-$-#
####-$-#$--#
___#--$#-$-#
___#-$--$--#
___#--##---#
___#########
7
_______#####_
_#######---##
##-#-@##-$$-#
#----$------#
#--$--###---#
###-#####$###
#-$--###-..#_
#-$-$-$-...#_
#----###...#_
#-$$-#_#...#_
#--###_#####_
####_________
8
__####__________
__#--###########
__#----$---$-$-#
__#-$#-$-#--$--#
__#--$-$--#----#
###-$#-#--####-#
#@#$-$-$--##---#
#----$-#$#---#-#
#---$----$-$-$-#
#####--#########
__#------#______
__#------#______
__#......#______
__#......#______
__#......#______
__########______
9
__________#######
__________#--...#
______#####--...#
______#------.-.#
______#--##--...#
______##-##--...#
_____###-########
_____#-$$$-##____
_#####--$-$-#####
##---#$-$---#---#
#@-$--$----$--$-#
######-$$-$-#####
_____#------#____
_____########____
10
_###__#############
##@####-------#---#
#-$$---$$--$-$-...#
#--$$$#----$--#...#
#-$---#-$$-$$-#...#
###---#--$----#...#
#-----#-$-$-$-#...#
#----######-###...#
##-#--#--$-$--#...#
#--##-#-$$-$-$##..#
#-..#-#--$------#.#
#-..#-#-$$$-$$$-#.#
#####-#-------#-#.#
____#-#########-#.#
____#-----------#.#
____###############
11
__________####_____
_____####_#--#_____
___###--###$-#_____
__##---@--$--#_____
_##--$-$$##-##_____
_#--#$##-----#_____
_#-#-$-$$-#-###____
_#---$-#--#-$-#####
_###----#--$$-#---#
####-##-$---------#
#.----###--########
#..-..#_####_______
#...#.#____________
#.....#____________
#######____________
12
################_
#--------------#_
#-#-######-----#_
#-#--$-$-$-$#--#_
#-#---[email protected]$---##-##
#-#-#$-$-$###...#
#-#---$-$--##...#
#-###$$$-$-##...#
#-----#-##-##...#
#####---##-##...#
____#####-----###
________#-----#__
________#######__
13
___#########_______
__##---##--######__
###-----#--#----###
#--$-#$-#--#--...-#
#-#-$#@$##-#-#.#.-#
#--#-#$--#----.-.-#
#-$----$-#-#-#.#.-#
#---##--##$-$-.-.-#
#-$-#---#--#$#.#.-#
##-$--$---$--$...-#
_#$-######----##--#
_#--#____##########
_####______________
14
_______#######____
_#######-----#____
_#-----#-[email protected]$-#____
_#$$-#---#########
_#-###......##---#
_#---$......##-#-#
_#-###......-----#
##---####-###-#$##
#--#$---#--$--#-#_
#--$-$$$--#-$##-#_
#---$-$-###$$-#-#_
#####-----$---#-#_
____###-###---#-#_
______#-----#---#_
______########--#_
_____________####_
15
#########______
#-------#______
#-------####___
##-####-#--#___
##-#@##----#___
#-$$$-$--$$#___
#--#-##-$--#___
#--#-##--$-####
####--$$$-$#--#
_#---##---....#
_#-#---#-#..-.#
_#---#-#-##...#
_#####-$--#...#
_____##---#####
______#####____
16
######_____####____
#----#######--#####
#---$#--#--$--#---#
#--$--$--$-#-$-$--#
##$-$---#-@#-$----#
#--$-###########-##
#-#---#.......#-$#_
#-##--#-......#--#_
#-#---$........$-#_
#-#-$-#....-..#--#_
#--$-$####$####-$#_
#-$---###-$---$--##
#-$-----$-$--$----#
##-######-$-#####-#
#---------#-------#
###################
17
___##########___
___#..--#---#___
___#..------#___
___#..--#--####_
__#######--#--##
__#------------#
__#--#--##--#--#
####-##--####-##
#--$--#####-#--#
#-#-$--$--#-$--#
#-@$--$---#---##
####-##-#######_
___#----#_______
___######_______
18
_____###########___
_____#--.--#---#___
_____#-#.----@-#___
_#####-##..#-####__
##--#-..###-----###
#-$-#...---$-#--$-#
#----..-##--##-##-#
####$##$#-$-#---#-#
__##-#----#$-$$-#-#
__#--$-#-#--#-$##-#
__#---------------#
__#--###########--#
__####_________####
19
__######___________
__#---@####________
#####-$---#________
#---##----####_____
#-$-#--##----#_____
#-$-#--#####-#_____
##-$--$----#-#_____
_#-$-$-###-#-#_____
_#-#--$--#-#-#_____
_#-#-#$#---#-#_____
##-###---#-#-######
#--$--####-#-#....#
#----$----$---..#.#
####$--$#-$---....#
#-------#--##-....#
###################
20
____#######________
____#--#--####_____
#####-$#$-#--##____
#..-#--#--#---#____
#..-#-$#$-#--$####_
#.--#-----#$--#--#_
#..---$#--#-$----#_
#..@#--#$-#$--#--#_
#..-#-$#-----$#--#_
#..-#--#$$#$--#--##
#..-#-$#--#--$#$--#
#..-#--#--#---#---#
##.-####--#####---#
_####__####___#####
21

list.txt

chuangguanjilu.txt

paihang.txt


游戏效果图

请添加图片描述

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>