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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:56:47+00:00 2026-05-25T18:56:47+00:00

First, let me apologize for asking a question that may seem a bit vague

  • 0

First, let me apologize for asking a question that may seem a bit vague (or badly formalized), but I lack experience to ask anything more specific.

I’m building an engine for playing 2D adventure games (the you-click-on-an-object-and-something-happens sort) in C# and I’m considering the best structure for it. As you can imagine, different things can happen when you interact with an object: if it’s a door, you expect to enter another room, if it’s a person, you expect to start talking to them, etc. My idea is to achieve this behaviour with delegates, like this:

public abstract class GameObject {
    public delegate void onAction();
    public onAction Click;
}

public class Door : GameObject {
    public Door() {
        Click = new onAction(ChangeRoom);
    }
    private void ChangeRoom() {
        //code to change room here
    }
}

public class Person : GameObject {
    public Person() {
        Click = new onAction(StartTalking);
    }
    private void StartTalking() {
        //code to display dialogue here
    }
}

I find this solution quite elegant, because if I want to create a special object with some behaviour not covered by its class, I can simply do this:

specialObject.Click += new onAction(SpecialMethod);

But this is also where things get complicated. I want my engine to be capable of playing different games simply by loading different data, without changes to the engine itself, so hard-coding the SpecialMethod somewhere inside the engine is not an option, it must be part of the data. For normal object, it can all be done with (de)serialization, but from what I’ve read, this is problematic with delegates. Can you suggest a way to do it?

P.S.: Since I’m still on the concept level and the code above is not yet implemented, you are free to suggest whatever solution you find best, even one that avoids delegates completely.

  • 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-05-25T18:56:47+00:00Added an answer on May 25, 2026 at 6:56 pm

    First of all writing engine when you lack experience may be harder then you think. I’ll suggest that you write you first game without engine and hardcode as much as you want and then learn from the experience and write your engine… I know that’s not what you want 😀

    If you haven’t checked yet look at http://www.adventuregamestudio.co.uk/ play with the editor and think of the object model underneath. It will help.

    Since you want your games to be data driven you have to be able dynamically load and execute code. “It doesn’t have to be a scripting language.” It’s against my nature to suggest adding scripting language and learning it at the same time when you learn how to build an engine. .NET Framework has a great reflection system that allows you to load C# code and compile it at runtime. I have to point out that this is kind of scripting in C# but there is a lack of proper definition of scripting language.

    Since you don’t have a lot of experience in this my suggestion would be to use XML files that define your rooms and have a basic sequence of nodes (commands) that define what should happened when you click something. You should implement all the commands in your “engine” but you would be able to easily create new rooms therefore similar games. XML will be also very expandable approach since because of it’s hierarchical structure it will allow you to add conditions, loops, etc. that will expand your engine’s “scripting” capabilities.

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

Sidebar

Related Questions

First let me say that I really feel directionless on this question. I am
First off, let me apologize if this has been asked already, but I can’t
Let me first apologize if this question could sound perhaps sort of amateurish for
First of all, let me apologize if this question is too broad. I'm looking
First let me apologize a bit for the length of this post, it's mostly
Let me first apologize. I've been coding for a long time now, but I'm
First of all, I apologize for yet another interface question. I thought that this
Ok. First let me apologize profusely if this question has been covered. I did
First off, let me apologize in advance for the extremely long question -- kudos
I couldn't think of a decent title, so let me first apologize for that.

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.