Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
liweinan committed Mar 24, 2013
1 parent 46982f3 commit 7235b04
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 30 deletions.
7 changes: 7 additions & 0 deletions .idea/ant.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__junit_junit_4_10.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions README.md
@@ -1,4 +1,27 @@
mazejava
========
# Maze Java

A maze game written in java for fun.

## Usage

Create a 5x5 maze:

Maze maze = MazeFactory.createMaze(5, 5);

Print it:

maze.print();

+---+---+---+---+---+
> | | |
+---+ + + + +
| | | | |
+ + + +---+ +
| | | | |
+ + +---+---+ +
| | | |
+ +---+ + + +
| | V |
+---+---+---+---+ +


MazeJava
38 changes: 16 additions & 22 deletions pom.xml
@@ -1,25 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io</groupId>
<artifactId>maze</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<groupId>mazejava</groupId>
<artifactId>mazejava</artifactId>
<version>1.0-SNAPSHOT</version>

<name>maze</name>
<url>http://maven.apache.org</url>
<dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
</project>
18 changes: 14 additions & 4 deletions src/main/java/io/maze/Maze.java
Expand Up @@ -18,7 +18,7 @@ public class Maze {
private CellState in, out;
private CellState[][] cells;
private int m, n;
private LinkedList<CellState> histories = new LinkedList<CellState>();
private Stack<CellState> histories = new Stack<CellState>();
private int visited_cnt = 0;

public Maze(int m, int n) {
Expand Down Expand Up @@ -48,7 +48,7 @@ public void generate() {
histories.push(currentCell);
visited_cnt++;

System.out.println("LEGEND: C- CANDIDATE, D- DECISION, R- RESULT, F- FALLBACK");
System.out.println("LEGEND: C- CANDIDATE, D- DECISION, R- RESULT, G- GO BACK");
while (histories.size() > 0 && visited_cnt < m*n) {

while (currentCell != null) {
Expand All @@ -59,7 +59,7 @@ public void generate() {
}
}
currentCell = histories.pop();
System.out.println("F- x:" + currentCell.getX() + " y:" + currentCell.getY());
System.out.println("(G- x:" + currentCell.getX() + " y:" + currentCell.getY() + ")");
}
}

Expand Down Expand Up @@ -183,17 +183,27 @@ public void print() {

for (int y = 0; y < n; y++) {
Queue<String> parts = new LinkedList<String>();

for (int x = 0; x < m; x++) {

CellState cell = cells[x][y];
String part = new String(token);

if (x==0 && y==0) { // in
part = part.replaceAll(" \\|", " > |");
}

if (x==m-1 && y==n-1) { //out
part = part.replaceAll(" \\|", " V |");
}


if (cell.getSouthDoor().isOpened()) {
part = part.replaceAll("\\-", " ");
}
if (cell.getEastDoor().isOpened()) {
part = part.replaceAll("\\|", " ");
}

parts.offer(part);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/maze/PlayMaze.java
Expand Up @@ -13,7 +13,7 @@
public class PlayMaze {

public static final void main(String[] args) {
Maze maze = MazeFactory.createMaze(60, 60);
Maze maze = MazeFactory.createMaze(5, 5);
maze.print();
}
}

0 comments on commit 7235b04

Please sign in to comment.