Press "Enter" to skip to content

Lesson 18.1 – Future enhancements for the game

Congratulations!

You finished with the lessons, and have a working game!

Plus, you’ve learned many of the most common things you need to write more C# programs.

There is still plenty more to learn, if you decide to get serious about programming. I’ve been programming for over 30 years, and learn something new every week.

 

Expanding the game

The easiest thing for you to do is to make a bigger world, with more locations, quests, monsters, and items.

Draw a map of your larger world, and modify the World class to include these new locations. Create more monsters and quests. Add more powerful weapons, so the player can defeat the giant spider.

 

Ideas for new features

This is a very simple RPG, and there is a lot you can do to expand it.

Here are a few ideas:

  • Save the player’s current game to disk, and re-load it later
  • As the player gains experience, increase their level
    • Increase MaximumHitPoints with each new level
    • Add a minimum level requirement for some items
    • Add a minimum level requirement for some locations
  • Add randomization to battles
    • Determine if the player hits the monster
    • Determine if the monster hits the player
  • Add player attributes (strength, dexterity, etc.)
    • Use attributes in battle: who attacks first, amount of damage, etc.
  • Add armor and jewelry
    • Makes it more difficult for the monster to hit the player
    • Has special benefits: increased chance to hit, increased damage, etc.
  • Add crafting skills the player can acquire
  • Add crafting recipes the player use
    • Require the appropriate skill
    • Requires components (inventory items)
  • Make some quests repeatable
  • Make quest chains (player must complete “Quest A” before they can receive “Quest B”)
  • Add magic scrolls
  • Add spells
    • Level requirements for the spells
    • Spells require components to cast (maybe?)
  • Add more potions
    • More powerful healing potions
    • Potions to improve player’s “to hit” chances, or damage
  • Add poisons to use in battle
  • Add pets
    • Help the player in battle by attacking opponents
    • Help the player in battle by healing the player
  • Add stores/vendors
    • Player can sell useless items and buy new equipment, scrolls, potions, poisons, and crafting/spell components

 

There are also more programming techniques you can learn to make the program a little cleaner.

  • LINQ, when searching lists
  • Events/delegates, to handle communication between the “logic” project and the UI project – which will let you move more logic code out of the UI project
  • BindingList, so you don’t have to repeatedly repopulate the DataGridViews and ComboBox in the UI

 

Version control

If you’re going to make more changes, or write more programs, you really should learn how to use a version control tool.

You can create a backup copy of your program by copying the solution folder to a new location before making your change. But version control software is a better solution.

It will let you keep track of all the changes you ever make to your program. This is extremely helpful when you make some changes that don’t work, and want to go back to the old, working version.

I use TortoiseSVN (Subversion) and VisualSVN (a Visual Studio plug-in that works with TortoiseSVN).

Git is another popular version control tool. Many programmers use a web-based version of it at GitHub.

Version control tools usually take a little while to set up, and to figure out how to use. But once you have one in place, and you learn the basics, using it will become a habit that doesn’t require any time or thought. And the first time you need to go back to a previous version, you’ll thank yourself that you used version control.

 

Summary

Now that you have the basic game, you can expand it.

Hopefully you enjoyed these lessons, and learned some new things.

Please let me know if you have any questions about anything that wasn’t clear in the lessons, if you want to see some other features in the game, or if you want to learn some other aspects of programming in C#.

 

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

Previous lesson: Lesson 17.1 – Running the game on another computer

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

