Lesson 20.1 – Refactoring the SuperAdventure program

Right now, SuperAdventure works the way it should. But the code is a little sloppy in some places. That’s because I didn’t want to get into the more complex parts of programming for this beginner’s guide.

However, if you’ve come this far, you’re ready for more advanced techniques.

As you do more programming, and write larger programs, you’ll want to keep your solutions, projects, and classes well-organized. You’ll also want to keep the logic out of the user interface code – something we didn’t do in the current project.

We’re going to clean up SuperAdventure by refactoring – making changes to a program, without changing the way it works (adding new features, fixing bugs, or making it faster). These changes are only for us – so it will be easier to maintain the program and add more features in the future.

Ideally, your UI code should only do things related to receiving input and displaying output. In the current program, the UI code handles some of the game logic. It should really only handle receiving input from the player, and displaying output from the classes in the “Engine” project.

We’ll continue what we started in Lesson 16.2 – Refactoring the player movement function. We’ll move more of the logic to the Player class, into smaller functions. We’ll also “decouple” the UI code from the logic code.

If any of these lessons aren’t clear, please leave a comment and I’ll try to improve it.


Next lesson: Lesson 20.2 – Binding a custom object’s properties to UI controls

Previous lesson: Lesson 19.6 – Increase maximum hit points when the player gains a level

All lessons: Learn C# by Building a Simple RPG Index

Leave a Reply

Your email address will not be published. Required fields are marked *