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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:52:21+00:00 2026-05-29T08:52:21+00:00

I have a class with an enumerated type GameStates. In the (public) constructor I

  • 0

I have a class with an enumerated type GameStates. In the (public) constructor I initialise GameStates like this:

GameStates enumGameState = Ready;

Then in a public method run() i have a switch like this:

switch(enumGameState)
        {
        case Ready:
            if (theGameEngine->KeyHit(Key_Space))
            {
                enumGameState = Firing;
                cout << "\nGame State moved to Firing";
            }   // End if
            break;
        case Firing:
            if (theGameEngine->KeyHit(Key_Space))
            {
                enumGameState = Contact;
                cout << "\nGame State moved to Contact";
            }   // End if
            break;
        case Contact:
            if (theGameEngine->KeyHit(Key_Space))
            {
                enumGameState = Over;
                cout << "\nGame State moved to Over";
            }   // End if
            break;
        case Over:
            break;
        };  // End of GameState switch

Whilst the code does not error, none of the states are met. How should i be accessing the value of enumGameState?

EDIT: All class code.

class Game
{
private:
    Block* arrBlocks[10][10];   
    //IMesh* objBlockMesh;
    IMesh* objGunMesh;
    IMesh* objDummyMesh;
    Gun* objGun;
    int Game::intSpeed;
    I3DEngine* theGameEngine;
    float fltSkyboxXCo;
    float fltSkyboxYCo;
    float fltSkyboxZCo;
    float fltFloorXCo;
    float fltFloorYCo;
    float fltFloorZCo;

    enum GameStates{Ready,Firing, Contact, Over};
    GameStates enumGameState;

public: 

    Game(I3DEngine* the3dengine)
    {
        Game::theGameEngine = the3dengine;
        theGameEngine->StartWindowed();

        // Add default folder for meshes and other media
        theGameEngine->AddMediaFolder( "C:\\TL-Engine\\Media\\AssigmentTwo\\Media" );

        //intSpeed = 1;

        Game::DrawBasicScene(theGameEngine);
        Game::DrawBlocks();
        Game::CreateAGun();
        Bullet::Bullet(theGameEngine);
        Game::enumGameState = Ready;
    }   // End of Constructor


private:    


    void DrawBlocks()
    {
        float fltBlockOffSet = 12.0f;
        float fltLeftMost = -54.0f;
        float fltBlockZCo = 120.0f;
        float fltBlockYCo = 5.0f;
        float fltCurrentXCo;
        float fltCurrentYCo = 5.0f;
        float fltCurrentZCo = 120.0f;
        // Stick 10 blocks in an array
        // Display them

        for(int i = 0; i < 10; i++)
        {
            if (i == 1) // Once i have created the first row all the other blocks are going to be created in a hidden state
            {
                fltCurrentYCo = -50.0f;
            }
            for(int j = 0; j < 10; j++)
            {
                fltCurrentXCo = ((float)j*fltBlockOffSet) + fltLeftMost;    // Cast j into a float explicitly so that it doesn't it implicitly
                arrBlocks[i][j] = new Block(theGameEngine, fltCurrentXCo, fltCurrentYCo, fltCurrentZCo);
                if(fltCurrentYCo < 0)
                {
                    arrBlocks[i][j]->SetBlockState(Block::Destroyed);
                }   // End if
                else
                {
                    arrBlocks[i][j]->SetBlockState(Block::New);
                }
            }   // End of inner loop

            fltCurrentZCo += fltBlockOffSet;

        }   // End of outer loop

    }

    void CreateAGun()
    {
        // Create a gun
        Gun::Gun(theGameEngine);
    }

public:
    void Game::Run()
    {
        //Start watching input in a while loop
        // The main game loop, repeat until engine is stopped
        while (theGameEngine->IsRunning())
        {
            // Draw the scene
            theGameEngine->DrawScene();
            if (theGameEngine->KeyHit(Key_Escape))
            {
                theGameEngine->Stop();
            }

            if)theGameEngine->KeyHit(Key_Space))
            {
                cout << "\n space";
            }

            GameStates currentGameState = enumGameState;
            switch(enumGameState)
            {
            case Ready:
                if (theGameEngine->KeyHit(Key_Space))
                {
                    enumGameState = Firing;
                    cout << "\nGame State moved to Firing" << endl;
                }   // End if
                break;
            case Firing:
                if (theGameEngine->KeyHit(Key_Space))
                {
                    enumGameState = Contact;
                    cout << "\nGame State moved to Contact" << endl;
                }   // End if
                break;
            case Contact:
                if (theGameEngine->KeyHit(Key_Space))
                {
                    enumGameState = Over;
                    cout << "\nGame State moved to Over" << endl;
                }   // End if
                break;
            case Over:
                break;
            };  // End of GameState switch
        }

    }
};  // End of Game 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-29T08:52:22+00:00Added an answer on May 29, 2026 at 8:52 am

    Thanks for your help guys. The issue was not with the class, or code oustide of the class at all. It was an issue with visual studio, i’m not sure what unfortunately. When the code was copied out and added into a new project, it compiled perfectly, and all the break points placed in main were hit.

    MORAL OF THE STORY: Try the obvious first.

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

Sidebar

Related Questions

I have an Application Delegate class with a enumeration which looks like this: typedef
I have class method that returns a list of employees that I can iterate
I have class A: public class ClassA<T> Class B derives from A: public class
I have class A: public B { ...} vector<A*> v; I want to do
I have class Fred { public: void inspect() const {}; void modify(){}; }; int
I have Event<T> class for event handle, where T is functor type of signature
I have a enum type: enum class MyEnumType { A , B , C
I have a C# method that returns very large number of objects. This is
Suppose I have some per-class data: (AandB.h) class A { public: static Persister* getPersister();
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from

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.