diff --git a/doc/tutorials/klondike/step5.md b/doc/tutorials/klondike/step5.md index 0c1be83aa7c..f9116b4580f 100644 --- a/doc/tutorials/klondike/step5.md +++ b/doc/tutorials/klondike/step5.md @@ -415,23 +415,24 @@ re-created during each of the above actions. ### KlondikeWorld class -In Flame, a World is a type of Component that can contain other Components, such as Piles. +In Flame, a ```World``` is a type of ```Component``` that can contain other ```Components```, + such as Piles. -You can learn more about Worlds in game programming here: +You can learn more about World in game programming here: -We won't dive too deep into Worlds here, just understand their purpose for now. +We won't dive too deep into World here, just understand their purpose for now. #### Creating KlondikeWorld -Let's create a World for our Klondike game, called KlondikeWorld. -At the start of the game, we'll create a World. Each new game will be represented by a new World. +Let's create a ```World``` for our Klondike game, called ```KlondikeWorld```. +At the start of the game, we'll create a ```World```. Each new game will be represented by a new World. Worlds are also created when the player restarts the game. -Each World is responsible for loading its own Components and dealing the cards accordingly. -Therefore, the onLoad() method will be moved from the KlondikeGame class to KlondikeWorld. -First, let's modify the KlondikeGame class: +Each ```World``` is responsible for loading its own Components and dealing the cards accordingly. +Therefore, the ```onLoad()``` method will be moved from the ```KlondikeGame``` class to ```KlondikeWorld```. +First, let's modify the ```KlondikeGame``` class: ```dart // KlondikeWorld is our new World @@ -449,6 +450,39 @@ class KlondikeGame extends FlameGame { ``` +The code above shows that when ```FlameGame``` is initialized, a ```KlondikeWorld``` is +also initialized. +Previously, without the ```KlondikeWorld``` class, FlameGame would create a +default ```World``` upon +initialization. It's important to note that a Game can have multiple Worlds, +but only one World is displayed at a time. + +We removed the ```onLoad()``` method from the ```KlondikeGame``` class and now +need to re-implement it in ```KlondikeWorld```. + +First, create a file called ```klondike_world.dart``` in the lib folder and add +the following ```KlondikeWorld``` class: + +```dart + class KlondikeWorld extends World with HasGameReference { + final cardGap = KlondikeGame.cardGap; + final topGap = KlondikeGame.topGap; + final cardSpaceWidth = KlondikeGame.cardSpaceWidth; + final cardSpaceHeight = KlondikeGame.cardSpaceHeight; + + final stock = StockPile(position: Vector2(0.0, 0.0)); + final waste = WastePile(position: Vector2(0.0, 0.0)); + final List foundations = []; + final List tableauPiles = []; + final List cards = []; + @override + Future onLoad() async { + // ... + + } +} +``` + #### what properties?