88 Comments

  1. Chris
    Chris October 21, 2014

    I read this whole series and it was perfect. I’m already versed in programming but trying to come up with the logic for some of this is difficult since I’m not very familiar with C#, but you helped explain it wonderfully. Thanks for the awesome tutorial.

  2. Morgan Jones
    Morgan Jones November 4, 2014

    This tutorial taught me more than my beginning c# college class, and I paid good money for that. Thanks a bunch, I’m excited to start building more on this and making it my own.

    • Scott Lilly
      Scott Lilly November 5, 2014

      You’re welcome. If you build something cool, please let me know!

  3. Nicholas
    Nicholas November 10, 2014

    I’ve never seen a better programming tutorial for beginners. It wasn’t long so it held my attention and finally I’ve created something that can be called a simple game. Thank you a lot.

    • Scott Lilly
      Scott Lilly November 13, 2014

      You’re welcome. Hopefully, this will get you started on creating your own programs, from your own ideas.

  4. Westin Minson
    Westin Minson January 14, 2015

    Hey Figured out my problem and I can say I really like this tutorial !!!!

  5. Andreas Walker
    Andreas Walker March 15, 2015

    First of all, amazing tutorial. Small question, I may just need to give it a second look, but in which tutorial would I find a leveling system

    • Scott Lilly
      Scott Lilly March 15, 2015

      Thanks.

      In these lessons, we only do a simple calculation to determine the player’s level – divide experience points by 100 and add 1. You can see that calculation in the Level property, in the Player class. If you want each level to require a different amount of experience points, you could use the technique I show here: How to create a SortedList in C# with the ability to find floor and ceiling values.

      If that isn’t what you’re looking for, please let me know and give me some more details of what you want to accomplish.

  6. Drew
    Drew March 30, 2015

    Im not sure if you still read these, but I had a question. Lets say I wanted to start with a character creation screen where you put in name, gender, race, etc.. Then I store that information in a character object. How would I then pass that object onto the main game form? I am racking my brain trying to figure this out. Any insight?

    • Scott Lilly
      Scott Lilly March 31, 2015

      Hi Drew,

      When the player is finished creating their character, and ready to start the game, I’m guessing that you have a button they click (or something similar). In the event handler function for that button click, I assume you have code like this:

      private void btnStartGame_Click(object sender, EventArgs e)
      {
      SuperAdventure game = new SuperAdventure();
      game.Show();
      this.Hide();
      }

      If you want to pass a Character object from the character creation form to the SuperAdventure form, you’d need to change the constructor of the SuperAdventure form to accept a Character object parameter. Then, in your btnStartGame_Click() function, create the Character object from the user input and pass it when you instantiate the SuperAdventure object. So, it might be something like this:

      private void btnStartGame_Click(object sender, EventArgs e)
      {
      Character player = new Character();
      player.Name = txtName.Text;
      player.Gender = txtGender.Text;

      SuperAdventure game = new SuperAdventure(player); // Notice that the player object is being passed to the SuperAdventure form
      game.Show();
      this.Hide();
      }

      Your constructor code in SuperAdventure would change from this:

      public SuperAdventure()

      to this:

      public SuperAdventure(Character character)

      Then, you could use the “character” object in the SuperAdventure form. There are other ways to do this, but I think this is one of the better ways.

      Please let me know if that helped.

  7. Tiago Riscado
    Tiago Riscado April 22, 2015

    Hi,I’m having some trouble in creating a NPC that will handle selling the Players Items and selling Items for the Player,I have already created a NPC class in Engine.
    In the World.cs class I have created a new Location to hold this NPC,it’s West of the farmer field.
    I know what I have to do but dont know how to put it into code.
    Need some Insight.

    Regards Tiago Riscado

    • Scott Lilly
      Scott Lilly April 22, 2015

      Wow! That’s a big enhancement.

      The way I would probably do it is to add another DataGridView to the SuperAdventure.cs form.

      When a player moves to a location, if there is an NPC at the location, the DataGridView is populated with the NPC’s inventory and the DataGridView’s “Visible” property gets set to “true” (if there is no NPC at the location, “Visible” is set to “false”). One of the columns in that DataGridView would be a DataGridViewButtonColumn. When the user clicks on that button, the player “buys” that item (subtracting it from the NPC inventory, adding it to the player inventory, and decreasing the player’s gold quantity). You could also add a DataGridViewButtonColumn to the player’s inventory when there is an NPC at the location, that lets them sell that item from their inventory.

      Let me know if that makes sense to you, or if you need some more details.

  8. Nicolas
    Nicolas May 21, 2015

    Hi there,

    I’m having different problem unfortunately..
    the first is that visual tells me that the static class “World” Can’t have a constructor because it is static.
    The second one is that I’m having a lot of accessibilites issues. I have put public everywhere but it doesn’t look like the reference is working.. What should I do ?

    Thanks by advance,
    Nicolas

    • Scott Lilly
      Scott Lilly May 21, 2015

      In the World class, the first function should only say “static World()”. It sounds like you may have “public static World()” in there right now. That function really isn’t a constructor, it’s only something that is run the first time the static class is used.

      The most common reason I’ve seen when people have lots of accessibility issues is if they renamed the “Engine” project. That causes a lot of namespace issues. Did you ever rename the Engine project? You can also look at the project source code on GitHub at https://github.com/ScottLilly/SuperAdventure (although the source code there also includes the changes in the enhancement lessons).

      If you can’t fix the problem that way, can you upload your solution to GitHub (or some other place) and let me know the URL? That will make it easier to track down the problem.

  9. Athyx
    Athyx June 28, 2015

    Thank you very much for this tutorial! I had a blast following along and adding my own stuff to the game as I went along! I was wondering if you might ever add a map-like system to this?

    • Scott Lilly
      Scott Lilly June 29, 2015

      Thanks. The new version I’m working on will have some simple graphics to represent the map.

  10. Athyx
    Athyx June 28, 2015

    I was wondering how I might be able to pass the player name into the World.cs? I added a string FinishDescription to the Quest.cs properties so when you turn the quests in, the characters that I made up that give the quests, have something to say in return. I would like them to be able to say “Thank you, ” + _player.Name. + “!”

    public Quest(int id, string name, string description, string finishDescription, int rewardExperiencePoints, int rewardGold)
    // QUEST: "Clear the Alchemist's Garden"
                Quest clearAlchemistGarden =
                    new Quest(
                        QUEST_ID_CLEAR_ALCHEMIST_GARDEN,
                        "Clear the Alchemist's Garden",
                        "The alchemist, Rashik has asked you to help him Kill rats in his garden and bring back 5 Rat tails for his next batch of potions. " +
                        "He mentions that his garden is just North of his hut, and he is willing to give you a Healing Potion and 10 Gold. for your help.",
                        "Rashik approaches you with such excitement! 'Thank you very much, young hero! Here are the items that I promised you.'", 20, 10);

     

     

    • Scott Lilly
      Scott Lilly June 29, 2015

      One way to do it is to have your FinishDescription include a value you’ll replace when you display the message, like this:

      "Thank you very much {NAME}!"

      Then, when you display the FinishDescription, instead of using:

      quest.FinishDescription

      use:

      quest.FinishDescription.Replace("{NAME}", _player.Name)

      That will replace the {NAME} part of the description with the player’s name, before displaying the message. If you wanted, you could make it more complex by “method chaining”, and have something like this:

      "Thank you very much {TITLE} {NAME} of {HOMEVILLAGE}!"

      and:

      quest.FinishDescription.Replace("{TITLE}", _player.Title).Replace("{NAME}", _player.Name).Replace("{HOMEVILLAGE}", _player.HomeVillage)

      You don’t have to use curly-braces, or upper-case letters for this. You just need something that you know won’t appear as a normal word in the rest of the message, since Replace() will replace all occurrences of the string.

  11. Athyx
    Athyx June 30, 2015

    Great! Thank you very much, Mr. Lilly!

  12. Brett
    Brett July 1, 2015

    Scott,

    What a wonderful series of lessons you have here. I’ve just finished the final lesson. I’m not a beginner in C# but, certainly in the concepts of game design and programming. Your ability to teach in an easy to understand manner is quite simply, awesome. Thanks for a great tutorial.

    Kind regards,

    Brett

  13. Kevin
    Kevin August 3, 2015

    Hi Scott!

    I just wanted to thank you for all the great work you’ve made with these tutorials. Even if I am not new to programming, I’ve learned lots of useful things related to C# and game concepts. You explain things very clearly and simply.

    At this point, I’ve followed the whole series, and made a few modifications : full localization of the application, a menu which allows to reset, save, and open previously saved games, moved inventory and quests dgv to a tab control to recover a bit of space in the form and a bank system where player can save his gold and retrieve it only when in a bank. Thanks again!

     

    • Scott Lilly
      Scott Lilly August 3, 2015

      Thank you, Kevin. It’s great to hear that you’ve expanded on the game!

  14. Callum
    Callum September 16, 2015

    Awesome tutorial gone from start to finish, great way to start as a beginner and create a project that you know your way around and can expand on with more features at your own behest.

    Exactly what I was looking for unlike the tutorials on things like pluralsight were they just have you create blocks of disposable code and you never get to see how it all goes together.

  15. David
    David April 8, 2016

    Hi Scott!

    I have a question: Is there any way to make these windows form applications somehow online? I would like to create for example a basic tennis-like game in visual studio with c#. It would be very simple: on a black background there would be white objects: 2 player objects (one is left one is right side of the screen) and a ball object starting from the middle. If the ball touches the left side of the screen, then played 1 loose, when it touches the right then player 2 loose. Very simple.

    My question is that is there some way to make it possible to put it online and try it to play with my friends? I’m just curious how to make 2player or multiplayer online games. I like to work with visual studio, especially after your tutorial! At the end I would like to make a card game, where should I start? (my dream would be to create a trading card game online). I have been searching on the internet but I cant find anything to start with, maybe you could help me!

    Kind regards,
    David

    • Scott Lilly
      Scott Lilly April 8, 2016

      Hi David,

      If you continue up to Lesson 23.1 – Creating a console front-end for the game, you’ll see how to use the Engine project with a different front-end – although the front-end I add is a command line interface, not the web. But, if you understand the principles, you should be able to quickly create a web front-end project. This would allow you to play the game online. If you modified the database lessons, by adding player name/ID to the tables (and changing the SQL queries to only use the data for the player), you could even to allow different people to play – by themselves.

      However, allowing two or more people play the game at the same time, and interacting with each other (like they would need to do in your tennis game idea) is probably ten times more difficult than the existing game. You need to write code to handle communications, and all the possible communications problems. What if one player loses their Internet connection, what if the players have different speed Internet connections, are you certain the second player received the first player’s actions, what if one player tries to hack the game, etc.? There is a lot of work involved to create that type of game.

      I might do a tutorial in the future, to show how to do a simple game. But I want to finish the WPF class I’m working on first. That should be done around June, or July.

  16. Brenda Schmidt
    Brenda Schmidt April 11, 2016

    I just finished the basic tutorial this morning.  Thank you so much for this tutorial.  I just started to learn to code about three weeks ago.  Dementia runs in my family and I’m trying to keep my mind active as I go into middle age.  I’ve never done anything like coding before in my life.  This tutorial was fantastic for cementing some of the concepts I’ve been learning in other tutorials.  I didn’t copy and paste anything as I went along.  I feel that I learned more from typing in every line of code.  I knew I was taking a risk, but I have a perfectly functioning game and I know the code well.  My husband and I had a blast yesterday modifying some of it.  Again, thank you so much.

    • Scott Lilly
      Scott Lilly April 11, 2016

      Hi Brenda,

      You’re welcome! I’m happy to hear that you and your husband are enjoying the game, and making your own version of it. One of my favorite things about programming is that it is both creative and analytical. It’s a great way to exercise all of your brain. 🙂

  17. J
    J May 13, 2016

    Hi Scott,

    I’m in the process of adding my own code to the game, and currently among others I have added a method to the UI to automatically select the strongest weapon I have looted or gotten as a reward. Below is my code for doing this. First I created this method:

    private object selectStrongestWeapon(List<Weapon> weapons)
    {
    Weapon weaponWithHighestDamage = null;

    foreach (Weapon weapon in weapons)
    {
    if (weaponWithHighestDamage == null)
    {
    weaponWithHighestDamage = weapon;
    }
    else
    {
    if (weapon.MaximumDamage > weaponWithHighestDamage.MaximumDamage)
    {
    weaponWithHighestDamage = weapon;
    }
    }
    }

    return weaponWithHighestDamage;
    }

    And then I call it from the UpdateWeaponListInUI() which you provided, the last line being:

    cboWeapons.SelectedItem = selectStrongestWeapon(weapons);

    Do you think this is a good way to achieve this, and if not, what can I do to improve this?

    Thanks again for all your help. It is much appreciated.

    Kind regards,

    J

    • Scott Lilly
      Scott Lilly May 13, 2016

      I would look at using LINQ, to make that function smaller. To point you in the right direction, LINQ has a Max function you can use, to find the highest amount of damage of all weapons in the list. Then, you could find the first weapon that does that much damage (in case two or more weapons do the max damage). Let me know if you try that and have any problems.

  18. J
    J May 13, 2016

    Also I have changed some properties to be generic lists as wel rather than just of a single type so I can have multiple rewards, addes a RewardItems class which is basically a reference to a reward and a quantity integer (like your examples)… added an area with a quest and rewards and going to try and expand some more as this is IMO the best way to practice rather than just copying stuff. 🙂

    • Scott Lilly
      Scott Lilly May 13, 2016

      Cool! I’m always excited to see what changes people make to the game. It’s a small game, but there is a lot you can add to it.

  19. Inksaver
    Inksaver July 1, 2016

    Hi Scott

    Thanks for this excellent tutorial.

    I run computer clubs in a number of schools, and the pupils seem to really take to C#, even at primary level. I was looking for a text adventure using a GUI, and this fits the bill perfectly.

    It also runs in the SharpDevelop IDE, which in turn can be launched from a USB drive, to overcome the fact that most schools do not have Visual Studio. I may have to simplify it (e.g. no inheritance) but the principles are all there.

    • Scott Lilly
      Scott Lilly July 2, 2016

      You’re welcome. It’s cool that you run computer clubs. I’d like to find something similar near me.

      If you simplify some of these lessons, you might also consider doing the refactoring lessons in smaller steps, and closer to the lesson where the original code was written – instead of having all the changes in a massive “cleanup” lesson. That’s one thing I wish I did with this course.

  20. Lukasz
    Lukasz January 9, 2017

    Hi Scott,
    Could you tell me how to change color of a string property?
    I’d like to make quests’ names appear in color.
    Thanks

Leave a Reply to Inksaver Cancel reply

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