⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mazeelement.java

📁 简单的迷宫生成算法、复杂的迷宫生成算法、简单的迷宫搜索算法、复杂的迷宫搜索算法
💻 JAVA
字号:
/** ver: 0.1, date 19-12-2007 by Jeroen Willemsen
 * added and implemented booleans gets and sets.
 * added and implemented integers for keeping track of the states for Solve and Build algorithms;
 * added and implemented 2 constructors: 1 default, 1 with walls, 1 with the complete set
 * added and implemented gets and sets for the states of build and solve
 * 27-12-2007 - Jeroen S - Clear should reset the states as well (ease of use for MazeGraph) 
 * ver: 0.2, date 27-12-2007 by Marcel Hekman
 * added isVisited and markAsInvalid
 * added SOLVE_UNVISITED, SOLVE_VISITED, SOLVE_INVALID, SOLVE_START and SOLVE_END
 * ver: 0.3, date 02-01-2007 by Marcel Hekman
 * - clearSolveState().
 * ver: 0.4, date 02-01-2007 by Jeroen Willemsen and Jeroen ter Strake
 * - added buildlocation paramters and methods
 * 
 */

package mazeAssignment;

/**
 *
 * @author: jeroen, jeroen, marcel en teun
 */
public class MazeElement {
        public static final int SOLVE_UNVISITED = 0;
        public static final int SOLVE_VISITED = 1;
        public static final int SOLVE_INVALID = 2;
        public static final int SOLVE_START = 3;
        public static final int SOLVE_END = 4;
        
    private boolean westWall, eastWall, southWall, northWall;
    private int solveState, buildState, buildLocation;
    
    //default constructor: (true means that the wall is true!!!!)
    public MazeElement()
    {
        this(true, true, true, true, 0, 0, 0);
    }
    
    //constructor for making special blocks on the grid
    public MazeElement(boolean nWall, boolean eWall, boolean sWall, boolean wWall){
        westWall = wWall;
        eastWall= eWall;
        southWall= sWall;
        northWall= nWall;
        solveState = SOLVE_UNVISITED;
        buildState = 0;
        buildLocation=0;
    }
    
    //constructor for making prefab blocks on the grid and to test the GUI, Solve and Build 
    public MazeElement(boolean nWall, boolean eWall, boolean sWall, boolean wWall, int sState, int bState, int bLocation){
        westWall = wWall;
        eastWall= eWall;
        southWall= sWall;
        northWall= nWall;
        solveState = sState;
        buildState = bState;
        buildLocation = bLocation;
    }  
    
    //the Solve algorithm can use methods like these to visit a block on the grid and alter its
    //state. you are free to alter these numbers and methods!!!
    public void clearSolveState()
    {
        if(solveState != SOLVE_START && solveState != SOLVE_END)
        {
                solveState = SOLVE_UNVISITED;
        }
    }
    //Marks as visited
    public void visit()
    {
        if(solveState != SOLVE_START && solveState != SOLVE_END)
        {
                solveState = SOLVE_VISITED;
        }
    }
    //Marks the path as invalid
    public void markAsInvalid()
    {
        if(solveState != SOLVE_START && solveState != SOLVE_END)
        {
                solveState = SOLVE_INVALID;
        }
    }
    //Returns true if the field has been visited
    public boolean isVisited()
    {
        return (solveState != SOLVE_UNVISITED && solveState != SOLVE_END);
    }
    // to get the solvestate
    public int getSolveState()
    {
        return solveState;
    }
    
    
    
    //to get the buildstate
    public int getBuildState()
    {
        return buildState;
    }
    //to see wheither there is a wall on the westside
    public boolean getWest(){
        return westWall;
    }
    //to see wheither there is a wall on the eastside
    public boolean getEast(){
        return eastWall;
    }
     //to see wheither there is a wall on the northside
    public boolean getNorth(){
        return northWall;
    }   
    //to see wheither there is a wall on the south
    public boolean getSouth(){
        return southWall;
    }
    //sets northWall and alters buildState
    public void setNorth(boolean state){
        buildState++;
        northWall = state;
    }
    //sets southWall and alters buildState
    public void setSouth(boolean state){
        buildState++;
        southWall = state;
    }
    //sets northWall and alters buildState
    public void setEast(boolean state){
        buildState++;
        eastWall = state;
    }
    //sets southWall and alters buildState
    public void setWest(boolean state){
        buildState++;
        westWall = state;
    }
    
    //clears element 
    public void clear(){
        eastWall=true;
        westWall=true;
        southWall=true;
        northWall=true;
        buildState = 0;
        solveState = SOLVE_UNVISITED;
        buildLocation=0;
    }
    //is an extra variable to show the location of the element to buildalgorithms
    public void setBuildLocation(int bLocation)
    {
        buildLocation=bLocation;
    }
    //gets the extra variable
    public int getBuildLocation()
    {
        return buildLocation;
    }
    
    // Used for setting start + end point
    public void setSolveState(int sState)
    {
        solveState = sState;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -