Beispiel #1
0
    def add_implied_barriers(self, x, y):

        [status, text] = self.check_north(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'north':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'north':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('n'))

        [status, text] = self.check_south(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'south':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'south':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('s'))

        [status, text] = self.check_east(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'east':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'east':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('e'))

        [status, text] = self.check_west(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'west':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'west':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('w'))
Beispiel #2
0
class World:  # I choose to define the world as a class. This makes it more straightforward to import into the game.
    map = [[
        TopLeft(barriers=[barriers.Wall('n')]),
        TopMiddle(barriers=[barriers.Wall('n')]),
        DoorEntrance(barriers=[barriers.Wall('n'),
                               barriers.Door('e')]),
        DoorExit(barriers=[barriers.Wall('n')]),
        FusionCannon(barriers=[barriers.Wall('n'),
                               barriers.Wall('e')],
                     items=[items.FusionCannon()]),
        SpaceTile(),
        SpaceTile(),
        SpaceTile(),
        SpaceTile(),
        SpaceTile()
    ],
           [
               Nail(items=[items.Nail()]),
               ShipTile(),
               Hammer(barriers=[barriers.Wall('e')], items=[items.Hammer()]),
               Cortex(barriers=[barriers.Wall('w')], items=[items.Cortex()]),
               R2Blank(barriers=[barriers.Wall('e')]),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               BottomLeft(barriers=[barriers.Wall('w'),
                                    barriers.Wall('s')]),
               MiddleLeft(barriers=[barriers.Wall('s')]),
               HatchEntrance(barriers=[
                   barriers.Wall('e'),
                   barriers.Wall('s'),
                   barriers.HatchDoor('e')
               ]),
               HatchExit(barriers=[barriers.Wall('w'),
                                   barriers.Wall('s')]),
               R2Blank(barriers=[barriers.Wall('e'),
                                 barriers.Wall('s')]),
               SpaceTile(),
               SpaceTile(),
               wormHole(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               wormHole(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               wormHole(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               wilkinsTile(barriers=[barriers.Wall('w'),
                                     barriers.Wall('n')],
                           npcs=[NPC.Wilkins()]),
               EmptySpace(barriers=[barriers.Wall('n')]),
               EmptySpace(barriers=[barriers.Wall('e'),
                                    barriers.Wall('n')]),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               EmptySpace(barriers=[barriers.Wall('w')]),
               EmptySpace(),
               groundNPC(
                   barriers=[barriers.Wall('e')],
                   enemies=[enemies.Invader(loot=[items.Sparkling_Gem()])]),
               SpaceTile(barriers=[
                   barriers.Asteroid('w'),
                   barriers.Asteroid('n'),
                   barriers.Asteroid('s')
               ]),
               SpaceTile(
                   barriers=[barriers.Asteroid('n'),
                             barriers.Asteroid('s')]),
               SpaceTile(),
               SpaceTile(barriers=[barriers.Asteroid('e')]),
               SpaceTile(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               EmptySpace(barriers=[barriers.Wall('w')], npcs=[NPC.Riddler()]),
               EmptySpace(),
               EmptySpace(barriers=[barriers.Wall('e')]),
               SpaceTile(barriers=[barriers.pWall('w')]),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               groundNPC(barriers=[barriers.Wall('e'),
                                   barriers.Wall('s')],
                         enemies=[enemies.Invader()]),
               planetEntrance(),
               merchantTile(barriers=[barriers.Wall('e'),
                                      barriers.Wall('s')],
                            npcs=[NPC.Merchant()]),
               SpaceTile(barriers=[barriers.pWall('w')]),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile()
           ],
           [
               SpaceTile(),
               SpaceTile(barriers=[barriers.pWall('go')]),
               SpaceTile(barriers=[barriers.pWall('a'),
                                   barriers.pWall('n')]),
               SpaceTile(barriers=[barriers.pWall('a')]),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile(),
               SpaceTile()
           ]]

    def __init__(self):
        for i in range(
                len(self.map)
        ):  # We want to set the x, y coordinates for each tile so that it "knows" where it is in the map.
            for j in range(
                    len(self.map[i])
            ):  # I prefer to handle this automatically so there is no chance that the map index does not match
                if (self.map[i][j]):  # the tile's internal coordinates.
                    self.map[i][j].x = j
                    self.map[i][j].y = i

                    self.add_implied_barriers(
                        j, i
                    )  # If there are implied barriers (e.g. edge of map, adjacent None room, etc.) add a Wall.

    def tile_at(self, x, y):
        if x < 0 or y < 0:
            return None
        try:
            return self.map[y][x]
        except IndexError:
            return None

    def check_north(self, x, y):
        for enemy in self.map[y][x].enemies:
            if (enemy.direction == 'north'):
                return [False, enemy.check_text()]
        for barrier in self.map[y][x].barriers:
            if (barrier.direction == 'north' and not barrier.passable):
                return [False, barrier.description()]

        if y - 1 < 0:
            room = None
        else:
            try:
                room = self.map[y - 1][x]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the north."]
        else:
            return [False, "There doesn't seem to be a path to the north."]

    def check_south(self, x, y):
        for enemy in self.map[y][x].enemies:
            if (enemy.direction == 'south'):
                return [False, enemy.check_text()]
        for barrier in self.map[y][x].barriers:
            if (barrier.direction == 'south' and not barrier.passable):
                return [False, barrier.description()]

        if y + 1 < 0:
            room = None
        else:
            try:
                room = self.map[y + 1][x]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the south."]
        else:
            return [False, "There doesn't seem to be a path to the south."]

    def check_west(self, x, y):
        for enemy in self.map[y][x].enemies:
            if (enemy.direction == 'west'):
                return [False, enemy.check_text()]
        for barrier in self.map[y][x].barriers:
            if (barrier.direction == 'west' and not barrier.passable):
                return [False, barrier.description()]

        if x - 1 < 0:
            room = None
        else:
            try:
                room = self.map[y][x - 1]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the west."]
        else:
            return [False, "There doesn't seem to be a path to the west."]

    def check_east(self, x, y):
        for enemy in self.map[y][x].enemies:
            if (enemy.direction == 'east'):
                return [False, enemy.check_text()]
        for barrier in self.map[y][x].barriers:
            if (barrier.direction == 'east' and not barrier.passable):
                return [False, barrier.description()]

        if x + 1 < 0:
            room = None
        else:
            try:
                room = self.map[y][x + 1]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the east."]
        else:
            return [False, "There doesn't seem to be a path to the east."]

    def add_implied_barriers(self, x, y):

        [status, text] = self.check_north(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'north':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'north':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('n'))

        [status, text] = self.check_south(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'south':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'south':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('s'))

        [status, text] = self.check_east(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'east':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'east':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('e'))

        [status, text] = self.check_west(x, y)
        barrier_present = False
        if (not status):
            for enemy in self.map[y][x].enemies:
                if enemy.direction == 'west':
                    barrier_present = True
            for barrier in self.map[y][x].barriers:
                if barrier.direction == 'west':
                    barrier_present = True
            if (not barrier_present):
                self.map[y][x].add_barrier(barriers.Wall('w'))

    def update_rooms(self, player):
        for row in self.map:
            for room in row:
                if (room):
                    room.update(player)
Beispiel #3
0
class World:									# I choose to define the world as a class. This makes it more straightforward to import into the game.
	map = [
		[Corridor(barriers = [barriers.LockedDoor('e')]),			NearVictory(barriers = [barriers.Wall('s')]),				VictoryTile(),																																										Corridor(barriers = [barriers.Wall('w')]), 											Corridor()],
		[ExpanseNW(),												ExpanseNE(barriers = [barriers.Wall('n')]),	 				Nook(barriers = [barriers.Wall('n'), barriers.Wall('s'), barriers.Wall('e')]), 		Corridor(barriers = [barriers.Wall('e'), barriers.Wall('w')]),									Corridor(barriers = [barriers.Wall('w')])],
		[ExpanseSW(),												ExpanseSE(barriers = [barriers.Wall('s')]), 				Corridor(barriers = [barriers.Wall('n'), barriers.Wall('s')]), 																														Corridor(barriers = [barriers.Wall('e'), barriers.Wall('s')]),		 				Corridor(barriers = [barriers.Wall('w')])],
		[None,														Corridor(barriers = [barriers.Wall('n')]),					StartTile(barriers = [barriers.Wall('s'), barriers.Wall('n')]), 																													Corridor(barriers = [barriers.Wall('n')]), 											Corridor()],
		[None,														Corridor(barriers = [barriers.WoodenDoor('e')]),			StoreRoom(barriers = [barriers.Wall('n')]),																																			None,																				None]
	]

	def __init__(self):
		for i in range(len(self.map)):			# We want to set the x, y coordinates for each tile so that it "knows" where it is in the map.
			for j in range(len(self.map[i])):	# I prefer to handle this automatically so there is no chance that the map index does not match
				if(self.map[i][j]):				# the tile's internal coordinates.
					self.map[i][j].x = j
					self.map[i][j].y = i

					self.add_implied_barriers(j,i)	# If there are implied barriers (e.g. edge of map, adjacent None room, etc.) add a Wall.


	def tile_at(self, x, y):
		if x < 0 or y < 0:
			return None
		try:
			return self.map[y][x]
		except IndexError:
			return None

	def check_north(self, x, y):
		for barrier in self.map[y][x].barriers:
			if(barrier.direction == 'north' and not barrier.passable):
				return [False, barrier.description()]

		if y-1 < 0:
			room = None
		else:
			try:
				room = self.map[y-1][x]
			except IndexError:
				room = None

		if(room):
			return [True, "You head to the north."]
		else:
			return [False, "There doesn't seem to be a path to the north."]

	def check_south(self, x, y):
		for barrier in self.map[y][x].barriers:
			if(barrier.direction == 'south' and not barrier.passable):
				return [False, barrier.description()]

		if y+1 < 0:
			room = None
		else:
			try:
				room = self.map[y+1][x]
			except IndexError:
				room = None

		if(room):
			return [True, "You head to the south."]
		else:
			return [False, "There doesn't seem to be a path to the south."]

	def check_west(self, x, y):
		for barrier in self.map[y][x].barriers:
			if(barrier.direction == 'west' and not barrier.passable):
				return [False, barrier.description()]

		if x-1 < 0:
			room = None
		else:
			try:
				room = self.map[y][x-1]
			except IndexError:
				room = None

		if(room):
			return [True, "You head to the west."]
		else:
			return [False, "There doesn't seem to be a path to the west."]

	def check_east(self, x, y):
		for barrier in self.map[y][x].barriers:
			if(barrier.direction == 'east' and not barrier.passable):
				return [False, barrier.description()]

		if x+1 < 0:
			room = None
		else:
			try:
				room = self.map[y][x+1]
			except IndexError:
				room = None

		if(room):
			return [True, "You head to the east."]
		else:
			return [False, "There doesn't seem to be a path to the east."]

	def add_implied_barriers(self, x, y):

		[status, text] = self.check_north(x,y)
		barrier_present = False
		if(not status):
			for barrier in self.map[y][x].barriers:
				if barrier.direction == 'north':
					barrier_present = True
			if(not barrier_present):
				self.map[y][x].add_barrier(barriers.Wall('n'))

		[status, text] = self.check_south(x,y)
		barrier_present = False
		if(not status):
			for barrier in self.map[y][x].barriers:
				if barrier.direction == 'south':
					barrier_present = True
			if(not barrier_present):
				self.map[y][x].add_barrier(barriers.Wall('s'))

		[status, text] = self.check_east(x,y)
		barrier_present = False
		if(not status):
			for barrier in self.map[y][x].barriers:
				if barrier.direction == 'east':
					barrier_present = True
			if(not barrier_present):
				self.map[y][x].add_barrier(barriers.Wall('e'))

		[status, text] = self.check_west(x,y)
		barrier_present = False
		if(not status):
			for barrier in self.map[y][x].barriers:
				if barrier.direction == 'west':
					barrier_present = True
			if(not barrier_present):
				self.map[y][x].add_barrier(barriers.Wall('w'))
Beispiel #4
0
class World:  # I choose to define the world as a class. This makes it more straightforward to import into the game.
    map = [
        [
            Corridor(barriers=[barriers.Wall('e'),
                               barriers.Wall('n')]),
            NearVictory(barriers=[barriers.Wall('s')]),
            VictoryTile(),
            Corridor(barriers=[barriers.Wall('w')]),
            Corridor()
        ],
        [
            None,
            ExpanseNE(barriers=[barriers.Wall('n')]),
            Corridor(barriers=[barriers.Wall('e'),
                               barriers.Wall('w')]),
            Corridor(barriers=[barriers.Wall('e'),
                               barriers.Wall('w')]),
            Corridor(barriers=[barriers.Wall('w')])
        ],
        [
            EarthElementTile(barriers=[barriers.Wall('n'),
                                       barriers.Wall('s')]),
            Corridor(barriers=[barriers.Wall('n'),
                               barriers.Wall('s')]),
            StartTile(),
            Corridor(barriers=[barriers.Wall('n'),
                               barriers.Wall('s')]),
            Corridor(barriers=[barriers.Wall('w')])
        ],
        [
            None, None,
            Corridor(barriers=[barriers.Wall('e'),
                               barriers.Wall('w')]),
            Corridor(barriers=[barriers.Wall('n')]),
            Corridor()
        ],
        [
            Nook(),
            Corridor(barriers=[barriers.WoodenDoor('w')]),
            Corridor(barriers=[barriers.Wall('w')]), None, None
        ]
    ]

    #StoreRoom(barriers = [barriers.Wall('n')], items = [items.RustySword("A rusty sword is propped against the wall.")]), >> how to items/barriers

    def __init__(self):
        for i in range(
                len(self.map)
        ):  # We want to set the x, y coordinates for each tile so that it "knows" where it is in the map.
            for j in range(
                    len(self.map[i])
            ):  # I prefer to handle this automatically so there is no chance that the map index does not match
                if (self.map[i][j]):  # the tile's internal coordinates.
                    self.map[i][j].x = j
                    self.map[i][j].y = i

    def tile_at(self, x, y):
        if x < 0 or y < 0:
            return None
        try:
            return self.map[y][x]
        except IndexError:
            return None

    def check_north(self, x, y):
        for barrier in self.map[y][x].contents['barriers']:
            if (barrier.direction == 'north' and not barrier.passable):
                return [False, barrier.description()]

        if y - 1 < 0:
            room = None
        else:
            try:
                room = self.map[y - 1][x]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the north."]
        else:
            return [False, "There doesn't seem to be a path to the north."]

    def check_south(self, x, y):
        for barrier in self.map[y][x].contents['barriers']:
            if (barrier.direction == 'south' and not barrier.passable):
                return [False, barrier.description()]

        if y + 1 < 0:
            room = None
        else:
            try:
                room = self.map[y + 1][x]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the south."]
        else:
            return [False, "There doesn't seem to be a path to the south."]

    def check_west(self, x, y):
        for barrier in self.map[y][x].contents['barriers']:
            if (barrier.direction == 'west' and not barrier.passable):
                return [False, barrier.description()]

        if x - 1 < 0:
            room = None
        else:
            try:
                room = self.map[y][x - 1]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the west."]
        else:
            return [False, "There doesn't seem to be a path to the west."]

    def check_east(self, x, y):
        for barrier in self.map[y][x].contents['barriers']:
            if (barrier.direction == 'east' and not barrier.passable):
                return [False, barrier.description()]

        if x + 1 < 0:
            room = None
        else:
            try:
                room = self.map[y][x + 1]
            except IndexError:
                room = None

        if (room):
            return [True, "You head to the east."]
        else:
            return [False, "There doesn't seem to be a path to the east."]