Exemplo n.º 1
0
class Room:
    def __init__(self, x, y):
        self.width = x
        self.length = y
        emptyTile = Tile()
        self.map = [[emptyTile] for i in range(x)]
        for i in range(x):
            for j in range(1, y):
                self.map[i].append(emptyTile)
        self.inventory = Inventory()

    def addTile(self, tile, x, y):
        tile.setLocation([x, y])
        self.map[x][y] = tile

    def getTile(self, x, y):
        return self.map[x][y]

    def nameTile(self, name, x, y):
        self.map[x][y].setName(name)

    def getMap(self):
        return self.map

    def printMap(self):
        y = self.length - 1
        x = self.width - 1
        for i in range(self.width):
            for j in range(self.length):
                print(x, y, " : ", self.map[x][y].getName())
                y -= 1
            print("\n")
            y = self.length - 1
            x -= 1

    def putItem(self, item):
        self.inventory.addItem(item)

    def takeItem(self, item_name):
        return self.inventory.removeItem(item_name)
Exemplo n.º 2
0
class Tile:
    def __init__(self):
        self.name = 'Empty'
        self.location = [0, 0]
        self.description = ''
        self.inventory = Inventory()
        self.north = False
        self.east = False
        self.south = False
        self.west = False

    def getName(self):
        return self.name

    def setName(self, name):
        self.name = name

    def setDescription(self, description):
        self.description = description

    def getDescription(self):
        return self.description

    def setLocation(self, location):
        self.location = location

    def getLocation(self):
        return self.location

    def makePath(self, direction):
        if direction == "n": self.north = True
        if direction == "e": self.east = True
        if direction == "s": self.south = True
        if direction == "w": self.west = True
        if direction == "all":
            self.north = True
            self.east = True
            self.south = True
            self.west = True

    def clearPath(self, direction):
        if direction == "n": self.north = False
        if direction == "e": self.east = False
        if direction == "s": self.south = False
        if direction == "w": self.west = False
        if direction == "all":
            self.north = False
            self.east = False
            self.south = False
            self.west = False

    def checkPath(self, direction):
        if direction == "n": return self.north
        if direction == "e": return self.east
        if direction == "s": return self.south
        if direction == "w": return self.west

    def putItem(self, item):
        self.inventory.addItem(item)

    def takeItem(self, item_name):
        return self.inventory.takeItem(item_name)

    def lookForThings(self):
        self.inventory.showItems()
Exemplo n.º 3
0
class Player:

    def __init__(self):
        self.name = 'nobody'
        self.alive = True
        self.inventory = Inventory()
        self.map = None
        self.location = [0,0]

    def killPlayer(self):
        self.alive = False

    def revivePlayer(self):
        self.alive = True

    def namePlayer(self, name):
        self.name = name

    def putPlayer(self, room, x, y):
        self.map = room
        self.location = [x, y]

    def getLocation(self):
        return(self.location)

    def movePlayer(self, direction):
        if self.map == None: return False
        start_tile = self.map.getTile(self.location[0], self.location[1])
        if direction == "n" and start_tile.checkPath("n"):
            self.location[1] += 1
            return True
        if direction == "e" and start_tile.checkPath("e"):
            self.location[0] += 1
            return True
        if direction == "s" and start_tile.checkPath("s"):
            self.location[1] -= 1
            return True
        if direction == "w" and start_tile.checkPath("w"):
            self.location[0] -= 1
            return True
        return False

    def printScene(self):
        print(self.map.getTile(self.location[0], self.location[1]).getDescription())

    def lookForThings(self):
        self.map.getTile(self.location[0], self.location[1]).lookForThings()

    def pickUp(self, item_name):
        item = self.map.getTile(self.location[0], self.location[1]).takeItem(item_name)
        if item:
            self.inventory.addItem(item)

    def putDown(self, item_name):
        item = self.inventory.removeItem(item_name)
        if item: self.map.getTile(self.location[0], self.location[1]).putItem(item)

    def consume(self, item_name):
        return self.inventory.removeItem(item_name)

    def transmute(self, item_name, new_item):
        self.inventory.removeItem(item_name)
        self.inventory.addItem(new_item)


    '''