Building a Monopoly app - part 14: Embedding building houses into the main flow

In the previous (rather lengthy) episode, we built the flow that allows players to buy houses and hotels. In this episode, we’ll make sure that players get the opportunity to buy houses at the appropriate moment in their turn.

The short version is simply that the subflow for buying houses needs to be inserted here.

But that would make for a very short blog post, so let’s also talk about what else needs to be handled at that point in the flow.

When the player arrives at a new location, several subflows need to be executed. First of all, the following checks must be made:

  • whether a Rule needs to be executed
  • whether the player must pay rent
  • whether the player may and wants to but the position's Asset

The first two are not up to the player to decide, so it makes sense to handle those first. Purchasing a property, however, is a decision the player must make themselves—just like buying additional houses. Since you might want to place houses on a street you’ve just bought, the option to buy houses will come after the property purchase.

This needs to happen in both cases—after a double roll and after a non-double roll. Here’s what the SCR – Roll and Move flow currently looks like.

In all three of these subflows, the player may spend money. In some cases, they even must, even if they don’t have enough Cash Balance to cover it.

In that case, the player will need to come up with enough money by selling houses or properties, or by mortgaging properties. We’ll build that flow next time. For now, we’ll already add the decision point that determines whether the player needs to be guided through that flow. This decision comes after the mandatory expenses and before the option to buy houses.

To ensure that the main flow always has the player’s current Cash Balance, we need to make sure these subflows pass their updated data back to the main flow via the inputPlayer record. That’s why we’ll update the inputPlayer variable in all three flows to also serve as an output variable.

In the subflow elements within SCR – Roll and Move, we assign the output variable from each subflow back to `recordId`, the variable that represents the player in this main flow.

The sequence of elements now looks like this:

We do the same in the case where the player ends up with a non-double roll. Under the N path of that decision, we’ll insert the flow next time that allows the player to sell houses or properties.