-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
179 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package javelin.controller.generator.dungeon; | ||
|
||
import java.util.HashMap; | ||
|
||
import javelin.controller.Point; | ||
import javelin.controller.generator.dungeon.template.Template; | ||
|
||
public class VirtualMap { | ||
public Character fill = '_'; | ||
HashMap<Point, Character> map = new HashMap<Point, Character>(); | ||
|
||
public boolean draw(Template t, int rootx, int rooty, boolean check) { | ||
for (int x = 0; x < t.width; x++) { | ||
for (int y = 0; y < t.height; y++) { | ||
Point p = new Point(x + rootx, y + rooty); | ||
if (!check) { | ||
map.put(p, t.tiles[x][y]); | ||
continue; | ||
} | ||
Character c = map.get(p); | ||
if (c != null) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public String rasterize() { | ||
int min = Integer.MAX_VALUE; | ||
int max = Integer.MIN_VALUE; | ||
for (Point p : map.keySet()) { | ||
min = Math.min(min, Math.min(p.x, p.y)); | ||
max = Math.max(max, Math.max(p.x, p.y)); | ||
} | ||
StringBuilder raster = new StringBuilder(); | ||
for (int y = max; y >= min; y--) { | ||
for (int x = min; x <= max; x++) { | ||
Character c = map.get(new Point(x, y)); | ||
raster.append(c == null ? fill : c); | ||
} | ||
raster.append('\n'); | ||
} | ||
return raster.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return rasterize(); | ||
} | ||
|
||
public boolean draw(Template t, int x, int y) { | ||
if (!draw(t, x, y, true)) { | ||
return false; | ||
} | ||
draw(t, x, y, false); | ||
return true; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
javelin/controller/generator/dungeon/tables/ConnectionTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package javelin.controller.generator.dungeon.tables; | ||
|
||
public class ConnectionTable extends DungeonTable { | ||
public static final Row CORRIDOR = new Row(2, 2, 2, true); | ||
public static final Row ROOM = new Row(2, 2, 2, true); | ||
|
||
public ConnectionTable() { | ||
add(CORRIDOR); | ||
add(ROOM); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
javelin/controller/generator/dungeon/tables/DungeonTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package javelin.controller.generator.dungeon.tables; | ||
|
||
import java.util.ArrayList; | ||
|
||
import tyrant.mikera.engine.RPG; | ||
|
||
public class DungeonTable implements Cloneable { | ||
ArrayList<Row> table = new ArrayList<Row>(); | ||
ArrayList<Row> rows = new ArrayList<Row>(); | ||
|
||
void add(Row r) { | ||
int n = r.getamount(); | ||
for (int i = 0; i < n; i++) { | ||
table.add(r); | ||
} | ||
} | ||
|
||
public Row roll() { | ||
return RPG.pick(table); | ||
} | ||
|
||
@Override | ||
protected DungeonTable clone() { | ||
try { | ||
DungeonTable clone = (DungeonTable) super.clone(); | ||
for (int i = 0; i < rows.size(); i++) { | ||
clone.rows.set(i, clone.rows.get(i).clone()); | ||
} | ||
return clone; | ||
} catch (CloneNotSupportedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package javelin.controller.generator.dungeon.tables; | ||
|
||
import tyrant.mikera.engine.RPG; | ||
|
||
public class Row implements Cloneable { | ||
int min; | ||
int max; | ||
int change; | ||
boolean optional; | ||
|
||
public Row(int min, int max, int change, boolean optional) { | ||
super(); | ||
this.min = min; | ||
this.max = max; | ||
this.change = change; | ||
this.optional = optional; | ||
change(); | ||
} | ||
|
||
void change() { | ||
int amount = RPG.r(-change, +change); | ||
min += amount; | ||
max += amount; | ||
if (!optional) { | ||
min = Math.max(1, min); | ||
max = Math.max(1, max); | ||
} | ||
} | ||
|
||
public int getamount() { | ||
return RPG.r(min, max); | ||
} | ||
|
||
@Override | ||
protected Row clone() { | ||
try { | ||
return (Row) super.clone(); | ||
} catch (CloneNotSupportedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters