-
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
7 changed files
with
140 additions
and
10 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
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
65 changes: 65 additions & 0 deletions
65
javelin/controller/generator/dungeon/tables/NumericTable.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,65 @@ | ||
package javelin.controller.generator.dungeon.tables; | ||
|
||
import tyrant.mikera.engine.RPG; | ||
|
||
/** | ||
* Subverts {@link DungeonTable} to instead provice a number and not a | ||
* {@link Row} object, making it easier to implement things like "room size | ||
* table". A value can be returned via {@link #rollvalue()}. | ||
* | ||
* Subclasses will need to implement a zero-argument constructor. | ||
* | ||
* @author alex | ||
*/ | ||
public class NumericTable extends DungeonTable { | ||
int min; | ||
int max; | ||
int delta; | ||
boolean optional; | ||
/** | ||
* Exposed amount of modification. | ||
*/ | ||
public int change; | ||
|
||
class NumericValue extends Row { | ||
final int value; | ||
|
||
public NumericValue(int value) { | ||
super(1, 1, 0, false); | ||
this.value = value; | ||
} | ||
} | ||
|
||
public NumericTable(int min, int max, int delta, boolean optional) { | ||
super(); | ||
this.min = min; | ||
this.max = max; | ||
this.delta = delta; | ||
this.optional = optional; | ||
} | ||
|
||
@Override | ||
public NumericValue roll() { | ||
return (NumericValue) super.roll(); | ||
} | ||
|
||
public int rollvalue() { | ||
return roll().value; | ||
} | ||
|
||
@Override | ||
protected void modify() { | ||
change = RPG.r(-delta, +delta); | ||
modify(change); | ||
} | ||
|
||
void modify(int change) { | ||
int floor = optional ? 0 : 1; | ||
min = Math.max(min + change, floor); | ||
max = Math.max(max + change, floor); | ||
table.clear(); | ||
for (int i = min; i <= max; i++) { | ||
add(new NumericValue(i)); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
javelin/controller/generator/dungeon/tables/RoomSizeTable.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,43 @@ | ||
package javelin.controller.generator.dungeon.tables; | ||
|
||
import javelin.controller.Point; | ||
|
||
public class RoomSizeTable extends NumericTable { | ||
public class RoomSize extends NumericTable { | ||
public RoomSize(int min, int max, int delta, boolean optional) { | ||
super(min, max, delta, optional); | ||
} | ||
|
||
@Override | ||
protected void modify() { | ||
super.modify(); | ||
while (min <= 2 && min <= 2) { | ||
super.modify(); | ||
} | ||
} | ||
} | ||
|
||
NumericTable width = new RoomSize(3, 7, 3, false); | ||
NumericTable height = new RoomSize(1, 6, 2, false); | ||
|
||
public RoomSizeTable() { | ||
super(0, 0, 0, false); | ||
width.modify(); | ||
height.modify(width.change); | ||
} | ||
|
||
@Override | ||
protected void modify() { | ||
width.modify(); | ||
height.modify(width.change); | ||
} | ||
|
||
@Override | ||
public NumericValue roll() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public Point rolldimensions() { | ||
return new Point(width.rollvalue(), height.rollvalue()); | ||
} | ||
} |
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