资源简介

java课程设计大作业写的 推箱子小游戏(含说明文档) java课程设计大作业写的 推箱子小游戏(含说明文档)

资源截图

代码片段和文件信息

package controller;

import entity.immobile.Immobile;
import entity.mobile.Box;
import entity.mobile.Mobile;
import exception.CannotUndoException;

/**
 * Created by caojiajun on 2018/3/24.
 */
public class History {
    private Node current;
    private static History history;

    private History() {
        this.current = new Node(null null);
    }

    public static History getHistory() {
        if (history == null) {
            history = new History();
        }
        return history;
    }

    public static void restart() {
        history = null;
    }

    public void addRecord(Immobile from Immobile to Mobile mobileInstance) {
        HistoryRecord newRecord = new HistoryRecord(from to mobileInstance);
        Node newNode = new Node(current newRecord);
        current = newNode;
    }

    private void undoHelper() {
        HistoryRecord record = current.record;
        int rowFrom = record.from.getPositionRow();
        int colFrom = record.from.getPositionCol();
        int rowTo = record.to.getPositionRow();
        int colTo = record.to.getPositionCol();
        record.mobileInstance.move(rowTo colTo rowFrom colFrom);
        current = current.pre;
    }

    public void undo() throws CannotUndoException {
        if (current == null || current.record == null) {
            throw new CannotUndoException(“已经到了初始状态,不能进行回退!“);
        }

        if (current.pre != null && current.pre.record != null && current.pre.record.mobileInstance instanceof Box) {
            undoHelper();
            undoHelper();
        } else {
            undoHelper();
        }
    }

    private class HistoryRecord {
        final Immobile from;
        final Immobile to;
        final Mobile mobileInstance;

        protected HistoryRecord(Immobile from Immobile to Mobile mobileInstance) {
            this.from = from;
            this.to = to;
            this.mobileInstance = mobileInstance;
        }
    }

    private class Node {
        Node pre;
        final HistoryRecord record;

        protected Node(Node pre HistoryRecord record) {
            this.pre = pre;
            this.record = record;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-31 05:54  Sokoban-master\
     文件         130  2018-03-31 05:54  Sokoban-master\README.md
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\.idea\
     文件         273  2018-03-31 05:54  Sokoban-master\Sokoban\.idea\misc.xml
     文件         254  2018-03-31 05:54  Sokoban-master\Sokoban\.idea\modules.xml
     文件        8792  2018-03-31 05:54  Sokoban-master\Sokoban\.idea\uiDesigner.xml
     文件       33859  2018-03-31 05:54  Sokoban-master\Sokoban\.idea\workspace.xml
     文件         423  2018-03-31 05:54  Sokoban-master\Sokoban\Sokoban.iml
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\maps\
     文件          76  2018-03-31 05:54  Sokoban-master\Sokoban\maps\1.map
     文件          59  2018-03-31 05:54  Sokoban-master\Sokoban\maps\2.map
     文件         113  2018-03-31 05:54  Sokoban-master\Sokoban\maps\3.map
     文件          67  2018-03-31 05:54  Sokoban-master\Sokoban\maps\4.map
     文件          92  2018-03-31 05:54  Sokoban-master\Sokoban\maps\5.map
     文件          93  2018-03-31 05:54  Sokoban-master\Sokoban\maps\6.map
     文件         125  2018-03-31 05:54  Sokoban-master\Sokoban\maps\7.map
     文件         126  2018-03-31 05:54  Sokoban-master\Sokoban\maps\8.map
     文件          70  2018-03-31 05:54  Sokoban-master\Sokoban\maps\9.map
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\src\
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\src\controller\
     文件        2199  2018-03-31 05:54  Sokoban-master\Sokoban\src\controller\History.java
     文件        4389  2018-03-31 05:54  Sokoban-master\Sokoban\src\controller\Main.java
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\
     文件        4254  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\Map.java
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\immobile\
     文件        1272  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\immobile\Immobile.java
     目录           0  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\mobile\
     文件        1264  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\mobile\Box.java
     文件        2394  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\mobile\Mobile.java
     文件        1108  2018-03-31 05:54  Sokoban-master\Sokoban\src\entity\mobile\Player.java
............此处省略3个文件信息

评论

共有 条评论