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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:34:43+00:00 2026-06-15T04:34:43+00:00

I have a game that i’m working on where I have a particle effect

  • 0

I have a game that i’m working on where I have a particle effect as a separate class

    public class Explosion 
    {
         private List<Particle> Particles; 
         private const int particle_Count = 100; 
         public Explosion(Vector2 location) { 
               Random random = new Random(); 
               Particles = new List<Particle>(particle_Count);
               for(int i = 0; i < particle_Count; i++)
                   Particles.add(new Particle(location, new Vector2(random.NextDouble() * i,
                       random.NextDouble() * i)); 
         }
    }

Now, there need to be several different types of explosions in my game, but they only vary very slightly (It’s literally the difference between one Vector2 object (Which is just an object that stores two coordinates and a few helper functions for those whom aren’t familiar with XNA))

My question is, because Random is only accessible once I enter the constructer, how do i make variations on of this explosion?

Should I make a new class for each explosion? (That seems unnecessary due to how little changes between explosions)

Should I overload the function to take a separate parameter (maybe an int) for each different explosion?

Should I directly pass the Vector2 in through the constructor (which seems like it would break good OOP principle to me)

Or is there another way to get around this that i’m just not seeing.

Any help would be much appreciated, I like to do things right the first time, and this is an important part of my application.

Thanks.

  • 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-15T04:34:44+00:00Added an answer on June 15, 2026 at 4:34 am

    Since there’s only one parameter difference between each variation, the best thing is just to pass another parameter into the constructor (as you mentioned). Just pass in the minimal info you need; if you like, give it a default value so that it’s not required:

    public Explosion(Vector2 location, int velocity = 1) { 
    }
    

    If it’s a complex object, and not just an int, then consider making a helper method of some kind:

    public class Explosion
        public Explosion(Vector2 location, Velocity velocity) { 
        }
    }
    
    public class Velocity {
        public static Velocity Get(int a, int b) {
            // construct the velocity as needed
        }
    }
    

    This way calling the constructor for Explosion doesn’t have to get too messy:

    var explosion = new Explosion(vectorLocation, Velocity.Get(5, 10));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a chess game that originally used an stl list to store the
I have a game that I am working on where I am wanting to
I have a game that I am working on in a C# console application,
I have a game that I've been working on for iOS. We let our
I have a game that currently runs under Windows and Mac OS X and
We have a game that is very close to being released, but we have
I have a game engine that uses OpenGL for display. I coded a small
I have a game server that spawns a thread for each client with forkIO.
I have a cocos2d powered game that uses UIKit menues, so I only use
I have a big 3d game that lets players build and create interesting and

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.