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



Future lessons (exact content and order may change)

  • Add automated unit tests
  • More features
    • ??? – Load world data from XML file
    • ??? – Healing items (potions, food, etc.)
    • ??? – Crafting recipes
    • ??? – Save/load player game data
    • ??? – Enchanting items (weapons)
    • ??? – Complex battle logic

61 thoughts on “Build a C#/WPF RPG

    1. Thank you. Are you asking about the ability to load the game data (items, locations, monsters, etc.) from a file or database? If so, I think I can do that soon. I updated the future lessons list for what I have planned.

      1. not exactly im more talking about that i would store a city etc in a world entity
        so im am searching for a way to connect the locations from 2 different worlds.
        so that u can “walk” from one location to another in different worlds.
        though i have writen a connector class to connect the locations i m searching for another solution due to i have to add the connector manually every time i create a new world, wich i want to create with a world creator.

        1. The first idea I have is to create a new City class that has a list of Locations. Then, the World class holds a list of cities – and does not store Locations. The GameSession class would need another property for CurrentCity. If you have a “Travel to new city” button, that would show all the City objects in the World class. The City class would probably also need a “StartingLocation” property, for when a player first goes to that city. The World class would porbably also need a “StartingCity” property, for when a player starts a new game.

          There is probably more to consider. But, that is how I would start.

          1. To help out with Marco question:
            Why not have another location before the x,y coordinates?
            Then you can have 0 – Current map, x, y?
            This will allow to add more locations up and down.

          2. You could definitely do that. If you wanted to add locations above and below (a third dimension of travel), you could add a “Z” coordinate property to the Location class. Or, if you want to have cities, you could add a CityID property. If you do cities, I would probably add a “Cities” SortedList or Dictionary static property to the World class. It would have an integer as its key (for the CityID), and a string for the value (to hold the city name). That property would be useful when you want to associate the ID with the city name for the UI.

  1. Hi Scott. The walkthrough is really helping. Thanks! Going back a bit to the creation of the Quest Factory, you set it up so that itemsToComplete and rewardItems are set references for quests. I’m assuming you mean to change that so that any new quests will be able to have different quest items and rewards. I was thinking of putting it in an array, but I don’t want my code to diverge too far from yours. 🙂 Now that you are back to making updates I’m wondering if that could be in a future refactoring session?

    1. You’re welcome.

      Yes, to make additional quests, you would need to do itemsToComplete.Clear() and rewardItems.Clear() before populating those variables for the next Quest. Or, you could use some other technique to populate the Quest’s ItemsToComplete and RewardItems properties. In the future, all these factories will be changed to load from data files, or a database. But, I want to make sure the models are close to finished, so we don’t need to constantly update the data files to match the changed model classes.

      It should be safe to modify the factories to instantiate more locations, monsters, quests, etc. I don’t think any of the changes should affect the factories too much, until the big change to load them from data fiels.

  2. After the last lesson 10.3, I’m only seeing 1 of the quest items being removed instead of all 5 (it was working previously). I replaced my code with yours for the quests in case I I accidentally made some change, but there is no difference. It’s like the foreach loop is only running once. Any suggestions on where to look?

    1. You are correct. It looks like I have a bug in the RemoveItemFromInventory function, when subtracting quantities in the GroupedInventory property. I’ll make a bug-fix video. But, if you want to fix it now, I think you can change lines 147-148 in LivingEntity.cs to:

      GroupedInventoryItem groupedInventoryItemToRemove =
      GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID);

  3. Scott,
    I really enjoyed going through this with you. Is it possible you can post the completed code? I think I have an error, particular, the Quantity is not increasing. Strange is that the TraderScreen shows correct amounts.

  4. Hi Scott,

    I’ve been working on expanding the program with minor things like implementing additional attributes and weapons. I noticed the money system is very simple and breaks quickly when adding more expensive items. Instead of having a 5000 Gold Greataxe, I was wondering if you had thought about expanding to a copper/silver/gold/platinum system. A couple coppers for a rat tooth sounds more likely that a couple gold.

    I found a nice looking RPG currency System at


    1. You could do that. I would probably do something a little simpler. I’d create an extension method (let’s call it ToFormattedMoney) to format the integer property value as “1p 12g 75s 33c” – unless you want to force the player to go to a bank and convert their coins from 100 copper into 1 silver (for example). Then, I’d create new expression-bodied properties like “public string FormattedPrice => Price.ToFormattedMoney();”, and bind to those properties in the UI.

Leave a Reply

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