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.

 

SECTIONS

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

{ 19 comments… read them below or add one }

kobrad

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

Reply

Scott Lilly Scott Lilly

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

Reply

Jase

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.

Reply

Scott Lilly Scott Lilly

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.

Reply

Jase

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

Reply

Scott Lilly Scott Lilly

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.

Reply

Jase

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

Reply

Luke

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.

Reply

Scott Lilly Scott Lilly

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.

Reply

Zerocchi

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

Reply

Scott Lilly Scott Lilly

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

Reply

TheCaptain

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

Reply

Scott Lilly Scott Lilly

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

Reply

Rusty

Really helpful and fun way to explore C#

Reply

Rusty

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.

Reply

Scott Lilly Scott Lilly

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.

Reply

Rusty

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.

Reply

Scott Lilly Scott Lilly

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.

Scott Lilly Scott Lilly

Thanks!

Reply

Leave a Comment