Build a C#/WPF RPG

This is a new WPF/XAML game, based on the game from my Windows Form tutorial: Learn C# by Building a Simple RPG


For the latest version of the complete solution, visit:



Lesson 00.1: Overview



Lesson 01.1: Installing Visual Studio Community 2015 – Update 3

Lesson 01.2: Installing TortoiseSVN and VisualSVN



Lesson 02.1: Planning the Game



Lesson 03.1: Creating the Solution and Game Screen

Lesson 03.2: Creating and Using a Subversion Repository

Lesson 03.3: Creating the Player Class

Lesson 03.4: Creating the GameSession (ViewModel) Class

Lesson 03.5: Displaying the Player Object

Lesson 03.6: Update Player data with the PropertyChanged event

Lesson 04.1: Creating the Location class

Lesson 04.2: Creating the World

Lesson 04.3: Moving in the game world

Lesson 04.4: Improving the World – Inheritance and INotifyPropertyChanged

Lesson 04.5: Improving the World – Factory and Guard Clauses

Lesson 05.1: Creating the Game Item Factory

Lesson 05.2: Creating the Player Inventory

Lesson 06.1: Creating the Quest Factory

Lesson 06.2: Using Quests in the Game

Lesson 07.1: Creating Monsters

Lesson 07.2: Adding Monsters to Locations

Lesson 07.3: Sending Messages from the ViewModel to the View

Lesson 07.4: Monster Combat

Lesson 07.5: Monster and Combat Refactoring

Lesson 08.1: Completing Quests

Lesson 09.1: Creating Traders

Lesson 09.2: Adding the Trade Screen


Cleanup/refactoring, before adding more features

Lesson 10.1: Refactoring Base Class for Player, Monster, and Trader

Lesson 10.2: Grouping GameItems in Inventories

Lesson 10.3: Refactoring – Encapsulating LivingEntity Properties (Hit Points and Gold)

Lesson 10.4: Bug Fix – Removing multiple items from GroupedInventory

Lesson 10.5: Encapsulating Level and ExperiencePoints Properties

Lesson 10.6: Clean up property setters and PropertyChanged notifications


Create a base for automated tests

Lesson 11.1: Creating the Unit Test Project


New game features

Lesson 12.1: Making the GameItem class more flexible

Lesson 12.2: Creating the AttackWithWeapon command

Lesson 12.3: Making the Action class more flexible with an interface

Lesson 12.4: Letting the Monster use AttackWithWeapon

Lesson 12.5: Creating the first consumable GameItem

Lesson 12.6: Refactoring after adding Actions

Lesson 12.7: Creating recipes

Lesson 12.8: Crafting items with recipes

Lesson 13.1: Add keyboard input for actions, using delegates

Lesson 13.2: More keyboard actions (and fixes)


Load game world objects from XML files

Lesson 14.1: Moving game data to external files

Lesson 14.2: Creating extension methods

Lesson 14.3: Read World (Location) data from an XML file

Lesson 14.4: Read Monster data from an XML file

Lesson 14.5: Move Remaining Game Data to XML Files



Lesson 15.1: Bug Fixes, Unit Tests, and Tooltips

Lesson 15.2: Catch and log exceptions

Lesson 15.3: Building a “functional” inventory class

Lesson 15.4: Using GitHub to upload and download a solution


Better combat

Lesson 16.1: Adding centralized messaging

Lesson 16.2: Creating the Battle class

Lesson 16.3: Complex attack initiative and hit success logic


Continued lessons

Lesson 17.1: Saving and loading game state

Lesson 17.2: Reducing serialized data in save game file

Lesson 17.3: Add a menu to save and load the game state

Lesson 17.4: Automated test for saved game reader


Lesson 99.1: Fix event subscriptions

