Lesson 06.1 – Creating the remaining classes

Lesson Objectives

At the end of this lesson, you will know…

  • Nothing new. However, you do need to create the rest of the classes, so you can eventually play the game.

 

Time to add more classes

Now we can create the rest of the classes you’ll use in the game.

By the way, some programmers would call these classes the “business classes”, or “business objects”. Even though this is a game, and not a business application, that’s a term you might hear.

 

Step 1: Start Visual Studio Express 2013 for Desktop, and open the solution.

Step 2: Right-click on the “Engine” project, in Solution Explorer, then select “Add”, and then “Class”.

Enter the name of the class you want to create, and add the properties in the class – just like you did with the Player class.

Instead of manually typing in all the classes and properties from this page, get the source code for the classes from the link at the end of this lesson. That way, you’ll be sure to have the spelling and casing correct. That will be important when we start using the classes.

It may not be obvious what all the properties will be used for, but we’ll get to that in a later lesson.

When you’re done

Make sure that your Engine project has all of these classes, and that you didn’t miss any.

  • HealingPotion
  • Item
  • Location
  • Monster
  • Player (already created in a previous lesson)
  • Quest
  • Weapon

 

Summary

There wasn’t really anything new in this lesson. We just need to add these classes to make the game actually do something.

 

Source code for this lesson

Get it from GitHub: https://gist.github.com/ScottLilly/ade88e1a92a2ff8799f0

or DropBox: Lesson 06.1 – https://www.dropbox.com/sh/qmx40r21zvi3o25/AACW0_t731T5LijiWpz7gx3da?dl=0

 

Next Lesson: Lesson 07.1 – Inheritance and base classes

Previous lesson:  Lesson 05.1 – Creating objects from classes

All lessons: Learn C# by Building a Simple RPG Index

 

11 thoughts on “Lesson 06.1 – Creating the remaining classes

  1. Is it possible to provide a list of the properties of the 7 new classes as part of the tutorial? Some of us accessing this great tutorial in totalitarian states do not have the luxury of downloading files from github 🙁 Thanks a bunch!

    1. Hello Ken,

      Here’s a DropBox location with the files: DropBox – Lesson 06.1

      I’m going to see if I can either install a Git repository on this site, or find second place to put the files on GitHub. Some of the files get much bigger, so adding them all inside the lesson might not work well. I might not be able to copy everything over to a new location until this weekend, but I will let you know when thethey are ready.

      Please let me know if you cannot access DropBox, or if you know a better file-sharing location you can access.

    2. All the lessons that have code on GitHub should now have links to the same files on DropBox. Please let me know if there is any problem with those files, or with accessing them. Thanks!

  2. Hi! Sorry i was just going to ask in case i’ve missed something but where we supposed to come up with these ourselves or copy your code? Thanks! The tutorial has been great!

    1. Hi Will. You can get the source code for these classes from the GitHub or Dropbox links at the bottom of the lesson (or, just use them from here: classes on GitHub or classes on Dropbox). Create each class by right-clicking on the project name, then “Add”, then “Class”. Then copy/paste the code for the class from GitHub. I just did things that way to keep this page a little cleaner, and not have it full of code.

      1. In a future lesson, we are going to create a “World” class, that will hold collections of all the items, monsters, quests, and locations. We need a way to find the exact item/monster/quest/location in those collections, and an ID is the best way to do that. We wouldn’t want to use the name, because you might change the name (for example, if you were writing the game for a different language – like Spanish).

Leave a Reply

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