클래스가 열거 형 GameStates입니다. (공개) 생성자에서 나는이 같은 GameStates를 초기화 :C++ 클래스 열거 형 멤버 변수
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
코드 하다니 오류없는 전혀 : public 메소드 실행에 다음
GameStates enumGameState = Ready;
() 나는이 같은 스위치가 없다 상태가 충족됩니다. enumGameState의 가치에 어떻게 접근해야합니까?
편집 : 모든 클래스 코드. 생성자가 그대로 다음 코드 줄을있는 경우
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
인쇄물에 std :: endl을 추가하여 줄을 비우는 것이 도움이됩니까?'std :: cout << "Text"<< std :: endl; –
아니요, 콘솔 출력에는 아무것도 없습니다. 나는 지금 스위치의 바깥 쪽에서 key_Space를 테스트했지만, 키 누름이 읽히지 않는 것처럼 보입니다. 이스케이프 키 캡처가 제대로 작동하는 것처럼 보이는 것은 이상합니다. –
죄송합니다. 위의 발췌 문장에없는 것을 알고 있습니다. 스위치 직전에 게임을 종료하는 이스케이프 키에 대한 또 다른 theGameEngine-> Key_Hit()가 있습니다. 완벽하게 작동합니다! –