Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:43:57+00:00 2026-06-05T07:43:57+00:00

Before I get to my question, here is a sample of the structure of

  • 0

Before I get to my question, here is a sample of the structure of my code:

abstract class Entity
{
    #region Declarations
    public string Name;
    public string Description;
    #endregion

    #region Constructor
    public Entity(string Name, string Description)
    {
        this.Name = Name;
        this.Description = Description;
    }
    #endregion
}

abstract class Item : Entity
{
    #region Declarations
    public bool SingleUse;
    #endregion

    #region Constructor
    public Item(string Name, string Description, bool SingleUse = false)
        :base(Name, Description)
    {
        this.SingleUse = SingleUse;
    }
    #endregion

    #region Public Methods
    public void NoUse()
    {
        Program.SetError("There is a time and place for everything, but this is not the place to use that!");
    }
    #endregion
}

class BrassKey : Item
{
    public BrassKey(string Name, string Description, bool SingleUse = false)
        :base(Name, Description, SingleUse)
    {
    }

    public void Use()
    {
        if (Player.Location == 2)
        {
            Program.SetNotification("The key opened the lock!");
            World.Map[2].Exits.Add(3);
        }
        else
        {
            NoUse();
            return;
        }
    }
}

class ShinyStone : Item
{
    public ShinyStone(string Name, string Description, bool SingleUse = false)
        : base(Name, Description, SingleUse)
    {
    }

    public void Use()
    {
        if (Player.Location == 4)
        {
            Player.Health += Math.Min(Player.MaxHealth / 10, Player.MaxHealth - Player.Health);
            Program.SetNotification("The magical stone restored your health by 10%!");
        }
        else
        {
            Program.SetNotification("The shiny orb glowed shiny colors!");
        }
    }
}

class Rock : Item
{
    public Rock(string Name, string Description, bool SingleUse = false)
        : base(Name, Description, SingleUse)
    {
    }

    public void Use()
    {
        Program.SetNotification("You threw the rock at a wall. Nothing happened.");
    }
}

I then construct a list of Item objects in my World class. Each object in the list is of the type of item it is.

public static List<Item> Items = new List<Item>();

private static void GenerateItems()
{
    Items.Add(new BrassKey(
        "Brass Key",
        "Just your generic key thats in almost every game.",
        true));

    Items.Add(new ShinyStone(
        "Shiny Stone",
        "Its a stone, and its shiny, what more could you ask for?"));

    Items.Add(new Rock(
        "Rock",
        "It doesn't do anything, however, it is said that the mystical game designer used this for testing."));
}

How could I then call the use method of each specific item class like this:

World.Items[itemId].Use();

If there is something you don’t understand about my issue, please don’t hesitate to ask me!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:43:58+00:00Added an answer on June 5, 2026 at 7:43 am

    Define the Use Method in your ItemClass and mark it virtual. Then in your subclasses mark the method as override and you should be able to do what you want

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I get to my question/problem, here is the basic structure of my application:
I have asked this before but I didn't get the question right so the
Before you all get pissy about me posting this question again, let me explain
This question has been asked before perhaps multiple times, but I can't get the
I'm writing a class to insert users into a database, and before I get
I'm probably going to get abuse for this question but here goes. Oh but
It looks like this question has been asked before, here and in other places
The question I am going to ask here has already been asked before in
Before I get anywhere with this post, let me make this clear, there is
Ok, before I get a ton of responses. I know you cannot talk to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.