Press "Enter" to skip to content

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



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


Cleanup/bug fix

Lesson 99.1: Fix event subscriptions

Lesson 99.2: Replace random number library


Customizable Player attributes

Lesson 18.1: Making Configurable GameDetails

Lesson 18.2: New starting windows and configurable player races

Lesson 18.3: Player creation screen

Lesson 18.4: Adding Player Attributes to Living Entities

Lesson 18.5: Update game loading and saving


Upgrade and improvements

Lesson 19.1: Converting SOSCSRPG to .NET 5

Lesson 19.2: Identifying refactoring targets

Lesson 19.3: Move data and image files out of Engine project

Lesson 19.4: Replace BaseNotificationClass with Fody PropertyChanged Notification

Lesson 19.5: Convert properties to auto-properties

Lesson 19.6: Move files out of Engine project

Lesson 19.7: Decouple services from ItemQuantity

Lesson 19.8: Create SOSCSRPG.Core project for native language extensions

Lesson 19.9: Decouple services from Location and Monster model classes

Lesson 19.10: Create a GameState model for SaveGameService

Lesson 19.11: Move common functions to SOSCSRPG.Core

Lesson 19.12: Decouple InventoryService from LivingEntity

Lesson 19.13: Remove CombatService dependency from model classes

Lesson 19.14: Moving the Engine classes to their new projects


UI Improvements

Lesson 20.1: Create floating inventory canvas

Lesson 20.2: Create floating quest and recipe canvases

Lesson 20.3: Create floating player details canvas

