Moving between areas

This is a discussion on Moving between areas within the C++ Programming forums, part of the General Programming Boards category; NewUserlocation NewUser.location O_O something is different... Soma...

  1. #61
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    NewUserlocation
    NewUser.location

    O_O

    something is different...

    Soma

  2. #62
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Fixed it, was missing a dot

  3. #63
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Oh u beat me to the punch haha

  4. #64
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    if I wanted to load the rooms from a file, would be it besomething like this

    Code:
    string line[23];
    
    ifstream tscreen;
    tscreen.open("rooms.txt");
    
    int num;
    for (int num = 0; num <= 23; num++)
    {
    getline(tscreen, line[num]);
    cout << line[num] << endl;
    }
    
    tscreen.close();

    and the txt file would be like this

    Code:
    	Room *rooms = new Room [4];
    	rooms[0].description = "Crossroads";
    	rooms[1].description = "Bridge";
    	rooms[2].description = "Gateset";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";
    	rooms[3].description = "Cut Thoat Path";

  5. #65
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    except that will display it... but could I use something like that but not cout

  6. #66
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    One thing to note is that you have 23 elements, yet you access 24 (the <= in the for loop).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #67
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ok ill fix that, but would that work? if i minus the cout?

    I have about 100 rooms and I dont really want that in my main file

  8. #68
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    It will work in that fashion by storing data in a file and loading it, yes. But it will not work with your current code, of course.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #69
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Yeah I thought so, was worth checking .

  10. #70
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Well I have put most of snippets together and it all works lovely.

    Just wondering if it is possible to put a function in between the moving, using this method.

    E.g To move from Room 1 to Room 2 you must answer this question,

    to move to Room 2 to Room 4 you must answer this different question

    Or is the only way to put a funcion into the room class and dot call it like description once in the room?

    Or I could put functions within a class and do something like this right?

    cout << "(W)est to: " << NewUser.location->west->description->fone << endl; // where fone is a function in the class
    Last edited by Aliaks; 07-16-2009 at 05:59 AM.

  11. #71
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Seriously, now, this is a programming language and what you're talking about is logic, not language features, so of course it's possible!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #72
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Yeah but the only way I can see doing it is putting a function in the class and using some library function that can randomly select a function to be called.

    Or when moving to a different area doing the same thing, but I don't know if there is a c++ function that can call randomly a created function.

  13. #73
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    I don't know what you're trying to do at all...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #74
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    say I make a math function like ...

    Code:
    cout << "What is 10 plus 2?";
    cin >> input
    and when the user moves from room 1 to room 2 they have to answer that function to move to room 2

    but I want a different function between each room

  15. #75
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Look at this:
    Code:
    		if (input == 'n' && player.location->north)
    			player.location = player.location->north;
    Now, what if we change input from == 'n' to == 12?
    Code:
    int input;
    cout << "What is 10 + 2?";
    cin >> input;
    if (input == 12 && player.location->north)
        player.location = player.location->north;
    If the input is 12, we set the player's new location to the room that is north of here.
    Difficult?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 5 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack overflow errors in 3 areas
    By ulillillia in forum C Programming
    Replies: 13
    Last Post: 04-29-2007, 04:20 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-24-2007, 12:05 AM
  3. rescaling areas
    By hannibar in forum C Programming
    Replies: 2
    Last Post: 02-28-2006, 03:22 PM
  4. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 05:46 AM
  5. Simple program i cant get (dot moving)
    By Lupusk9 in forum C++ Programming
    Replies: 4
    Last Post: 09-14-2004, 09:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21