Learn C# by Building a Simple RPG – Index

Giant Spider!
Mandatory Giant Spider!

If you want to write a Role Playing Game, but don’t know how to program, or just want to learn how to program in C#, then you’re at right the place.

These lessons will take you from a complete beginner, to being an author of a Role Playing Game, for free.

Now, this isn’t the world’s greatest game. In fact, it’s very short and kind of ugly.

However, as you create it, you’ll learn the most common C# programming practices and techniques. Then, if you want, you can improve the game, adding more features and your own special touch to it.



Lesson 00.1 – What is in these lessons?

Lesson 00.2 – General information about programming in C#

Lesson 00.3 – The parts of Visual Studio

Lesson 01.1 – Defining classes and objects for the game

Lesson 02.1 – Installing Visual Studio Express 2013 for Desktop

Lesson 02.2 – Building the solution for the game

Lesson 03.1 – Building the first screen

Lesson 04.1 – Creating the Player class and its properties

Lesson 05.1 – Creating objects from classes

Lesson 06.1 – Creating the remaining classes

Lesson 07.1 – Inheritance and base classes

Lesson 08.1 – Setting properties with a class constructor

Lesson 08.2 – Using class constructors with derived classes

Lesson 09.1 – Using your classes as datatypes

Lesson 10.1 – Creating collections of objects

Lesson 11.1 – Using a static class

Lesson 12.1 – Add the remaining UI controls

Lesson 13.1 – Functions, procedures, and methods

Lesson 13.2 – Creating functions to handle user input

Lesson 14.1 – Variables

Lesson 14.2 – If statements

Lesson 14.3 – Foreach loops

Lesson 15.1 – Getting random numbers for the game

Lesson 16.1 – Writing the function to move the player

Lesson 16.2 – Refactoring the player movement function

Lesson 16.3 – Functions to use weapons and potions

Lesson 17.1 – Running the game on another computer

Lesson 18.1 – Future enhancements for the game

Bonus lessons (enhancements to the game)

Lesson 19.1 – Scroll to the bottom of a rich text box

Lesson 19.2 – Use a calculated value for a property

Lesson 19.3 – Clean up the source code by converting foreach to LINQ

Lesson 19.4 – Saving and loading the player information

Lesson 19.5 – Changing dropdown default values

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


If you create a cool game, please send me a message with a link to your blog post, or video, showing your game. I’ll share it here.

