Chapter 9 Victory and Defeat

Hands-on Rust — by Herbert Wolverson (70 / 120)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Wrap-Up | TOC | Building a Smarter Monster 👉

After hours of searching the twisting dungeon halls, our brave hero notices the glistening Amulet of Yala in a corner. Raising the amulet in triumph, the hero slips its chain around their neck. Power courses through them and the darkness that threatened their home is repelled. They have achieved a great victory and can rest — knowing that their friends and families are once again safe.

Meanwhile, in an alternate universe, our hero is surrounded by enemies. Fatigue weighs the hero down as they hew at a seemingly never-ending wave of monsters. Orcs and goblins fall, but the hero suffers increasingly devastating injuries as they fight to forestall the end. Finally, a vicious orc lands a telling blow and our hero sinks to the ground — defeated.

What you’ve just read are common endings in roleplaying games: the player has either won or lost the game. The two go hand in hand; victory with no chance of failure isn’t a game and failure with no chance of winning is just depressing.

In this chapter, you’ll give the monsters some intelligence, introducing the real possibility of failure. You’ll add a game over screen with an option to try again.

Once you have that working, you’ll add the code necessary to spawn the Amulet of Yala somewhere within the dungeon, and as far away from the player as possible. You’ll also add…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.