Dark theme

Hopefully you've got a game you're happy with, but you've probably become frustrated with sorting out the order of nested if-statements? In this part, we'll look at a solution to this.

Really nested if-statements are only for short sequences in a game - you wouldn't build a whole game out of them because it would be too hard to keep track of. So, we're going to re-write our game without them!

You might think this is frustrating, having just spent a lot of time writing them, but rewriting stuff in a better way after an initial go at it is very common in software: it is called refactoring.

Ultimately, the important part of your game, and the bit that takes time getting right, is what the game is about and the interaction with the user, not the code beneath. If rewriting the code gives you more options or makes the game better, it is worth rewriting - the effort you've put in to thinking about it isn't lost!

With that in mind, let's look at a better way of building our game, based on a map...

[Home > Part 5 > Next]