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 9219651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:09:51+00:00 2026-06-18T03:09:51+00:00

I´m making this game but I´ve run into a problem with the structures. I´ve

  • 0

I´m making this game but I´ve run into a problem with the structures. I´ve made a class called Structure and other classes like Traps, Shelter, Fireplace inherits from this class. The tiles in the game have their own class(Tile) and have a list of Structures on that tile. I can succesfully build structures on tiles which are included in the list. The problem comes when I try to acces the functions from classes like Traps etc. it won´t work. I can only use the functions from the base class Structure.

List in Tile:

class Tile
{
     public List<Structure> Structures = new List<Structure>();
}

How I build a Trap or other building:

        bool anyFireplace = Bundle.map.tile[Bundle.player.X, Bundle.player.Y].Structures.OfType<Shelter>().Any();
        if (!anyFireplace)
        {
            woodlogsCost = 4;
            if (Bundle.player.Woodlogs - woodlogsCost >= 0)
            {
                Bundle.map.tile[Bundle.player.X, Bundle.player.Y].Structures.Add(new Shelter(Bundle.player.X, Bundle.player.Y));
                Bundle.player.Woodlogs -= woodlogsCost;
            }
        }

When I draw the Structures (here is where my problem is, note the comments)

foreach (Structure s in Bundle.map.tile[x, y].Structures)
{
   if (s is Fireplace)
{
   //This is the function from base class Strucure
   s.ColorBody(g, 10, x - minx, y - miny, 0, Brushes.Firebrick);

   // The function that I wan´t to use but can´t be used
   //s.ColorBody(g, x - minx, y - miny); 
}
if (s is Shelter)
{
s.ColorBody(g, 10, x - minx, y - miny, 1, Brushes.ForestGreen);
}
if (s is Sleepingplace)
{
   s.ColorBody(g, 10, x - minx, y - miny, 2, Brushes.Brown);
}
if (s is Trap)
{
   s.ColorBody(g, 10, x - minx, y - miny, 3, Brushes.Silver);
}
if (s is Barricade)
{
   s.ColorBody(g, 10, x - minx, y - miny, 4, Brushes.DarkOliveGreen);
}
}

Soo… I wonder how do I access the functions I wan´t to use?

  • 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-18T03:09:52+00:00Added an answer on June 18, 2026 at 3:09 am

    To the computer, s is only a Structure. If you want to call a specific method that only the Fireplace class has but the abstract class Structure does not have (e.g. Fireplace class might have a BurnWood() method that wouldn’t make sense for a Structure to have), then you want to let the computer know that this Structure is actually also a Fireplace (for example). So you could do this by casting; for example:

    ((Fireplace)s).ColorBody(g, x - minx, y - miny); 
    

    or

    (s as Fireplace).ColorBody(g, x - minx, y - miny); 
    

    See this post on the difference between casting and using the as operator.

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

Sidebar

Related Questions

I've run into an odd problem in a pong/brick-breaker game I'm making: one of
my problem is: I'm making a game for iOS using cocos2d and this game
I am making a game using LibGdx framwork.This is working fine for dekstop but
I'm making a game for iOS using XCode however I have run into one
I made a sweet system update feature for this game I'm making here is
I'm making a multiplayer iOS game and have run into the following issue: i
I am making a game but whenever i run the second jFrame I have
I'm making this game where I'm trying to pair people. So I have this
I am making a pokemon game and this section is giving me 3 errors:
Hopefully this is a quick question. I'm making a simple rock paper scissors game.

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.