Page 2 of 2

Re: Development Topic: Text Game

Posted: Fri Jun 12, 2009 7:08 am
by Martijn
eeeeeeeeedit:

Lucas helped me on MSN, and it now works perfect :).
I just "mapped" some placed and it's really confusing atm but w/e :p.


Here is a screenshot of how it looks now:

Image

See the compass? Well it looks great in my opinion but I want it at the bottom like this:

Image


I know it's in dutch, but look at the bottom, he got the navigation stuff there. How can I do that? Or is that way to complicated? Because if I got it there I can just simply edit it, and not mess with spaces each time :p.

Re: Development Topic: Text Game

Posted: Fri Jun 12, 2009 3:11 pm
by MarauderIIC
Output a bunch of newlines. But I'm not sure how you would position the input cursor.

Re: Development Topic: Text Game

Posted: Fri Jun 12, 2009 3:44 pm
by Martijn
If I would unput lines until the bottom of the page, i would need to CLS each time.. which I don't want :p.
It looks like the divided his console into 2 parts, no idea how he did it tho :o

Re: Development Topic: Text Game

Posted: Fri Jun 12, 2009 3:51 pm
by Bakkon
If you're programming in Windows, <windows.h> has some nifty functions for cursor control.

Code: Select all

void gotoxy(int x, int y)
{
	HANDLE output_handle = GetStdHandle(STD_OUTPUT_HANDLE);

	COORD position;
	position.X = x;
	position.Y = y;

	SetConsoleCursorPosition(output_handle, position);
}
Make sure to search MSDN for anything that looks odd to you. This should allow you to jump down a view lines, draw your compass, then jump back up to ask for a direction.

Re: Development Topic: Text Game

Posted: Mon Jun 15, 2009 11:14 am
by Martijn
@Bakkon: Meh, i'm not really getting it but thats okay got other things to worry about atm :p.


Like the walking, it works but you can move EVERYWHERE and I want to be able to say for each map exits = north, west
so you can only leave the map to the north and west! Anyone got an idea how to do that?

Re: Development Topic: Text Game

Posted: Mon Jun 15, 2009 6:16 pm
by MarauderIIC
Martijn wrote:...I want to be able to say for each map exits = north, west
so you can only leave the map to the north and west! Anyone got an idea how to do that?
I'm not going to pull any punches here :) Normally I don't post solutions, but I don't feel creative enough to make you think.

So, yes. Make a Room class and a Direction enum.

Code: Select all

enum Direction {
    NORTH,
    EAST,
    SOUTH,
    WEST,
    NUM_DIRECTIONS
};

class Room {
/* ... */
    int index;
    Room* exits[NUM_DIRECTIONS]; //contains pointers to Rooms
    int exitNums[NUM_DIRECTIONS]; //contains index #s of Rooms
/* ... */
};
In the constructor for Room, initialize all exits to NULL and all exitNums to -1. Load all the Rooms, leave the contents of exits as NULL but store the index of each exit to in the appropriate entry in exitNums. Once all the Rooms are loaded, go through every Room and search for the index of the Room that matches this Room's exitNums entry that we were searching for, skipping any exitNums entries that are -1. Assign exits[appropriateDirection] to the Room we found that has the index that matches exitNums[appropriateDirection]. When outputting exits, loop through Directions on exits. If exits[appropriateDirection] == NULL, don't output the direction as a possible exit, and prohibit movement in that direction. If not NULL, set Player's currentRoom to exits[appropriateDirection].

Obviously, I've done this before.

Re: Development Topic: Text Game

Posted: Sun Jun 21, 2009 1:55 am
by Ginto8
Martijn wrote:eeeeeeeeedit:

Lucas helped me on MSN, and it now works perfect :).
I just "mapped" some placed and it's really confusing atm but w/e :p.


Here is a screenshot of how it looks now:

-big_image-

See the compass? Well it looks great in my opinion but I want it at the bottom like this:

-big_image-


I know it's in dutch, but look at the bottom, he got the navigation stuff there. How can I do that? Or is that way to complicated? Because if I got it there I can just simply edit it, and not mess with spaces each time :p.
perhaps <iomanip> is what you're looking for... if not, try <windows.h> stuff

Re: Development Topic: Text Game

Posted: Tue Jun 23, 2009 12:51 pm
by Martijn
Okay. I tried to understand, I really did been googling for days but I don't get it ;/.
I understand the enum part, but the rest confuses me a little.

If someone got time, could they care to explain please?

Re: Development Topic: Text Game

Posted: Tue Jun 23, 2009 4:43 pm
by MarauderIIC
Your rooms have index #s.
Your file has descriptions of the rooms, and each index# that each room should exit to.

Start your program.
Load all the rooms.
Replace each room's "exit index#"s with pointers to the rooms that have those index numbers.

Allow the player to play.

To output the exits, iterate through the exits array (which contains pointers). If the entry is null, don't output it as a possible exit.

When the player chooses a direction to exit, associate that direction with an index in the exits array -- each room's exits are in the same order (north, east, south, west). Use their choice as an index into the exits array. If the entry is null, output "can't go that way." If the entry is not null, replace the pointer to the player's current room with the pointer to the appropriate exit, so now the pointer to the player's current room and the pointer to the appropriate exit point to the same room.

This is an example of the move code:

Code: Select all

Room* check;
if (myPlayerInput == "north")
    check = myPlayer.currentRoom.exits[NORTH];
else if (myPlayerInput == "east")
    check = myPlayer.currentRoom.exits[EAST];\
/* repeat for other directions */

myPlayer.move(check);

Code: Select all

Player::move(Room* room) {
    if (room == NULL) {
        cout << "Can't go that way" << endl;
    } else {
        this->currentRoom = room;
        this->look();
    }
}
This is an example of the code that replaces all index #s with pointers:

Code: Select all

class Room {
    int exitIndexes[NUM_DIRECTIONS];
    Room* exits[NUM_DIRECTIONS];
};

Code: Select all

class Game {
    vector<Room*> rooms;
    void loadRooms(string filename);
    void dereferenceRooms();
};

Code: Select all

Game::dereferenceRooms() {
    vector<Room*>::iterator curRoom;
    vector<Room*>::iterator exitRoom;

    //go through all the rooms
    for (curRoom = rooms.begin(); curRoom != rooms.end(); ++curRoom) {

        //go through all this room's exit indexes, examining each one
        for (int curExitIndex = NORTH; curExit < NUM_DIRECTIONS; ++curExit) { 

            //go through all the rooms, searching for an index that matches the exit index we're examining
            for (exitRoom = rooms.begin(); exitRoom != rooms.end(); ++exitRoom) { 

                //if they match, fill in the appropriate entry of exits[] and move on
                if (exitRoom->index == curRoom->exitIndexes[curExitIndex]) {
                    curRoom->exits[curExitIndex] = *exitRoom;
                    break;
                }

            } //end exitRoom loop
        } //end curExitIndex loop
    } //end curRoom loop
} //end function
Better?

Re: Development Topic: Text Game

Posted: Tue Jun 23, 2009 4:58 pm
by MarauderIIC
Marking as new since I edited like 15 minutes after I posted.