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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:24:35+00:00 2026-05-24T08:24:35+00:00

I am making a game which has a global (static) class called MedGameController. In

  • 0

I am making a game which has a global (static) class called MedGameController. In my class I have two arrays of fifteen objects each which hold the logic for each players units. In the game the player’s go to a form where they see their already created units and have buttons to create more units. I don’t know how to check if current units exist though so I can’t even create a single unit. How do I check if the instance of my unit class exists in the array? The array of units have to have a scope which incompasses two maybe three forms so that is why I created them in a global class. Here is the global class:

static class MedGameController      
{
    static int ply1pts;
    static int ply2pts;
    Squad[] ply1squads = new Squad[15];
    Squad[] ply2squads = new Squad[15];

    public static int SetPly1Pts
    {
        get { return ply1pts; }
        set { ply1pts = value; }
    }

    public static int SetPly2Pts
    {
        get { return ply2pts; }
        set { ply2pts = value; }
    }

    public static int SquadSetUp
    {
        get { return squadcreation; }
        set { squadcreation = value; }
    }
    public static void Player1Squads
    {
        This is where I think i'm supposed to check if they exist then if it doesn't then I create the instance of the squad class
    }
}

}

  • 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-24T08:24:36+00:00Added an answer on May 24, 2026 at 8:24 am

    Try this:

    if (ply1Squads.Length == 0)
    {
        for (int i = 0; i < 15; i++)
        {
            ply1Squads[i] = new Squad();
        }
    }
    

    You’ve already declared ply1Squads to have 15 Squad objects, so it’s just a matter of initializing the objects at that point.

    You can do the same thing for ply2Squads.

    BTW, you need to declare ply1Squads and ply2Squads as static as well, as static classes can’t have instance members:

    static Squad[] ply1Squads = new Squad[15];
    static Squad[] ply2Squads = new Squad[15];
    

    By default, these will be private variables, so you’ll want properties for these two arrays as well:

    public static Squad[] Ply1Squads
    {
        get
        {
            return ply1Squads;
        }
        set
        {
            ply1Squads = value;
        }
    }
    
    public static Squad[] Ply2Squads
    {
        get
        {
            return ply2Squads;
        }
        set
        {
            ply2Squads = value;
        }
    }
    

    Additional Thoughts

    If your design goal is to have MedGameController handle all the information related to the squads, I’d move away from what you appear to be doing – creating duplicate methods for each Squad array (i.e., Player1Squads). Instead, pass in a flag of some sort telling the controller which array to use, like this:

    public void CreateSquads(int playerNum)
    {
    
        select (playerNum)
        {
            case 1:
                for (int i = 0; i < 15; i++)
                {
                    ply1Squads[i] = new Squad();
                }
                break;
            case 2:
                for (int i = 0; i < 15; i++)
                {
                    ply2Squads[i] = new Squad();
                }
                break;
            default:
                // Handle wrong number here
                break;
        }
    }
    

    That’s a (very small) refactoring step. I would come up with a list of things you want the controller to do, and then figure out how to avoid a 1-1 mapping of every function to both arrays.

    Hopefully this makes some sense and gives you a direction to go in. I have some more ideas tickling the back of my brain, but I can’t pull them out to the front yet. If I do, I’ll add more if you’re interested (what’s another edit or two after the first half-dozen, right? 🙂 ).

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

Sidebar

Related Questions

I am making a card game in ruby. I have the Game class, which
I am making a game for my CS class and the sprites I have
I'm making a simple game, and it has a single instance of a class
I am making a multithreaded pacman game. There is a PacmanController class which extends
I'm making a small game, and this has a lot of loops, which all
I am making a game which has to load all bitmaps at start because
I'm making an iPhone game which has a quite intense use of pixel shaders.
Say I have a game in PHP which is a money making game and
We are making a game which will add a level editor feature soon. We
I'm making this game where I'm trying to pair people. So I have this

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.