Press "Enter" to skip to content

Learn C# by Building a Simple RPG

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.

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.


NOTE: If you already know the basics of C# programming (classes, properties, functions, “if” statements, etc.), you might want to look at the newer “Build a C#/WPF RPG” lessons. The code in those lessons is more like how I would write a “real” professional program – using better design and architecture.



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 Community Edition

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

Improving SuperAdventure’s code quality by refactoring

Lesson 20.1 – Refactoring the SuperAdventure program

Lesson 20.2 – Binding a custom object’s properties to UI controls

Lesson 20.3 – Binding list properties to datagridviews

Lesson 20.4 – Binding child list properties to a combobox

Lesson 20.5 – Moving the game logic functions from the UI project to the Engine project

Adding a vendor to locations (with buying and selling items)

Lesson 21.0 – Plans for adding a vendor to locations

Lesson 21.1 – Adding a price to game items

Lesson 21.2 – Create the vendor class and add it to locations

Lesson 21.3 – Add a button and create its eventhandler in code, without the UI design screen

Lesson 21.4 – Completing the trading screen

Use SQL to save and restore player’s game data

Lesson 22.1 – Installing MS SQL Server on your computer

Lesson 22.2 – Creating database tables from classes

Lesson 22.3 – Creating the SQL to save and load the saved game data

Creating a console UI for SuperAdventure

Lesson 23.1 – Creating a console front-end for the game

Final refactoring (cleanup) of the SuperAdventure source code

Lesson 24.1 – Make the SuperAdventure source code easier to understand and modify

New game features

Lesson 25.1 – Select a random monster at a location

Lesson 26.1 Displaying a World Map

Lesson 26.2 – Hiding Unvisited Locations on the World Map


Bug Fixes

Lesson 99.1 – Preventing duplicate quests

Lesson 99.2 – Setting CurrentWeapon when the player has multiple weapons


Share your personal, expanded versions of SuperAdventure here!


  1. kobrad
    kobrad November 27, 2013

    This seems like a really good tutorial – thank you for your work

    • Scott Lilly
      Scott Lilly December 2, 2013

      Thanks. I’ve been working on the next sections. They’ll be up soon.

  2. Jase
    Jase June 5, 2014

    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.

    • Scott Lilly
      Scott Lilly June 5, 2014

      Thank you.

      I just published Lesson 13.2 – Creating functions to handle user input. I’m working on Lesson 14, and it’s a big one. It covers the almost all of the game logic – moving around, completing quests, fighting monsters, etc. So, it will probably be split into 3 or 4 smaller lessons.

  3. Jase
    Jase June 6, 2014

    Sounds great. I’ll keep looking for it. 🙂 Thank you again for your work.

    • Scott Lilly
      Scott Lilly June 16, 2014

      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.

  4. Jase
    Jase June 22, 2014

    Yes, thank you!! I’ll get to work on it here early next week. Today is too busy. 🙁

  5. Luke
    Luke August 15, 2014

    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.

    • Scott Lilly
      Scott Lilly August 15, 2014

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

  6. Zerocchi
    Zerocchi August 26, 2014

    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 🙂

    • Scott Lilly
      Scott Lilly August 26, 2014

      You’re welcome. Please let me know if you have any questions.

  7. TheCaptain
    TheCaptain August 26, 2014

    This tutorial was great, thank you very much for the write up!

    • Scott Lilly
      Scott Lilly August 27, 2014

      You’re welcome. I’m glad it helped you.

  8. Rusty
    Rusty August 27, 2014

    Really helpful and fun way to explore C#

    • Rusty
      Rusty August 27, 2014

      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.

      • Scott Lilly
        Scott Lilly August 27, 2014

        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.

        • Rusty
          Rusty September 1, 2014

          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.

          • Scott Lilly
            Scott Lilly September 1, 2014

            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.

  9. Mark
    Mark September 23, 2014

    Brilliant tutorials really helping me in 2nd year CS.

  10. Nate
    Nate October 24, 2014

    Thank you for this great tutorial! Although i’m new to coding, It helps me understand more about C#. Cheers.

  11. Caynne
    Caynne December 21, 2014

    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.

  12. Levi Roe
    Levi Roe January 28, 2015

    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?

    • Scott Lilly
      Scott Lilly January 29, 2015

      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.

  13. Keszthelyi Máté
    Keszthelyi Máté February 2, 2015


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

    • Scott Lilly
      Scott Lilly February 3, 2015

      Great! I did not receive your e-mail, but it’s good to hear that you were able to make your own version of the program, with graphics and more features.

      • Keszthelyi Máté
        Keszthelyi Máté February 2, 2016


        Did you get my e-mail? I know i’m a bit unpatient, but because last time you didn’t i ask to be sure. 🙂 Used the ,,contact me” down there.

        • Scott Lilly
          Scott Lilly February 2, 2016

          I did not receive an e-mail from you. I sent an e-mail to the address you used for this comment. Can you reply to that?

  14. Woobster
    Woobster February 7, 2015

    Awesome tutorial.
    It really helped me get started with programing.
    Thanks Scott

  15. Tom Wheeler
    Tom Wheeler February 25, 2015

    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.


    • Scott Lilly
      Scott Lilly February 26, 2015

      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.

  16. Reuben Alexander
    Reuben Alexander February 26, 2015

    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!

  17. Peter
    Peter May 21, 2015

    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

    • Scott Lilly
      Scott Lilly May 21, 2015

      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.

      • Peter
        Peter May 22, 2015

        yeah that fixed it

  18. Rodrigo
    Rodrigo June 11, 2015

    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.

    • Scott Lilly
      Scott Lilly June 18, 2015

      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.

      • EvossaN
        EvossaN August 19, 2015

        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.

        • Scott Lilly
          Scott Lilly August 19, 2015

          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;

  19. Danny
    Danny July 26, 2015

    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.

    • Scott Lilly
      Scott Lilly July 27, 2015

      Thanks. One of the coolest things about programming is that you have the ability to create your own world, and all the rules in it. Good luck on your game!

  20. Collin
    Collin August 8, 2015

    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.

    • Scott Lilly
      Scott Lilly August 8, 2015

      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.

    • JJmiagi
      JJmiagi September 7, 2016

      try xamarin they have an IDE that works on all platforms

Leave a Reply

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