Press "Enter" to skip to content

Lesson 21.0 – Plans for adding a vendor to locations

Many people have asked about adding a vendor to the game. So, that’s what we will do in the next few lessons.

The first thing to do, when making any big change to a program, is to create a plan. A good plan will let you make your change faster. It will also prevent you from finishing half your changes, and realizing you need to delete all those changes and try a different method.

So, let’s figure out what we need to do.


Features for adding a vendor

Here are the changes we need to make.

  1. Add a price to items
  2. Create a new Vendor class. This class will have properties for the vendor’s name and their inventory.
  3. Change the Location class, to hold an (optional) Vendor at that location
  4. Change the UI to let the player buy and sell items with the vendor


Plan how to implement the changes

The first three changes don’t require any new skills. We’ve already created classes and added properties. So those should be simple to add.

The fourth change (the UI to buy and sell) could be done a few different ways.

The way I’m going to do it is with a new UI form. When the player moves to a location with a vendor, we will display a button to “open the store”. This will open a new form, which will show a list of the player’s inventory and the vendor’s inventory. The inventory lists will have buttons, to “buy” (from the vendor) or “sell” (to the vendor).

We could keep this all on the SuperAdventure.cs UI form, by making it bigger. But, because we’ll use a new form, you’ll see how to pass objects between forms – which is a useful thing to learn.


Source code for this lesson

There is no source code for this lesson


Next lesson: Lesson 21.1 – Adding a price to game items

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

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


  1. Pezem
    Pezem January 24, 2016

    The next lesson displays wrong text.

Leave a Reply

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