Help with text based game (MUD)

Help with text based game (MUD)

Postby theillbehaviored » Wed May 08, 2013 3:34 am

I had a few questions:
Firstly, How could I make this so rather than moving through rooms using while loops, the player class would register as actually being an attribute as the room class? I'm not sure how to explain this, but I feel like the way i'm doing it now is just ineffective and there is a better way.

Secondly,
When I run this code and try to move into the other room by inputting "e", the variable tork.x gets increased by one but it does not activate the while loop below it which is suppose to activate when tork.x=1.

Sorry if i'm going everywhere with this. I'm brand new to Python and appreciate any advice you guys can give me. Kthnx!


Code: Select all
class Player:
    def __init__(self, name, xlocation, ylocation):
        self.x=xlocation
        self.y=ylocation
        self.name=name
       
tork=Player("Tork", 0, 0)


class Room:
    def __init__(self, xcord, ycord, desc, player):
        self.x=xcord
        self.y=ycord
        self.roomdescription=desc
        self.player=player


     

       
room1=Room(0, 0, """

        A Metal Hallway
        This place is dimly lit and cool
        ----------------------------------------------------
        You stand in the middle of an intersection in a metal room.
        There are blue glowing lamps lighting this area up. There
        is a sign on the wall.
        ----------------------------------------------------
        Obvious exits:East, North""", True)

room2=Room(-1, 0, "This is a large metal room", False)
room3=Room(1, 0, """
        Thacker's Main Control Room
        This place is well lit and cool
        ----------------------------------------------------
        There are multiple panels throughout with a variety of levers and buttons.
        People stand in uniforms infront of computers, which are scattered throughout the room.
        There is a glass window here revealing space.
        Thacker is sitting here in the back of the room in a large chair.
        ----------------------------------------------------
        Obvious exits:West""", False)

room4=Room(0, 1, "This is a large metal room", False)

room5=Room(0, -1, """
        Large Hanger Bay
        This place is well lit and cool
        ----------------------------------------------------
        There are a variety of mobile suits here
        ----------------------------------------------------
        Obvious exits:South""", False)



holder=0
while(holder==0):
    holder=0

    while tork.x == room1.x and tork.y == room1.y:
            direction=input(print(room1.roomdescription) )
            if direction==("e"):
                tork.x = tork.x + 1

    while tork.x == room2.x and tork.y == room2.y:
        direction=input(print(room2.roomdescription))
        if direction==("w"):
            tork.x=tork.x-1

       
theillbehaviored
 
Posts: 1
Joined: Wed May 08, 2013 3:28 am

Re: Help with text based game (MUD)

Postby hansn » Wed May 08, 2013 8:13 am

theillbehaviored wrote:When I run this code and try to move into the other room by inputting "e", the variable tork.x gets increased by one but it does not activate the while loop below it which is suppose to activate when tork.x=1.

Why should it activate when tork.x == 1?
You are comparing it to room2.x which is set to -1

theillbehaviored wrote:How could I make this so rather than moving through rooms using while loops, the player class would register as actually being an attribute as the room class? I'm not sure how to explain this, but I feel like the way i'm doing it now is just ineffective and there is a better way.

In my opinion, there are a lot of better ways to do this. But there is no better way of learning than to create some bad code at first and then realizing how you could make it better. Don't always worry about 'the best way' to do something. Just enjoy doing it the way you know how, even if it's ineffective, and take a look at it afterwards to see if you can improve it.
Just my 2 cents as I've thrown a lot of fun and educational projects out of the window because I didn't think it was the 'correct' way to write it.
hansn
 
Posts: 87
Joined: Thu Feb 21, 2013 8:46 pm

Re: Help with text based game (MUD)

Postby Mekire » Thu May 09, 2013 1:05 am

You might be interested in Ichabod's thread here.

Other than that, well your main game loop will be a while loop obviously. I like having rooms in a dictionary where the keys are coordinate locations. This allows you to easily create a map but efforts have to be gone to to make different rooms feel unique. There are tons of ways to go about this--I think the most challenging part is trying to develop a flexible framework that will work with a lot of different situations. The easiest way is the least flexible, being to write custom logic for each individual room/area. This would get you a working project quickly but adding things is more arduous.

As hansn said, your first goal should be to get "something" working. Never mind how or what. Afterwards you and others can look over it and talk about other, perhaps better, ways to accomplish the same thing.

Anyway good luck and keep us updated on your efforts.
-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests