Thread: Moving between areas

  1. #16
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ahhh I see. Well I understand at face value just struggling to get my head around the moving between rooms after the 1st move .

    And no, not moving within the room, just between different rooms.

    Dont think im advance neough to rite a program that does it like that, I will have to rite it all myself

  2. #17
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Wait, I think im starting to get it, so that loop basicly continues for what ever room u are in? until the player quits? correct?..


    Also, I have always used include, what is import?

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It allows you to move between the rooms you have, yes.
    So long as you have set up the proper room structs, it should work.
    You could also set some pointers to NULL if, in a room, you can't move any more north, say. Remember to check for it also.

    About the -> syntax. It is the same as "(*p).".
    So basically it dereferences a pointer and access its members.
    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.

  4. #19
    Registered User
    Join Date
    Feb 2009
    Posts
    37
    Import?

    Don't worry about that, just use include. I copy-pasted out of my "Test" project I use for anything random like this, so there was other unrelated code. Otherwise you can actually compile this and have a working, simple, game.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What? No. Never include .cpp files.
    Never, ever do anything like that. There is no import either.
    .cpp files are compiled separately, thus they should not be included anywhere.
    I don't know how many times I must repeat this.
    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.

  6. #21
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ahh I see, thanks

    Code:
    public:
    
    	string description;
    
    	Room *north;
    	Room *south;
    	Room *east;
    	Room *west;
    };
    
    // A very simple player class
    class Player {
    public:
    	Room *location;
    };
    
    int main (int argc, char **argv) {
    
    	// Create an example map with four rooms:
    	// For an actual game you might load this data from a file.
    
    	// Create four rooms.
    	Room *rooms = new Room [4];
    	rooms[0].description = "Room 1";
    	rooms[1].description = "Room 2";
    	rooms[2].description = "Room 3";
    	rooms[3].description = "Room 4";
    With that part of the code, the dark red isnt a member, so surely the teal will be an error?

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    description is part of the class Room and you create 4 new rooms which has a description member, so it's fine.
    And also, I would recommend that you avoid new. I don't really see a need for it.

    We can also use a vector as:
    Code:
    std::vector<Room> Rooms;
    Rooms.push_back( Room("Room 1") );
    // etc
    Of course, we'll need a constructor for Room, too, so here goes:
    Code:
    Room::Room(const std::string& Description): description(Description), north(NULL), south(NULL), east(NULL), west(NULL) { }
    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.

  8. #23
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Well I just compiled the above and it says. . .

    C:\Users\Administrator\Desktop\roomtesty.cpp|9|err or: `string' does not name a type|
    C:\Users\Administrator\Desktop\roomtesty.cpp||In function `int main(int, char**)':|
    C:\Users\Administrator\Desktop\roomtesty.cpp|30|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|31|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|32|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|33|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|61|er ror: `cout' was not declared in this scope|
    C:\Users\Administrator\Desktop\roomtesty.cpp|61|er ror: `endl' was not declared in this scope|
    C:\Users\Administrator\Desktop\roomtesty.cpp|62|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|64|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|66|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|68|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|70|er ror: 'class Room' has no member named 'description'|
    C:\Users\Administrator\Desktop\roomtesty.cpp|75|er ror: `cin' was not declared in this scope|
    ||=== Build finished: 13 errors, 0 warnings ===|


    Is it better to use a vector liek that?

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to learn to interpret error messages. It says there is no such type as "string".
    This is because it should be std::string (the example wasn't properly tested).
    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.

  10. #25
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ahh im so used to using namespace std, I didn't pick up why string was an error.

    I think you mentioned to use std:: instead of using namespace std?
    Last edited by Aliaks; 07-13-2009 at 05:02 AM.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can either do std::string or add using namespace std.
    It is a good idea, however, to use std::, if only to get used to it.
    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. #27
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    How can I go about looking for runtime errors (I believe they are called). I am using vista and as soon as I run the exe which just contains the above example code, it comes up but then a dialog box appears ' roomexample.exe has stopped working'

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Run it in a debugger. There are many of those.
    My favorite would be Visual Studio, which is an IDE with a compiler and debugger among other things.
    Of course, there's also GDB and other debuggers you can find on the web.
    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. #29
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Probably a segmentation fault. Check your pointer logic.

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Learning to use a debugger is also a very valuable tool that is very important to a programmer.
    It also allows you to waste less time finding a problem and more fixing it.
    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.

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, 03:20 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  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, 08:04 PM