I used that code and made sure the program and fiel were in the dame folder and it still did not work. ): I am running Windows 7 and using Code::Blcoks if that helps at all.
Change Moschops's to use an ifstream, so you only need permission to 'read' the file (make sure tha you've got permission to 'read' the file)
Execute from a terminal, so you know the path environment.
#include <iostream>
#include <Windows.h>
#include <string>
usingnamespace std;
int gameloop();
void gameload();
void descgetter();
void input();
void output();
void locationgetter();
int location = 10000;
int north, east, south, west;
int x = 100;
int y = 100;
string name;
string desc;
int main(){
START:
string option;
cout << "Would you like to start a new game or load a previous one?" << endl;
cout << "[N]ew Game" << endl;
cout << "[L]oad Game" << endl;
cin >> option;
if(option == "N" || "n" ) system("cls"); gameloop();
if(option == "L" || "l" ) system("cls"); gameload();
goto START;
}
int gameloop(){
int gameon = 0;
while(gameon == 0){
locationgetter();
descgetter();
output();
input();
}
return 0;
}
void gameload(){
}
void input(){
START:
string input;
cin >> input;
if(input == "west" || west == 0) cout << "You can not move that way." << endl; goto START;
if(input == "north" || north == 0) cout << "You can not move that way." << endl; goto START;
if(input == "east" || east == 0) cout << "You can not move that way." << endl; goto START;
if(input == "south" || south == 0) cout << "You can not move that way." << endl; goto START;
if(input == "west" || west == 1){--x;}
if(input == "north" || north == 1){++y;}
if(input == "east" || east == 1) {++x;}
if(input == "south" || south == 1){--y;}
}
void output(){
cout << desc << endl;
}
void locationgetter(){
if(x == 100 && y == 100) location = 1;
if(x == 99 && y == 101) location = 2;
if(x == 100 && y == 101)location = 3;
}
void descgetter(){
switch(location){
case 1: desc = "You are in a large orange room. You can move north, east, south, and west."; west = 1; south = 1; east = 1; north = 1; break;
case 2: desc = "You are in a large blue room. You can move east."; west = 0; south = 0; east = 1; north = 0; break;
case 3: desc = "You are in a large grey room. You can move west and south."; west = 1; south = 1; east = 0; north = 0; break;
}
}
For this code it seems to not leave the input function. All the if statements inside of room1 are working fine, but when I type in north nothing happens. I can still continue to type in other directions though.
I ditched this project a while ago but I think it had something to do with:
1 2 3 4
if(input == "west" || west == 0) cout << "You can not move that way." << endl; goto START;
if(input == "north" || north == 0) cout << "You can not move that way." << endl; goto START;
if(input == "east" || east == 0) cout << "You can not move that way." << endl; goto START;
if(input == "south" || south == 0) cout << "You can not move that way." << endl; goto START;
I didn't use braces for them so even if none of the if statement's arguments were met I still went to START.