Skip to content

Commit dd04a40

Browse files
committed
Water and mountains.
1 parent f5594eb commit dd04a40

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

web/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<button id="Stop">STOP</button>
4949
&nbsp;
5050
<button id="Reset">RESET</button>
51+
<button id="Mountains">Mountains</button>
52+
<button id="Lochs">Lochs</button>
53+
5154
</div>
5255
</div>
5356
</body>

web/lib/featurebuilder.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class FeatureBuilder {
1111
final int count;
1212

1313
FeatureBuilder(this.land, this.state, this.startHeight, this.count) {
14-
1514
for (int i = 0; i < count; i++) {
1615
int spx = _rng.nextInt(land.width);
1716
int spy = _rng.nextInt(land.width);
@@ -31,13 +30,16 @@ class FeatureBuilder {
3130

3231
void drawPoint(int x, int y, int c) {
3332
if (x < 0 || y < 0 || x > land.width - 1 || y > land.width - 1) return;
33+
if (land.data[x][y].height < c)
34+
land.data[x][y].height = c;
3435

3536
land.data[x][y]
36-
..height = c
3737
..state = state
3838
..nextState = state;
3939

40+
4041
if (Vary3()) c--;
42+
4143
if (c > 0) {
4244
if (Vary2()) drawPoint(x + 1, y - 1, c);
4345
if (Vary2()) drawPoint(x, y - 1, c);
@@ -54,11 +56,11 @@ class FeatureBuilder {
5456
}
5557
}
5658

57-
bool Vary2() {
58-
return _rng.nextInt(7) == 1;
59-
}
59+
bool Vary2() =>
60+
_rng.nextInt(7) == 1;
61+
62+
63+
bool Vary3() =>
64+
_rng.nextInt(19) != 1;
6065

61-
bool Vary3() {
62-
return _rng.nextInt(20) != 1;
63-
}
6466
}

web/lib/forest.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ class Forest {
4040
land = new Grid(getTreeChance, getFireChance);
4141
print("world created");
4242
//water
43+
addWater();
44+
print("water created");
45+
addMountains();
46+
print("stone created");
47+
}
48+
49+
void addWater() {
4350
new FeatureBuilder(
4451
land, PlotState.water, 20 + rng.nextInt(20), 6 + rng.nextInt(6));
45-
print("water created");
52+
}
53+
54+
void addMountains() {
4655
new FeatureBuilder(
4756
land, PlotState.stone, 20 + rng.nextInt(20), 6 + rng.nextInt(6));
48-
print("stone created");
4957
}
5058

5159
void update() {

web/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ final InputElement speedControl = querySelector('#Speed');
1919
final ButtonElement startButton = querySelector('#Start');
2020
final ButtonElement stopButton = querySelector('#Stop');
2121
final ButtonElement resetButton = querySelector('#Reset');
22+
final ButtonElement mountainsButton = querySelector('#Mountains');
23+
final ButtonElement lochsButton = querySelector('#Lochs');
2224
final SpanElement statusDisplay = querySelector('#Status');
2325

2426
final Forest trees = new Forest();
@@ -75,4 +77,10 @@ void setupGuiEventHandlers() {
7577
trees.reset();
7678
statusDisplay.text = "World built.";
7779
});
80+
mountainsButton.onClick.listen((e) {
81+
trees.addMountains();
82+
});
83+
lochsButton.onClick.listen((e) {
84+
trees.addWater();
85+
});
7886
}

0 commit comments

Comments
 (0)