62 thoughts on “Learn C# by Building a Simple RPG – Index

  1. I like this tutorial a lot. It’s exactly what I was looking for. I’ve already finished through 13.1. I can’t wait for your future lessons as I’m trying to learn C#, while also building a simple text based game (although it doesn’t feel that simple yet). I think you’re doing a great job and I’ll keep checking back for the rest of your lessons. I bookmarked this website. Cheers.

    1. In case you haven’t seen, there are several new lessons available.

      Lessons 14.1, 14.2, and 14.3 cover variables, “if” statements, and “foreach” loops.
      Lesson 15.1 adds a class to let you create random numbers.
      Lessons 16.1, 16.2, and 16.3 add code to move the player around, let them get quests, fight monsters, and complete quests. These lessons are a bit long, since they cover a lot of code.

      At the end of lesson 16.3, you’ll be able to play the complete game, running it from within Visual Studio. The next lesson will be on how to run the game on other computers, without Visual Studio installed.

  2. I just finished this series, and I have learned so much! This series was amazing, and it was very well done. Thank you so much for making this series! It really gave me a huge boost in the right direction.

    1. Thanks for letting me know it helped you.

      If you want to see how the game would look with some more advanced techniques (such as, LINQ and raising events to communicate from the Engine project to the UI), I’m currently working on it here: https://github.com/ScottLilly/ShinyRockHunter. I don’t have any lessons for LINQ or event-handling (at least, not yet). But I may write some when the app is closer to being completed, if people are interested.

  3. I was looking for a website that teach C# by doing project. Seems like I come to the right place!

    Thanks for all your effort. Bookmarked this website and going to start learning now :)

    1. I see you offered to answer questions to another poster, I would love to ask a couple myself, if you are willing to answer them or explain some more about the language and class system.

      1. Certainly. I’m working on a few projects right now. So, if they’re difficult questions, it make take me a few days to write up an answer for them. But feel free to ask.

        1. Thanks Scott. Your WinForm RPG tutorial was great. I have taken your exampled and converted it to a WPF. I am still trying to wrap my head around how to set things up on the back end. I have been playing around with the code and got a very basic attribute system (strength, endurance, et cetera) and a class/role system (knight, wizard, et cetera). But I think I may have not set it up very well, because it is clunky and difficult to use/reference. My question is how can such a system be designed to be versatile enough to allow for the application of bonuses (from for example equipped equipment stacked on top a base build) but simple enough not to require too much coding. Forgive the newbie question, but this is probably just me not being fully versed in how C# class and objects propagate and get passed through loops of code.

          1. There are a few different ways you can implement applying bonuses. My first questions are 1) What things do you want to receive bonuses (attributes like strength and endurance, things like “to hit” percentage, etc.) and 2) What items do you want to affect the attributes (just wearable/usable items, or do you also want to be able to add gems to wearable/usable items – for customized bonuses)?

            Either way, I think the basics would be for you to have a list of the current items the player is using/wearing, within the Player class. You could do this with some class-level variables or properties for the Player class (e.g., CurrentWeapon, CurrentHelmet, CurrentNecklace), or add an “InUse” property to the Item class, and manage setting the player’s currently active items through the Player class, when they want to wear/use a different item. You could also add some new properties to the Item class for ToHitPercentBonus, ProtectionFromMagicBonus, etc. Set those values to zero, except for the properties you want that item to give a bonus for. Then, in your “AttackMonster” method (for example), you would check the player’s inventory for items that have bonuses that affect the battle.

            Let me know if that makes sense. If it isn’t clear, or you think your code still looks clunky, maybe you can put the relevant classes in a GitHub Gist for me to take a look at. Although, I may not be able to check it out until this weekend. I’ve got a lot of work and meetings this week.

  4. I’m new to coding and I really want to create my own RPG game and I think this tutorial will help. Bookmarked on my browser and thanks a lot.

  5. Hey, I was going to put a comment earlier about how none of the code you gave worked. I have a little bit of knowledge in other programming languages such as C++ so i was able to understand the code to a certain extent. I found nothing that was wrong with the programs that I had made but there were still errors in a lot of the coding. I just could not figure it out. Since i am new to C# and visual studio, I am not too familiar with the default settings and some of the other things that go along with these two things. I saw how in one of the early lessons that you said that visual studio would automatically put some code into a new class. When i created a new class, that coding didn’t even show up so i just took the code from the source code you gave and tried it out. it still didn’t work. Well, after doing all of that trying to figure out what was wrong with it I just gave up and went on to try to find a different tutorial for C# thinking that these tutorials might have been out of date or something like that. After a few minutes of searching for something else about programming in visual studio, I found out that visual studio has more than just C#. At first that was all i thought it had but after I figured out that it also had C++ and visual basic, i thought that maybe I was not using the right language when i made a new project. So, I went into the project that i was working on with these tutorials and it turns out that it was the problem. By default, visual studio set the language to visual basic and that was what it was trying to compile in but I was trying to write in C++. So, anyway, just wanted to say that these are great tutorials and i really like them. I just have one question though. Is there a way tp change the language the project is set to after it has been created?

    1. Hi Levi,

      Yes, Visual Studio supports several languages: C#, VB.Net, C++, and F#. I’ve heard there are ways to use it for some other languages, like Ruby and Python – although I’ve never used it for that. So, when you create a project, you need to be sure to select the correct language for the classes you’ll create in the project.

      Unfortuntely, there isn’t really a way to change the language of a project after it’s been created. It’s best to delete the project with the incorrect language and create it again with the correct one.

  6. Hey!

    I wrote an e-mail about 2 hours ago (about 2015.02.02 19:20). Before this tut i could do nothing in windows form, just console. Now i won’t say i’m good at it, but i could add picture for every location, add new location, items, monsters, and stuff. My next goal will be talking with ,,npcs” (meaning more quest and shop). Thanks for everything. :)

  7. Great tutorial. I am having a few issues in running the program. Hope you can help. I got through all the lessons and ran the program. The program starts successfully. However, when I move around, I noticed that the combo boxes did not appear when there was something to do in a room such as an Item to pick up. It didn’t pick up the sword at the fountain and when I get to the rats, there is nothing to use against them. Any idea where I should look to make the combo boxes visible at the appropriate time? Not sure if you have enough info to answer this question.


    1. Thanks Tom.

      Did you start the tutorial a while ago? In an older version, I had a sword at the fountain, but don’t have that in the current one. Instead, I have this line in the Player class constructor:

      player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1));

      That gives the player a starter weapon at the beginning of the game.

      You can double-check the Player and World classes here: SuperAdventure on GitHub. Let me know if that doesn’t help you. I’m going to be offline until next Tuesday, but can help you after then, if there is still a problem.

  8. Hi Scott,

    Thanks a million for the tutorial. I thoroughly enjoyed revising the basics, and watching the final product evolve. It’s always an exciting thing to watch the project compile and pop up on the screen.

    Keep up the great work!

  9. I dont know where to put this but i got an error message that says Error 2 ‘VerySimpleGame.VerySimpleUI.Dispose(bool)’: no suitable method found to override C:\Users\Peter\Documents\DoFE\C#\VerySimpleGame\VerySimpleGame\VerySimpleUI.Designer.cs 14 33 VerySimpleGame

    1. This error usually happens if you rename a form – in this case, changing SuperAdventure.cs to VerySimpleUI.cs. In Visual Studio’s solution explorer, double-click on the “VerySimpleUI.Designer.cs” file and make sure the line near the top says “partial class VerySimpleUI”, and not “partial class SuperAdventure”. Also, make sure the code behind VerySimpleUI.cs has “public partial class VerySimpleUI : Form”, and not the SuperAdventure name.

      The *.Designer.cs file contains some of the methods the *.cs form class uses. That’s why they are both “partial” classes, since they each contain “part” of the logic needed by the whole class. And you need to be sure their class names match.

      Let me know if that isn’t the problem.

  10. thanks for the tutorial! I am new in this and i want to ask how to create a boss monster (i haven’t figure out how create a monster than only appear one time then disappear after you defeat it), raise the life when the player level up and add a item shop.

    1. Hi Rodrigo,

      I’m sorry it’s taken me so long to reply. I didn’t have Internet in my new apartment until last night.

      To have a boss monster that could only be fought once, I would do this:

      1. Add a “BossMonster” property to the Location class (with a datatype of Monster).
      2. Add a “KilledBossMonster” property to the Location class (with a datatype of boolean).
      3. In the SuperAdventure.cs “MoveTo()” function, before the section where you see if there is a monster at the location, add some code to see if there is a boss monster at that location that has not been killed. If so, set the boss monster as the _currentMonster and skip over the section of code that looks for another monster at that location.

      To raise the player’s health when they are a new level, I would create an “AddExperience(int experiencePoints)” function in the Player class. Whenever the player gains experience, use that function, instead of directly adding the experience to the player’s ExperiencePoints property. Then, inside that function, you would add the points to the player’s ExperiencePoints property and increase their MaximumHitPoints if they gained a level.

      For an item shop, I would add an inventory list to the Location class. It would work similar to the Player’s inventory list, but you’d need to add an extra button column to the inventory datagridviews to let the player buy or sell items.

      Let me know if you have any other questions. I should have some time this weekend to go into more details.

      1. Hi again, yeah xD

        if (newLocation.KilledBossMonster == false)
        newLocation.BossMonster = _currentMonster;

        _currentMonster = null;

        been trying to get the boss thingy working, but i just cant make anything work, sigh…. I’ve been also trying to make some monsters only happear if the player has the quest, but it always fails.

        1. I think you probably want something like this:

          if (newLocation.KilledBossMonster == false)
          _currentMonster = newLocation.BossMonster;
          _currentMonster = null;

          This way, if the BossMonster was not killed, you will set the currentMonster to the BossMonster. Otherwise (if the BossMonster was killed), there won’t be a monster to fight (_currentMonster = null).

          You could also write it in the reverse order. Sometimes that makes if/elses a little clearer.

          if(newLocation.KilledBossMonster) // This is the same as “newLocation.KilledBossMonster == true”
          _currentMonster = null;
          _currentMonster = newLocation.BossMonster;

  11. Great tutorial, i have been building up an great idea for an RPG for quiet some time, but was waiting to learn the basics of c# in school. I am really glad i found this, it will give me a huge boost in school, and for the game. But i will probably need to watch more tutorials since the game has some really complicated stuff, cause its gonna be a sort of RPG that i have never seen done before. will take me a long time to make thats for sure. Thanks! will start learning soon probably.

  12. Great tutorial! But.. I can’t get past step 2.. because I don’t have Visual Studio and it doesn’t run on Windows Vista. Any workarounds? I’m using SharpDevelop. Lots of problems trying to follow along, and I can’t get VS without getting a new computer, which isn’t happening for a LONG time.

    1. I couldn’t find a good solution. I’m going to keep looking and see if I can find anything, but it doesn’t look like the odds are very good. If anyone reads this and has an idea, please post a comment.

  13. Hey there Scott,

    i can’t figure out how to properly add the health scaling per level. I tried the “AddExperience(int experiencePoints)” function you mentioned in another comment but I can’t get any further.
    While im adding new Items, Monster, Location and Quests, i really need to be able to raise player health at some point.
    A source code for the health increase per lvl would be awesome if that’s not too much to ask :p

    I really enjoyed your tutorial and it tought me a lot so far.

    Thank you!

  14. Hi Scott,

    i’d like to show all the movement buttons at any given time but grey out those, that can’t be used for the current location. How do I do this? Would be cool if you could help me with some specific source code :p.


    Thank you!

    1. woops, never mind, just changed .Visble to .Enabled, didn’t think it would be that easy, sorry :p

      But another thing:

      I’m trying to get the UI resized when the user is changing the window size, can’t get it to work as I want it to D:

      thanks again!

      1. Hi Sarah,

        Good job on finding the property! If you’re going to work a lot with the UI, you should take a look at the other properties and events on the different UI controls. That will make you familiar with what you can do to them.

        To resize items, you’ll want to use the “Anchor” property. That will let you say something like (for example), “no matter how big the form is, I want this button to stay 10 pixels from the right edge and bottom edge”. You may run into a problem if you want controls to stay a certain size from the center of a form. Then you’d need to do something like put a splitter control on the form, and put the other controls (buttons, datagrids, etc.) inside the splitter panels.

        There is also the form’s OnResize event. You can hook an event handler to that event. Then, when the user changes the form’s size, you can have a function that will adjust the controls. However, that can get a little complex – especially if you have a lot of controls on the form.

  15. Have been away from from C# for  several years. I am a retired truck driver. I wrote a small simple wargame about 4 years ago, VS express has changed a lot and my mind is like a sieve. Am going to try to get my feet wet with VS 2015 using your tutorial.

    wish me well, Joe

  16. This is exactly what I needed before I step into unity.  This will give a great foundation I can use in the future.  Thanks

Leave a Reply

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