Here's the concept behind my project: I've created a simple game that utilizes a do/while function and a switch statement to determine the player's current room. When the player is in room 1, the switch selects room1 and executes the room1() function. Within the room, the player can choose which direction to go. If they choose north or east, a door1() or door4() function will prompt them to open the door and progress to the next room, updating their room value in the process.
While everything seems to be working smoothly and the functions are functioning correctly, there is a major issue with the variables resetting whenever the player walks through a door. As a result, the player always ends up back in room 1, with their compass set to 0 and none of the doors or rooms marked as "visited."
Essentially, walking through a door should lead the player to room 2 or 4, but instead, they keep returning to room 1.
Below is the code, along with a step-by-step guide:
var room1V = 0;
var room2V = 0;
var room3V = 0;
var room4V = 0;
var door1V = 0;
var door2V = 0;
var door3V = 0;
var door4V = 0;
var compass = 0;
var room = 1;
var reply = 1;
win = 0;
do {
quit = 0;
switch(room) {
case '1':
room1(compass,room1V);
break;
case '2':
room2(compass,room2V);
break;
case '3':
room3(compass,room3V);
break;
case '4':
room4(compass,room4V);
break;
}
} while (win != 1);
Upon initiating the program, the room1(compass,room1V) function is invoked since the default room is set to 1.
function room1(compass,room1V) {
// Function logic
} // Working
If the player selects 'north,' the compass will be updated accordingly, and door4(room,door4V) will be executed.
function door4(room,door4V) {
// Function logic
} // Working
Despite the intention for the program to recognize the player's shift to room 4, they keep returning to room 1 whenever the do/while loop restarts, and all variables appear to be reset.