Browse Source

Finish chapter 27.

Herbert Wolverson 4 years ago
parent
commit
bd1eb1bb36

BIN
book/src/c27-s2.gif


+ 17 - 2
book/src/chapter_27.md

@@ -433,13 +433,28 @@ This is quite simple: it iterates through each area, and calls the new `spawn_re
 
 The game is now quite playable on these new maps:
 
-(SCREENSHOT)
+![Screenshot](./c27-s2.gif).
 
 ## Restoring randomness
 
+Once again, we should restore randomness to our map building. In `map_builders/mod.rs`:
+
+```rust
+pub fn random_builder(new_depth: i32) -> Box<dyn MapBuilder> {
+    let mut rng = rltk::RandomNumberGenerator::new();
+    let builder = rng.roll_dice(1, 4);
+    match builder {
+        1 => Box::new(BspDungeonBuilder::new(new_depth)),
+        2 => Box::new(BspInteriorBuilder::new(new_depth)),
+        3 => Box::new(CellularAutomotaBuilder::new(new_depth)),
+        _ => Box::new(SimpleMapBuilder::new(new_depth))
+    }
+}
+```
+
 ## Wrap-Up
 
-We've
+We've made a pretty nice map generator, and fixed our dependency upon rooms. Cellular Automota are a *really* flexible algorithm, and can be used for all kinds of organic looking maps. With a bit of tweaking to the rules, you can make a really large variety of maps.
 
 **The source code for this chapter may be found [here](https://github.com/thebracket/rustrogueliketutorial/tree/master/chapter-27-cellular-automota)**
 

+ 4 - 4
chapter-27-cellular-automota/src/map_builders/mod.rs

@@ -21,13 +21,13 @@ pub trait MapBuilder {
 }
 
 pub fn random_builder(new_depth: i32) -> Box<dyn MapBuilder> {
-    /*let mut rng = rltk::RandomNumberGenerator::new();
-    let builder = rng.roll_dice(1, 3);
+    let mut rng = rltk::RandomNumberGenerator::new();
+    let builder = rng.roll_dice(1, 4);
     match builder {
         1 => Box::new(BspDungeonBuilder::new(new_depth)),
         2 => Box::new(BspInteriorBuilder::new(new_depth)),
+        3 => Box::new(CellularAutomotaBuilder::new(new_depth)),
         _ => Box::new(SimpleMapBuilder::new(new_depth))
-    }*/
-    Box::new(CellularAutomotaBuilder::new(new_depth))
+    }
 }