Hi

I've been give a task to create a text based game (multi user dungeon) in python but am unsure where to start. All I know is I have to use tcp and udp or something like that. I am very unfamiliar with this so I hope someone can help me please.

Thank you.

There are 2 ways to go about this.

  1. You can design an engine that could be used for multiple games
  2. Design just the game, so you would know all the possible commands

Obviously the second way is easier, however, the first game is much more benificial.

I'm currently writing an engine as a learning project, but it's not close from being complete.

The second way would be much easier. Here's a simplified version of it:

end = False

class Room(object):
    def __init__(self, name, description, north=None, east=None, south=None, west=None, up=None, down=None):
        self.name = name
        self.description = description
        self.north = north
        self.east = east
        self.south = south
        self.west = west

    def __str__(self):
        return self.description


class Player(object):
    def __init__(self, name, currentRoom=None):
        self.name = name
        self.currentRoom = currentRoom

    def go(self, direction):
        direction = direction.lower()
        directiontxt = "self.currentRoom."+direction
        try:
            if eval(directiontxt) == None:
                print "You cannot go " + direction + "."
            else:
                self.currentRoom = eval(directiontxt)
                print self.currentRoom
            
        except AttributeError:
            print "The direction you are going does not exist. Try harder next time!"

class Game(object):
    def __init__(self, name, player):
        self.name = name
        self.player = player
        print player.currentRoom
        while end == False:
            cmd = raw_input(">> ")
            self.process(cmd)

    
    def process(self, cmd):
        global end
        cmdlist = cmd.split()
        if len(cmdlist) == 1:
            cmdtxt = "self.player." + cmdlist[0] + "()"
            eval(cmdtxt)
        elif len(cmdlist) == 2:
            cmdtxt = "self.player." + cmdlist[0] + "('" + cmdlist[1] + "')"
            eval(cmdtxt)
        else:
            print "You can only have a maximum 2 words for your command. Type 'help' for detail."




def main():    
    # This is a map of the proof of concept.
    # +-----+-----+-----+
    # |     |     |     |
    # |room1|room2|room3|
    # |     |    |     |
    # +-----+-----+-----+
    # |     |     |     |
    # |room4|room5|room6|
    # |     |     |     |
    # +-----+-----+-----+
    # |     |     |     |
    # |room7|room8|room9|
    # |     |     |     |
    # +-----+-----+-----+
    room1 = Room(name="room1", description="You're in room1")
    room2 = Room(name="room2", description="You're in room2")
    room3 = Room(name="room3", description="You're in room3")
    room4 = Room(name="room4", description="You're in room4")
    room5 = Room(name="room5", description="You're in room5")
    room6 = Room(name="room6", description="You're in room6")
    room7 = Room(name="room8", description="You're in room7")
    room8 = Room(name="room7", description="You're in room8")
    room9 = Room(name="room9", description="You're in room9")
    room10 = Room(name="room10", description="You're in room10")

    room1.south = room4
    room1.east = room2

    room2.south = room5
    room2.west = room1
    room2.east = room3

    room3.south = room6
    room3.west = room2

    room4.north = room1
    room4.east = room5
    room4.south = room7

    room5.north = room2
    room5.east = room6
    room5.south = room8
    room5.west = room4
    room5.down = room10

    room6.north = room3
    room6.south = room9
    room6.west = room5

    room7.north = room4
    room7.east = room8

    room8.north = room5
    room8.east = room9
    room8.west = room7

    room10.up = room5
    
    room9.north = room6
    room9.west = room8
    
    adventurer=Player(name="Adventurer", currentRoom=room5)
    
    game = Game(name="Proof of Concept", player=adventurer)

if __name__ == "__main__":
    main()

This is actually the very first proof of concept that I did for writing the engine. Right now, the engine is much more complicated, but this is the basics.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.