Fixed the above problem; I made a prototype of class tBedroom above game. However, I'm having other trouble, and I can't explain this.
I'm testing the first two classes, as you know. However, I'm having an interesting problem: A public variables refuses to change value. Or rather, it does, then it goes back. I'm testing all my commands for how well they work. First, I try to do all the commands before it should be possible to see the items. Then, make it so they can be seen but no items are taken. Then, get the items and try to get out the room. It all passes the tests, until the last part: Opening the door with the proper tools.
The variable I'm trying to modify is in class
game, called gamestate. It is a USHORT (typedef'd as Unsigned Short Integer). The chain of functions is as follows for the last test:
1. int main calls tBed.openDoor, passing engine (the game class) as a parameter.
2. tBed.openDoor sees that tbed.DoorLocked, a bool variable, is false, so it calls engine.win().
3. engine.win sets gamestate to 1, then
cout's the variable's value. (It changed to 1, as expected)
4. int main() does an if-then to check engine.gamestate's value. If it's 0, the test fails.
5. As it happens, gamestate is 0, and the game fails the test.
WHAT!?! Here's the code, in order of how it's called:
In int main():
tBed.openDoor(engine);
void tBedroom::openDoor(game engine)
{
if(doorLocked == true)
{
cout << "LOCKED.\n";
}
else
{
engine.win();
}
}
void game::win()
{
cout << "GAMESTATE IS " << gamestate << endl;
gamestate = 1;
cout << "GAMESTATE IS NOW " << gamestate << endl;
}
Back to int main():
if(engine.gamestate == 0)
{
cout << "TEST FAILED. DOOR CLOSED.\n";
cout << "GAMESTATE IS " << engine.gamestate << endl;
}
else
{
cout << "SUCCESS. ALL TESTS PASSED.\n"; //Passed final test
system("pause");
}
My output is:
SUCCESS. DOOR UNLOCKED.
GAMESTATE IS 0
GAMESTATE IS NOW 1
TEST FAILED. DOOR CLOSED.
GAMESTATE IS 0
WHAT THE *censored*