Extracting Code to Functions
The logic you coded into NyetHack in Chapter 3 was sound, but it would be a better practice to organize it using functions. Your first task is to reorganize your project to encapsulate much of the logic you have already written in functions. This will set the stage for adding new features to NyetHack.
Does this mean you are going to delete all your code and type the same logic in a different way? Perish the thought. IntelliJ will help you group your logic into functions easily.
Begin by opening your NyetHack project. Make sure the file Game.kt is open in the editor.
Next, select the conditional code that you defined for generating the player’s healthStatus message. Click and drag the cursor, beginning ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access