Build a C#/WPF RPG

This is a new version of my previous lessons in Learn C# by Building a Simple RPG. Except, the user interface will use WPF/XAML, instead of Windows Forms.

I’m also trying a different style for these lessons. They will be mostly video-based, so I can talk about why I’m writing the code a specific way. I hope this will give you an idea of how a programmer thinks, when they work on a program.

There will still be a webpage here for each lesson. They will summarize any new techniques covered in the video. You can also leave questions on those pages.

 

NOTE: This course is “in-progress”.

 

Overview

Lesson 00.1: Overview

 

Preparation

Lesson 01.1: Installing Visual Studio Community 2015 – Update 3

Lesson 01.2: Installing TortoiseSVN and VisualSVN

 

Planning

Lesson 02.1: Planning the Game

 

Programming

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

 

Future lessons (exact content and order may change)

  • 07.2 – Adding monsters to locations
    • List of monsters, random selection
    • Add the game message box
  • 07.3 – Fighting monsters
    • Display weapon controls
    • Combat
      • Player loses
      • Player wins
        • Gets loot/experience points/gold
  • 08.1 – Creating vendors
    • With inventories
    • Add to Locations
    • Display “Trade” button
  • 08.2 – Add “Trade” screen
    • Buy/sell items
  • 09.1 – Creating Vendors
    • With inventories
    • Add to Locations
    • Display “Trade” button
  • 09.2 – Add “Trade” screen
    • Buy/sell items
  • ?? – Save/load game

26 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. 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
    Markus

    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
        Markus

  7. 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?

    and

    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: http://answers.unity3d.com/questions/1254748/how-to-integrate-a-c-project-in-unity.html. 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.

Leave a Reply

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