172 thoughts on “Build a C#/WPF RPG

  1. Scott, I hope you will be continuing this series in the near future. I enjoyed following the Windows Forms version and feel like it was a valuable lesson. Now, I would like to move into the WPF world and ‘get more serious’ about interfaces, application programming and the like. your videos are extremely clear and easy to follow and really helps someone like me who is extremely visually oriented. Anyway, great job and like I said, please keep going!

  2. Scott,

    I want to thank you for putting these lessons together. I just finished your ebook version of “Learn C# By Building a Simple RPG”, or at least the first 18 lessons of it, and while you went into a lot of depth with your descriptions, hearing you talk about what you’re doing really helps to cement the ideas for me. I’m new to programming in general, so your lessons and the C# Yellow Book have been a huge help.

    Thank you again, I look forward to your next lesson.

    1. Thank you Kyle,

      I got busy during the holidays, but new lessons are on the way. I’m currently editing the second version of the next lesson (I didn’t like the first version), and should post it this weekend.

  3. I really loved your first series because it wasn’t all video. I learn a lot better when I read things – because they are easy to access later. Its so hard to find things later in a video. I realize it is probably a lot more work to write things out and you are kindly doing something for so many by teaching us coding in an interesting way. If you do decide to release transcripts I’m sure many will appreciate it.

    By the way, one thing that isn’t yet clear is the advantage of WPF/XAML, instead of Windows Forms. Could you enlighten us?

    1. Thanks for reminding me. Before the holidays, I started to search for a transcriber – but got busy with everything else. I’ll get back to finding someone.

      For WPF versus Windows Forms: It’s a little simpler to connect WPF to events (button clicks, text changed, etc.). But, the biggest advantage of WPF is that more people (and businesses) are using it to develop their programs. Most new projects I’ve seen over the last two years are in WPF. So, if you look for a C# programming job, you’ll probably need to know it.

    2. I would like to add that as I am currently learning WPF some of the advantages I’ve seen first is the flexibility of the new tools in VS 2015,next I would say designing the code logically in an XML format but more than anything the ability to embed controls within other controls so easily because they are designed to be this easy. In Winforms way way more difficult to achieve the same results. So you can really spice up your interfaces now quite easily.

      1. Another thing that would be very nice is to write C# code that outputs everything in HTML5 so it can be run through a browser – and then potentially become a multi-player game.

        What is the recommended way to take say WPF code and convert it so it runs as a web app?

        How about creating mobile phone apps using Xamarin to implement the RPG games?

        1. When the program has most of the basic features, I’ll show how to quickly attach different front-ends.

          Because we are using MVVM, it will be very simple to make the program work as a web program, as a console app, or any other type of user interface. If you haven’t already seen it in the previous course (building a similar game with a Windows Forms front-end), in Lesson 23.1, I show how to quickly create a console front-end for that game. That program did not have the ViewModel layer, so it wasn’t as simple as this one will be. However, it was still a relatively easy task.

  4. atm i try to change my views with the MVVM model
    i have a start screnn with change to the game screen however if have now to ViewModel folders one in the engine project and one in the WPFUI project.
    now my problem is i can change the view to the game screnn but now im stuck because im in the engine viewmodel folder is there a way to get back to the wpfui viewmodel or should i try it with a mvvm in only one project?

    1. I would keep all the ViewModels in the Engine project. This is not required. However, it will make several things easier – including automated tests, which we will add later.

      You could put the code to change to the different window in the XAML.CS, because that is functionality of the user interface (close this window, and display another window).

    1. I don’t have a regular schedule – especially over the last couple of months, when I was preparing for a live webinar (and finally took a vacation). But, it would be good to have one. I’m going to look at all the projects on my “To Do” list, see what I can trim, and try to come up with a consistent schedule.

  5. Hello Scott,

    I’ve had a lot of fun completing this course, and I’m learning a lot too. I started learning C# about 8 years ago, learned a lot of the basics, and never did anything with it. Thanks to you, everything I use to know has come back, and I’m learning really cool new stuff too.

    I actually first started out programming with text based adventures, all based in the console. I can’t wait to keep learning while also adding my own flair to the game we are making!

    1. I’m glad to hear the course helped. One nice thing about the program is that the game is easily expandable. Several people have shown me their modified versions, which were very cool.

  6. Also possible to have the videos up for download ? Would like to be able to download all of them and learn on the road.

  7. Hello Scott,

    i’ve read your tutorials with great interest – it’s clear and very easy to understand why you do the things the way you’re doing.

    Is it planed to add some better graphics to the game (maybe by using an external graphics engine like sdl or sharpDX)?

    Best regards from austria

    1. Hi Markus,

      Yes, I plan to add different front-ends. After completing the “Save/load” lesson, I will post the project to GitHub and plan to create a J-RPG UI, and maybe a rogue-like UI. However, those will probably use use standard .NET libraries. For other UI libraries, I will need to be sure the license works with the SOSCSRPG project license (I always use the MIT license).

      1. Hi Scott,

        thanks for your reply.
        The idea of using the standard .NET UI libraries sounds great – i’m looking forward to the next lesson!

        I’ve found out, that SharpDX uses the permissive MIT licence.

        Best regards

  8. Hi Scott,

    Thank you so much for taking the time and effort out of your life to do these courses – I’ve learned so much from following along both your previous RPG course and this one so far; I have one question though.

    So far I’ve been following along adapting your course to my own needs (I’m not doing an RPG but a business sim) and while I can directly use a lot of what you’re doing in terms of classes, architecture, factories and conceptual understanding of e.g. MVVP structure, I’m currently finding myself faced with the problem of adding a “main menu” screen to the game and MainWindow.

    I can do plenty of popups just fine, but having the game launch to a splash screen with a series of buttons like “NEW GAME”, “LOAD”, “CONTINUE” and “EXIT” and then transition to the mainwindow screen once new game is pressed. This problem ties into a recurrent worry I have that I may be handicapping myself and my game making efforts by not using Unity – I know that in unity the creation of, and transition between, scenes is a rather trivial matter but I cannot come up with an elegant solution for WPF.

    So my question is this:

    a) do you have any thoughts on how one might transport what is currently available in this fine course of yours and add the necessary architectural stuff to allow for scene/screen transitions?


    b) if not, are you familiar with unity and could you feasibly see e.g the ENGINE being adapted for use with a unity project?

    again – thank you so much for making this material available, it is a goldmine!

    1. Hi Stefan. I’m glad to hear that you like the course.

      I haven’t done any work with Unity, but have seen some source code for Unity projects. Much of the Engine project could be used in a Unity solution. You might need to use different ViewModels (although, the existing ones might work). But, the Models, Factories, and everything else should work without any changes.

      This post talks about how to integrate a C# program into Unity: You can try adding the Engine project to a new Unity solution, and seeing how easy it is to connect to the ViewModel, or the Player Model. A small experiment should let you know if it’s something simple to do, or if it will need more work.

  9. Loving the course so far, great work & thanks.

    I was wondering if you had any plans to implement a crafting system down the line? It would be very interesting to learn.
    Also looking forward to the potential JRPG & Roguelike UIs you mentioned above.

    Thanks again.

  10. Scott,
    Thanks for putting this out. I just started teaching C# at a Tech Collage and we have our students building an RPG for their projects. I point them to this site as an example and to learn from. You explain why you use what you use so well that I am still learning every time I come back.

    Thank you again.

  11. Hey Scott,
    Keep up the good work, i’m a total beginner at c# and am hoping to make a career out of it once I feel that I am capable enough to do so! I’m currently following a c# course through another source, but have today found your site and have favourited it.. so will be coming back in the near future to follow your lessons. Have you thought about signing up to Udemy or something similar?


  12. Hey Scott,

    I’m really digging the tutorials. I’ve been doing C# for about 3 years now and what got me going on your stuff is the Win-forms RPG. It’s funny because people say that Win-forms isn’t as popular or widely used but I find many uses for it. All the way from tools to basic programs. As a game play programmer I was thrilled to go thru your course and use Win-forms for games! This series uses XML which is great and I look forward to your future releases! I do have one question though, will you be doing any courses later that deal with php? I know you mention mySQL but I was wondering if you were thinking of doing of adding to this game or another where the player data is saved on a server and pushed thru using php/json.

    Thanks again!


    1. Hi Tim,

      Thank you! It’s great to hear you like the tutorial. There won’t be a PHP version, because it’s been years since I’ve done any PHP wok. There is a WPF version I’m working on here. I’m probably not going to do much more with this version of the game – any new work will be in the WPF version.

  13. Been great watching the development on this – Did anything come of the Udemy course? – I would gladly pay for the course.

  14. Loved your series, more than informative.

    I’m hoping we get to the point of adding settings and working with databases.
    Any idea on a timeline for these types of functionality?

    If you ever do release that SQL course you mentioned, please mention somewhere in these tutorials. It would be most helpful.

  15. Hey, I don’t know if my previous comment got through, so I’m sending this as well. 🙂


    Are you actively working on this tutorial, or has it been put on hold?

    Also, do you think it would be easy to follow along in UWP instead of WPF?

    1. Hi Alex,

      I’ve been busy with starting a consulting company, but am starting to get some free time. I just uploaded the next lesson today.

      I’m not sure about using UWP. I haven’t done anything with UWP yet.

  16. Hello, I was wondering if you use entity components for building this game and or the other RPG. I understand the concept of them but I have no idea how to do it and there are very few tutorials on it even though it seems to be wide spread in making games to avoid class inheritance collapsing.

    This guy goes into one way he did in C# but it’s pretty advanced. I’m only just now getting into events and I don’t have a clue about ‘reflection’ other than I know it’s apart of .NET.

    If you don’t go into entity components I hope you’ll consider it, you’ll be one of the very few to actually show how to do it. Thanks.

Leave a Reply

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