Development Topic: Text Game
Moderator: Coders of Rage
- Martijn
- Chaos Rift Newbie
- Posts: 22
- Joined: Thu Jun 04, 2009 4:47 pm
- Programming Language of Choice: C++
Re: Development Topic: Text Game
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:
See the compass? Well it looks great in my opinion but I want it at the bottom like this:
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.
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:
See the compass? Well it looks great in my opinion but I want it at the bottom like this:
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.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Development Topic: Text Game
Output a bunch of newlines. But I'm not sure how you would position the input cursor.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- Martijn
- Chaos Rift Newbie
- Posts: 22
- Joined: Thu Jun 04, 2009 4:47 pm
- Programming Language of Choice: C++
Re: Development Topic: Text Game
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
It looks like the divided his console into 2 parts, no idea how he did it tho
- Bakkon
- Chaos Rift Junior
- Posts: 384
- Joined: Wed May 20, 2009 2:38 pm
- Programming Language of Choice: C++
- Location: Indiana
Re: Development Topic: Text Game
If you're programming in Windows, <windows.h> has some nifty functions for cursor control.
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.
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);
}
- Martijn
- Chaos Rift Newbie
- Posts: 22
- Joined: Thu Jun 04, 2009 4:47 pm
- Programming Language of Choice: C++
Re: Development Topic: Text Game
@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?
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?
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Development Topic: Text Game
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.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?
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
/* ... */
};
Obviously, I've done this before.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Development Topic: Text Game
perhaps <iomanip> is what you're looking for... if not, try <windows.h> stuffMartijn 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- Martijn
- Chaos Rift Newbie
- Posts: 22
- Joined: Thu Jun 04, 2009 4:47 pm
- Programming Language of Choice: C++
Re: Development Topic: Text Game
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?
I understand the enum part, but the rest confuses me a little.
If someone got time, could they care to explain please?
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Development Topic: Text Game
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:
This is an example of the code that replaces all index #s with pointers:
Better?
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();
}
}
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
Last edited by MarauderIIC on Tue Jun 23, 2009 4:57 pm, edited 1 time in total.
Reason: put in loading code
Reason: put in loading code
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Development Topic: Text Game
Marking as new since I edited like 15 minutes after I posted.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.