Lesson 20.4: Create floating game messages canvas


  1. Dave Work
    Dave Work 2021-11-05

    Having pasted your entire file, I receive the following error in VS2019 and the window design does not appear:
    Severity Code Description Project File Line Suppression State
    Error Could not find file ‘C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ImageName’. WPFUI MainWindow.xaml 2

      SOSCSRPG 2021-11-05

      Hi Dave,

      I believe that is not a “real” error. Can you run the program, and does it look like it works?

      If the program runs correctly, that error is probably coming from Visual Studio trying to interpret the XAML page, which expects an instantiated Location object, with an ImageName value that points to a location (or monster) file. When you’re editing or compiling the program, and don’t have instantiated objects to bind to, Visual Studio shows that “error”.

      Please let me know if that is not the problem, or if my response is not clear.

      • Dave Work
        Dave Work 2021-11-10

        Hi Scott,

        Thanks for your response. The program runs ok.

  2. Manuel Ketisch
    Manuel Ketisch 2022-04-29

    Hello, thank you for this huge project. It is a wonderfully helpfull tutorial. I am learning a lot of things and appreciate all the effort and tim eyou invest into this project.
    Hopefully you will find experienced assistance to keep this project alive.

    Something i noticed about the new website. The code area could be somewaht wider. To read most of the code lines, you have to scroll alot sideways. I know there is videos in the first place, but maybe it is not that much needed to widen the text area so more of the code gets visible at once.

    Good luck with the project, i hope to see more videos in the future.
    Is there a .Net6 conversion in planning ?

      SOSCSRPG 2022-04-29

      Thanks Manuel.

      I changed the page layout to be wider. In lesson 191., we convert the solution to .NET 5. I haven’t tried it, but you can probably convert it to .NET 6. I tried to avoid code that only works in specific versions.

      • Manuel Ketisch
        Manuel Ketisch 2022-05-14

        Thanks alot, it is much better to read now.

        Understandable, I have converted my project to .NET6 and it works so far.

        Will this project receive any further lessons in the future? If so, what are you currently working on?

        Again, thanks for this great tutorial.

        • SOSCSRPG
          SOSCSRPG 2022-05-15

          I want to add more lessons in the future.

          Right now, I am working on creating a paid course for C# and SQL Server. I’d like to build a business teaching programming. Once I release this course, I’ll have a little time to add some more things to SOSCSRPG, but I don’t know exactly what new changes to make. If you have any ideas what you’d like to see next for the game, please let me know.

  3. Manuel Ketisch
    Manuel Ketisch 2022-06-10

    #Quote: “Right now, I am working on creating a paid course for C# and SQL Server. I’d like to build a business teaching programming. Once I release this course, I’ll have a little time to add some more things to SOSCSRPG…”

    Ok, nice. Looking forward to that course. =)

    Hmm, maybe some of the things already included as future release plans?
    maybe this?
    Armor System? Jewelry System? Echantment System? Buff/Debuff System?
    RPG Style Equipment window, drag and drop Items to slots, prevent items not fitting a slot to be equipped etc.?

      SOSCSRPG 2022-06-10

      Hi Manuel,

      I released the SQL course at:

      The separate program to manage the game data files might be a good thing to work on next. Although, I’m not sure if it would be better to make the changes to the class files first – since those changes would need to be handled in the game file editing program.

      • Manuel Ketisch
        Manuel Ketisch 2022-06-13

        Hi Scott,

        cool, bought the course. SQL is something that interests me. Haven’t yet spend to much time with it though. So this will come in handy. =)

        Hm, i guess handling the prerequisites first instead of jumping back and forth would be best in my opinion.

        • SOSCSRPG
          SOSCSRPG 2022-06-13

          Hi Manuel,

          Thanks for getting the course! It does need a little C# knowledge. But, if you understand classes, properties, functions, collections/lists, and static classes, you should be able to follow all the lessons.

          If you have any suggestions about ways to improve the lessons, please let me know.

  4. Claus Volko
    Claus Volko 2022-09-12

    Your tutorial is a highly valuable resource for C# programmers. I’ve learned a lot. Thanks!

      SOSCSRPG 2022-09-12

      You’re welcome! That’s great to hear.

  5. Stanley Morris
    Stanley Morris 2022-10-01

    Happy Fall Scott. I have been following your site and projects over the years. I was wondering if you were ever considering a console version of the second RPG game. Some of us are still on Mac though Visual Studio is getting better on Mac. We could do the console if needed

      SOSCSRPG 2022-10-05

      Thanks Stanley! I’ve tried to think of what to do next with SOSCSRPG, but haven’t come up with anything yet. Well, I’ve come up with a lot of ideas, but haven’t been able to get focused on one yet.

      I do like the idea of a console version. I’ve been writing more of my personal programs as console apps, and that would also allow for writing some natural language processing code.

      I just started a new project for a client, so I know I won’t start anything with SOSCSRPG for at least a few weeks. If I get started on updates for the game, I’ll post here and at the YouTube channel

  6. Wicked Cat
    Wicked Cat 2023-05-05

    Is this still being updated or have you moved on?

    I’m learning so much and I’m grateful, I’d like to also see combat against multiple enemies at once and player companions to help in combat. Buffs/debuffs, special abilities, npc’s to talk to.

    Thank you for all the work you put into this 🙂

      SOSCSRPG 2023-05-06

      You’re welcome Wicked Cat!

      You are correct. I’m not doing any further enhancements or updates for the game (although I still answer questions about the lessons). I’ve been trying to figure out my next project to work on, but haven’t decided what it should be yet. I’m glad to hear you’ve learned from these lessons and hope you can continue having fun with programming. 🙂

  7. Lazie
    Lazie 2024-02-23

    Thank you very much, I had been looking for a project for a long time that taught several C# concepts in a single application, not like in most books where each topic has an example but you can’t understand how each topic can be used or connected with the others.

    In your lessons it’s as if you were teaching how to build a house, first teaching what a tool does, then going to the house and using the new tool to create something new or improve something that already exists.

    You are an excellent programmer and teacher!

      SOSCSRPG 2024-02-23

      You’re welcome! I’m glad you liked the lessons. I hoped that building up a single program would make more sense for people learning, and maybe motivate them as they saw their program gradually grow and do more things.

      • Lazie
        Lazie 2024-05-21

        Hi, I made the project public on GitHub, if you want to take a look at it:

        In the link there is also an image of what the game’s UI looks like at the moment.
        I took your course 4 times, and now I’m having the “daring” to do some things differently. I’m building slowly because the journey is more interesting than the arrival point.

        I can only thank you immensely for everything I learned from you.

        • SOSCSRPG
          SOSCSRPG 2024-05-21

          Hi Lazie!

          You’re welcome!

          I’m glad to hear you’re venturing into experimenting with your own ideas. That’s when programming gets really fun. 🙂

          I tried visiting the link to your project, but the project didn’t show up when I clicked on the link.

Leave a Reply

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