# Creating a Roguelike game in C

I'm trying to create a simple rogue-like game in ncurses in a C program.

The idea here is that, I'd parse a file like this:

10X10 ds2 de2 dw5
12X12 ds3 de2 dw1
14X14 ds5 de1 dw5
10X10 ds5 de3 dw5
12X12 ds5 de2 dw5
14X14 dw2 de1 ds2


Where the first number is a door size(rows,columns), the second string being a door, where s = south, w = west, etc, so ds2 = door south 2 down (in the y direction).

Effectively, this looks like this when parsed, I have this:

Where (hopefully viewable), the plus signs at the end of each room, are the doors that lead to another room, so in the first room, the east door would lead to the room to the right, etc.

However, this is where I'm not sure how to go about implementing my logic. I need to make it when I step on a plus sign "effectively" a door, I'd teleport the player (the @ sign cursor) to the correct door.

Okay, great I know the locations of each doors, but how would I actually mvoe the cursor to the next room.

I can't simply hard code the distance between two rooms, as that's just ineffective and would take too long.

Just to clarify, what I mean about teleporting: See this picture:

Where the user "@" symbol would move to the door (in the first room), then get teleported to the second room (12x12 room). (AS seen in the next picture) (Again where the @ symbol is the user, moving the cursor around (w,a,s,d).

So to clarify: I need a way to move a cursor, between two rooms, without hardcoding the distance between rooms, unless there is an effective way to hard code the distances.

Any ideas?

• Assuming your character has a position(x,y) and your teleportation target (door's exit) has a position(x,y) wont player.setPosition(target.position) suffice? – Niels Feb 23 '16 at 13:59
• I'm not sure, that would play into the fact that I would have to hard code the teleportation target (Unless I'm misunderstanding your comment). I was thinking of maybe having each room be a struct element, and the struct would have members with x and y coordinates, but also members that are doors themselves, I really don't know. I guess at the end of the day I'm just quite confused about it. – TTEd Feb 23 '16 at 23:36
• I guess I was working on the assumption that you already had those in place. Are you planning on rendering all maps at once, or showing them separately? I did a similar project a few years ago in java, I will try and see if I can dig that up. Out of curiousity: what is the reason you chose to do this project in C? – Niels Feb 24 '16 at 6:55
• I've rendered all the rooms at once (if that's what you mean by maps). Also, this was one of my assignments in my first year of my undergrad (Last year). And this was one of the parts of the assignment I could never get working properly, so I figured I'd attempt to make a fully working version in my free time, since it seems like an interesting project. – TTEd Feb 26 '16 at 18:52
• Well with the similar project we did, we created an object to represent ascii-art bitmaps so we could just load an image for the map from disk, a map-file had the image, a list of blocking characters and a list of both objects and portals. the portals were references to another map, along with a coordinate. – Niels Mar 1 '16 at 7:22