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

  • Home
  • SEARCH
  • 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 7573915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:18:07+00:00 2026-05-30T16:18:07+00:00

I am making a strategy game and came across a kind of problem. Basically,

  • 0

I am making a strategy game and came across a kind of problem. Basically, I don’t know how to deal with the dynamic creation of the units I need. Should I use some big switch statement or is there a more ideal solution?

  • 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-30T16:18:09+00:00Added an answer on May 30, 2026 at 4:18 pm

    I assume, you are essentially talking about instantiating different kinds of classes at runtime. The possibilities are numerous 🙂

    One option is:

    You manage a map (basically an object), where the key is an identifier of your “unit” and the value is a class object, like so:

    var unitMap:Object = {
        "hero": UserGameCharacter,
        "enemy": NPCharacter,
        "chicken": ChickenCharacter
    };
    

    Note, that the values are class objects, not instances. Furthemore, let’s assume, that all the character classes either extend a base Character class or implement a Character interface. Now, when you want to instanciate a “unit”, you would do this:

    var newCharacter:Character = new (unitMap["hero"])();
    

    This way, you don’t need a switch statement anymore. Hope, this helps as a starting point.

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

Sidebar

Related Questions

Basically, I want to design a strategy game, where most of the game will
I'm in the process of making a browser based multiplayer turnbased strategy game similiar
I'm making a JavaScript dice roller for a tabletop strategy game that my friends
I'm writing a strategy-kind of multi user game for the web. It has a
I'm making a baseball program based on the strategy games produced by Avalon Hills
So, I'm making an Android app, and I have thought of a strategy to
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
I'm planning on making an editor for my current project and will need some
What is the best strategy for making changes to a specific file within a
Satisficing (a portmanteau of satisfy and suffice) is a decision-making strategy which attempts 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.