예제 #1
0
def play():
    world.load_tiles()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            if player.hp < player.maxhp:
                player.hp += 1

            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)

            action_input = input('Action: ')
            print()
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break

        if not player.is_alive():
            print('You are dead.')
예제 #2
0
 def room_inventory(self):
     # Prints room inventory
     item_number = 1
     room = world.tile_exists(self.location_x, self.location_y)
     print('*****    Area Items    *****')
     if len(room.room_inventory) == 0:
         # Returns if no items
         print("There's nothing here. Cold and empty like this world.\n")
         return
     for item in room.room_inventory:
         print('(', item_number, ')', item, '\n')
         item_number += 1
     # Loot item prompts and validations
     user_input = mod_input_validation.yes_or_no('Would you like to take any items?(y/n)')
     if user_input == 'n':
         return
     if user_input == 'y':
         room = world.tile_exists(self.location_x, self.location_y)
         selection = mod_input_validation.item_select('Select item to take (0 to exit):', len(room.room_inventory))
         if selection == 0:
             return
         else:
             # Pick up item from current room
             loot = room.room_inventory[int(selection) - 1]
             print('You picked up a', loot)
             self.inventory.append(loot)
             mod_sound_effects.inventory_pickup()
             # Removes from room inventory
             del room.room_inventory[int(selection) - 1]
     self.room_inventory()
예제 #3
0
파일: tiles.py 프로젝트: riz5034/PSU
    def adjacent_moves(self):
        """Returns all move actions for adjacent tiles."""
        moves = []
        if world.tile_exists(self.x + 1, self.y):
            moves.append(actions.MoveEast())
        if world.tile_exists(self.x - 1, self.y):
            moves.append(actions.MoveWest())
        if world.tile_exists(self.x, self.y + 1):
            moves.append(actions.MoveSouth())

        # Modify room to allow player to enter Upper Class Area
        if self.blackouts == 2:
            display.slow_print("""
        Jack tells the guards he needs to go through to continue his
        search, but the they tell him to search around town first.
            """)
            if self.nonUpperClassRooms == self.playerVisits:
                if world.tile_exists(self.x, self.y - 1):
                    moves.append(actions.MoveNorth())
                display.slow_print("""
        After telling the guards that the missing piece is not in town,
        the guards exclaim, "You may pass".
                """)
            else:
                display.slow_print("""
        You must leave.
                """)

        return moves
예제 #4
0
def play():
    world.load_tiles()

    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    #    print(room.tile_name())
    #    print vars(room)
    print room.room_name()
    print room.intro_text()

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            #            print("Choose an action:\n")
            available_actions = room.available_actions()
            room.exits_text()
            #            print exits
            for action in available_actions:
                print (action)
            #            print " "
            action_input = raw_input("\tWhat would you like to do? :")
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #5
0
def play():
	world.load_tiles()
	player = Player()
	room = world.tile_exists(player.location_x, player.location_y)
	print(room.intro_text())
	while player.is_alive() and not player.victory:
		room = world.tile_exists(player.location_x, player.location_y)
		room.modify_player(player)
		# Check again since the room could have changed the player's state
		if player.is_alive() and not player.victory:
			if player.hp < player.maxhp:
				player.hp += 1

			print("Choose an action:\n")
			available_actions = room.available_actions()
			for action in available_actions:
				print(action)

			action_input = input('Action: ')
			print()
			for action in available_actions:
				if action_input == action.hotkey:
					player.do_action(action, **action.kwargs)
					break

		if not player.is_alive():
			print('You are dead.')
예제 #6
0
def play():
    colorama.init()
    scale = world.load_tiles()
    player = Player()
    # initialize an empty world map to the scale returned from loading
    # the world tiles
    player.worldMap = [[' X ' for x in range(scale[0])]
                       for y in range(scale[1])]
    room = world.tile_exists(player.location_x, player.location_y)
    player.updateMap(room)
    print(Fore.WHITE, end='\r')
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        player.updateMap(room)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print(Fore.RED + Back.WHITE + "Choose an action")
            available_actions = room.available_actions()
            print(Fore.GREEN + Back.BLACK, end='\r')
            for action in available_actions:
                print(action)
            print(Fore.RED, end='\r')
            action_input = input('Action: ')
            print(Fore.WHITE, end='\r')
            os.system("cls")
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
    if not player.is_alive():
        print("You have died!")
예제 #7
0
def play():
    world.setup()
    player = Player()

    print """
	This is a text adveture game."""

    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    while not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        available_actions = room.available_actions(player)

        print "Here are your available actions in this room:"
        for action in available_actions:
            print(action)
        print

        action_input = raw_input('Action: ')
        valid_action = False
        for action in available_actions:
            if action_input == action.name:
                valid_action = action
        if valid_action:
            player.room = room
            player.do_action(valid_action, **action.kwargs)
        else:
            print "I didn't get that, please try again."
예제 #8
0
파일: game.py 프로젝트: jddaly2011/adv.py
def play():
    world.load_tiles()
#    pcs = npcs()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
#    print(room.tile_name())
#    print vars(room)
    print room.room_name()
    print room.intro_text()
    
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
#            print("Choose an action:\n")
            available_actions = room.available_actions()
            room.exits_text()
#            print exits
            # for action in available_actions:
            #      print(action)
#            print " "
            action_input = raw_input('\tWhat would you like to do? :')
            action_input = parse_translate(action_input)
#            print action_input
            action_parser(action_input, available_actions, player, room)
예제 #9
0
def play():

    world.parse_world_dsl()  # load tiles
    player = Player()

    #These lines load the starting room and display the text
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())

    while player.is_alive() and not player.victory:
        #Loop begins here
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)

        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input('Action: ')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #10
0
def play():
    world.load_tiles()
    player = Player()
    # Load starting room and display text
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # check if room has changed player state
        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input("Action: ")
            print("")
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
        elif not player.is_alive() and not player.victory:
            print("""
            You have been slain!
            The life force pours out from your body
            and you are left to wonder what you did wrong.     
                  """)
예제 #11
0
def play():

    world.load_tiles()
    Player = player()
    room = world.tile_exists(Player.location_x, Player.location_y)
    print(room.intro_text())

    while Player.is_alive() and not Player.victory:
        room = world.tile_exists(Player.location_x, Player.location_y)
        room.modify_player(Player)
        # Check again since the room could have changed the player's state

        if Player.is_alive() and not Player.victory:
            print("\nChoose an action:\n")
            available_actions = room.available_actions()

            # if isinstance(room, tiles.trader_room):
            #     available_actions.append(actions.Trade())

            for action in available_actions:
                print(action)
            action_input = input(
                '===================================\nAction: ')

            for action in available_actions:
                if action_input == action.hotkey:
                    Player.do_action(action, **action.kwargs)
                    break
예제 #12
0
def play():
    world.load_tiles()
    
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
#    print(room.tile_name())
#    print vars(room)
    print room.room_name()
    print room.intro_text()
    
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
#            print("Choose an action:\n")
            available_actions = room.available_actions()
            room.exits_text()
#            print exits
            for action in available_actions:
                 print(action)
#            print " "
            action_input = raw_input('\tWhat would you like to do? :')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #13
0
def play():
    world.load_tiles()
    player = Player()
    #These lines load the starting room and display the text
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input('Action: ')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break

    if not player.is_alive():
        print("--------------------------------------------------")
        print(
            "The enemy has defeated you. Maybe you need a stroner weapon. Try again."
        )
예제 #14
0
def play():
    world.load_tiles()
    #    pcs = npcs()
    global player
    global room

    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)

    #    print vars(room)
    print room.room_name()
    print room.intro_text()
    if room.inventory is not None:
        for item in room.inventory:
            print "\t{} is here.".format(item.name)
    room.exits_text()
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            #            print("Choose an action:\n")
            global available_actions
            available_actions = room.available_actions()
            Prompt().cmdloop()
예제 #15
0
def play():
    world.load_tiles()
    player = Player()

    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)

        if room.id == CONST.EXIT_TILE_ID:
            player.victory = True

        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)

            action_input = input('Action: ')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #16
0
def play():
    """
    Loop del juego
    """
    print("\n====================================================================")
    world.create_world()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        if player.is_alive() and not player.victory:
            print("\nElegí una acción:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input("\nAcción: ")
            print("====================================================================")
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    if action_input == 'i':
                        print(room.intro_text())
                    break

    if not player.is_alive():
        print("PERDISTE!\nIgual no te preocupes, la princesa estaba en otro castillo")
    elif player.victory:
        print("Lo siento, la princesa esta en otro castillo!")
예제 #17
0
def play():
    world.load_tiles()
#    pcs = npcs()
    global player
    global room

    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    
#    print vars(room)
    print room.room_name()
    print room.intro_text()
    if room.inventory is not None:
        for item in room.inventory:
            print "\t{} is here.".format(item.name)
    room.exits_text()         
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
#            print("Choose an action:\n")
            global available_actions
            available_actions = room.available_actions()
            Prompt().cmdloop()
예제 #18
0
def play():
    world.load_tiles()
    player = Player()
    #These lines load the starting room and display the text
    room = world.tile_exists(player.location_x, player.location_y)
    if room is None:
        room = world.tile_exists(2, 0)
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        #loop that shit
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        #check again since the room could've changed the player's state
        if player.is_alive() and not player.victory:
            #commented this shit out, prints the actions, we want them to guess
            #print("Choose an action:\n")
            available_actions = room.available_actions()
            #for action in available_actions:
            #	print(action)
            action_input = input('Action: ')
            action_found = False
            for action in available_actions:
                #print(action_input, action.hotkey)
                if action_input == action.hotkey:
                    action_found = True
                    player.do_action(action, **action.kwargs)
                    break

            if not action_found:
                print("\nYOU CAN'T DO THAT\n")
예제 #19
0
def play():
    world.load_tiles()
    player = Player()  #creates player as an object of the Player class
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    player.isquit = False
    while player.is_alive() and not player.victory and not player.isquit:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)  #modifies the player based on the room
        if player.is_alive(
        ) and not player.victory:  #checks to see that player is not dead to room actions
            print("Choose an action:")  #edit to change message
            available_actions = room.available_actions(player)
            if player.aa and not player.dr:  #st: aa turns off listing all actions
                for action in available_actions:
                    print(action)  #lists possible actions to player
            if player.dr:  #st: dr lists only directional actions
                partial_actions = room.adjacent_moves()
                for action in partial_actions:
                    print(action)

            action_input = input('Action: ')  #takes action input from player
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #20
0
 def get_dir(self):
     x = 0
     y = 0
     if self.x < self.dest_x and world.tile_exists(self.x + 1, self.y):
         #print "xdir is east"
         xdir = 'east'
         x = 1
     elif self.x > self.dest_x and world.tile_exists(self.x - 1, self.y):
         xdir = 'west'
         x = -1
         #print "xdir is west"
     else:
         xdir = None
         x = 0
         #print "xdir is None"
     if self.y > self.dest_y and world.tile_exists(self.x, self.y -1):
         ydir = "north"
         y = -1
         #print "ydir is north"
     elif self.y <  self.dest_y and world.tile_exists(self.x, self.y +1):
         #print "ydir is south"
         ydir = "south"
         y = 1
     else:
         ydir = None
         #print "ydir is None"
         y = 0
     return x, xdir, y, ydir
예제 #21
0
파일: tiles.py 프로젝트: jddaly2011/adv.py
    def exits_text(self):
        """Returns all move actions for adjacent tiles."""
        exits = []
        if world.tile_exists(self.x + 1, self.y):
            exits.append("east")
        if world.tile_exists(self.x - 1, self.y):
            exits.append("west")
        if world.tile_exists(self.x, self.y - 1):
            exits.append("north")
        if world.tile_exists(self.x, self.y + 1):
            exits.append("south")

        myroom = world.tile_exists(self.x, self.y)
        #        print myroom.room_name()
        if isinstance(myroom, LockedDoorRoom) and not myroom.solved:
            mydoor = myroom.door
            exits.remove(mydoor)

        if len(exits) == 1:
            print "\tThere is an exit to the {}".format(exits[0])
        elif len(exits) == 2:
            print "\tThere are exits to the {} and {}".format(
                exits[0], exits[1])
        elif len(exits) == 3:
            print "\tThere are exits to the {}, {}, and {}".format(
                exits[0], exits[1], exits[2])
        elif len(exits) == 4:
            print "\tThere are exits to the {}, {}, {}, and {}".format(
                exits[0], exits[1], exits[2], exits[3])
        else:
            if isinstance(myroom, Elevator):
                print "\tThe elevator door is closed"

            else:
                print "\tThere appears to be no way out"
예제 #22
0
def play():
    world.load_tiles()
    player = Player()
    #These lines load the starting room and display the textg
    room = world.tile_exists(player.location_x, player.location_y)
    util.printGameText(
        room.intro_text(player))  #Added player to check inventory before text
    print("")
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input('\nAction: ')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
    if player.is_alive() == False:
        sounds.die()
        print("You died.")
예제 #23
0
def eat(player, argument, raw_argument):
    """
    Args:
        player (object): user's player object
        argument (string): lowercase user input past the first word
        raw_argument (string): raw user argument
    Returns:
        N/A but drinks the argument
    """
    for index, item in enumerate(player.inventory):
        if argument in [name.lower() for name in item.name]:
            if isinstance(item, items.Food):
                item.eat()
                del player.inventory[index]
                return
            else:
                print("I wouldn't eat that...")
                return
    for index, item in enumerate(
            world.tile_exists(player.location_x, player.location_y).items):
        if argument in [name.lower() for name in item.name]:
            if isinstance(item, items.Food):
                item.eat()
                del world.tile_exists(player.location_x,
                                      player.location_y).items[index]
                return
            else:
                print("I wouldn't eat that...")
                return

    print("There's no '" + raw_argument +
          "' in your inventory or anywhere nearby.")
    return
예제 #24
0
def game_loop():
	
	world.load_tiles()
	player = Player()
	room = world.tile_exists(player.location_x, player.location_y)
	
	while player.is_alive() and not player.victory:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				quitgame()
	
		#get starting tile for intro text
		#These lines load the starting room and display the text
		room = world.tile_exists(player.location_x, player.location_y)
		print(room)
		room.modify_player(player)
		text = room.intro_text()
		blit_text(screen,text,(40,40),font)
		
		if player.is_alive() and not player.victory:
			
			#put player actions in button format at bottom of the screen
			available_actions = room.available_actions()
			action_list = []
			for action in available_actions:
				action_list.append(action)
			action_text_tile(action_list,player)
			
		update()
예제 #25
0
    def use(self, tile):
        check_item = input('Item to use? ')

        if check_item == "fsm" or check_item == "OwO":
            if not self.fsm:
                self.fsm = True
                print("\n<Developer Mode Active>\n")
            else:
                self.fsm = False
                print("\n<Developer Mode Inactive>\n")

            return

        for i in range(len(self.inventory)):
            if check_item.lower() == self.inventory[i].name.lower():
                if isinstance(self.inventory[i], items.Health):
                    self.hp = self.hp + self.inventory[i].heal
                    print("\n{} used, adding {} health\n".format(
                        self.inventory[i].name, self.inventory[i].heal))
                    del self.inventory[i]
                    return
                elif isinstance(self.inventory[i], items.Key):
                    print(
                        world.tile_exists(self.location_x + 1,
                                          self.location_y).key)
                    print(world.is_locked(0, 0))
                    if world.is_locked(
                            self.location_x + 1, self.location_y
                    ):  #checks to see if the tile exists and if it's locked
                        if world.tile_exists(
                                self.location_x + 1, self.location_y
                        ).key.lower() == self.inventory[i].name.lower(
                        ):  #checks to see if key name is equal to item used
                            world.unlock(self.location_x + 1, self.location_y,
                                         False)  #unlocks
                    if world.is_locked(self.location_x - 1, self.location_y):
                        if world.tile_exists(
                                self.location_x - 1, self.location_y
                        ).key.lower() == self.inventory[i].name.lower():
                            world.unlock(self.locaiton_x - 1, self.location_y,
                                         False)
                    if world.is_locked(self.location_x, self.location_y + 1):
                        if world.tile_exists(
                                self.location_x, self.location_y + 1
                        ).key.lower() == self.inventory[i].name.lower():
                            world.unlock(self.location_x, self.location_y + 1,
                                         False)
                    if world.is_locked(self.location_x, self.location_y - 1):
                        if world.tile_exists(
                                self.location_x, self.location_y - 1
                        ).key.lower() == self.inventory[i].name.lower():
                            world.unlock(self.location_x, self.location_y - 1,
                                         False)

                else:
                    self.inventory[i].use_item()
                    return

        print("\nNo item by that name to use\n")
예제 #26
0
def index():
    """Page for game"""
    # Establish the parameters of the room player is in and what effect it has on him
    room = world.tile_exists(player.location_x, player.location_y)
    if player.is_alive() and not player.victory:
        available_actions = room.available_actions()
        action_input = request.form.get("btn_submit")
        available_hotkeys = []
        # If a button was pushed, match it to the key word for one of the actions and do it
        for action in available_actions:
            available_hotkeys.append(action.hotkey)
            if action_input == action.hotkey:
                player.do_action(action, **action.kwargs)
                # Establish the parameters of the possibly new room player is in and what effect it has on him
                room = world.tile_exists(player.location_x, player.location_y)
                availableactions = room.available_actions()
                # Return relevant data so it can be printed in the HTML
                if player.is_alive() and not player.victory:
                    if action_input == "inventory":
                        return render_template(
                            "index.html",
                            firsttext=room.intro_text(),
                            nexttext=room.modify_player(player),
                            items=player.act,
                            thentext="",
                            availableactions=availableactions,
                            picture=room.getName())
                    else:
                        return render_template(
                            "index.html",
                            firsttext=room.intro_text(),
                            nexttext=room.modify_player(player),
                            items="",
                            thentext=player.act,
                            availableactions=availableactions,
                            picture=room.getName())
                break
        if action_input not in available_hotkeys and action_input is not None:
            return render_template("index.html",
                                   firsttext=room.intro_text(),
                                   nexttext="Please select a valid option",
                                   items="",
                                   thentext="",
                                   picture=room.getName())
    if player.victory or not player.is_alive():
        return render_template("index.html",
                               firsttext=room.intro_text(),
                               nexttext="You must restart",
                               items="",
                               thentext="",
                               picture=room.getName())
    return render_template("index.html",
                           firsttext=room.intro_text(),
                           nexttext=room.modify_player(player),
                           items="",
                           thentext="",
                           picture=room.getName())
예제 #27
0
    def move(self, dx, dy):
        """Move the player in the direction x and y.

        :param dx: The x-coordinate direction to move the player.
        :param dy: The y-coordinate direction to move the player.
        """
        self.location_x += dx
        self.location_y += dy
        world.tile_exists(self.location_x, self.location_y).intro_text()
예제 #28
0
 def adjacent_moves(self):
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth())
예제 #29
0
 def teleport(self):
     print("Teleport to (absolute coords):")
     movetox = int(input('x: '))
     movetoy = int(input('y: '))
     if world.tile_exists(movetox, movetoy):
         self.move(dx=(movetox - self.location_x),
                   dy=(movetoy - self.location_y))
         self.mapinfo(world.tile_exists(movetox, movetoy))
     else:
         print("\ntp: Tile does not exist\n")
 def adjacent_moves(self):
     """Determines what moves are valid in your world"""
     moves = []
     if world.tile_exists(self._x, self._y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self._x, self._y + 1):
         moves.append(actions.MoveSouth())
     if world.tile_exists(self._x + 1, self._y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self._x - 1, self._y):
         moves.append(actions.MoveWest())
     return moves
예제 #31
0
 def adjacent_moves(self):
     """ Devuelve todas las direcciones en las que el jugador puede moverse."""
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth())
     return moves
 def adjacent_moves(self):
     '''Returns all move actions for adjacent tiles'''
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.move_east())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.move_west())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.move_north())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.move_south())
     return moves
예제 #33
0
 def adjacent_moves(self):
     #Returns all move actions based of if there are adjacent tiles
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth())
     return moves
예제 #34
0
	def adjacent_moves(self):
		# tells player all move actions for adjacent tiles (?)
		moves = []
		if world.tile_exists(self.x+1,self.y):
			moves.append(actions.MoveEast())
		if world.tile_exists(self.x-1,self.y):
			moves.append(actions.MoveWest())
		if world.tile_exists(self.x,self.y-1):
			moves.append(actions.MoveNorth())
		if world.tile_exists(self.x,self.y+1):
			moves.append(actions.MoveSouth())  # is that right?
		return moves
예제 #35
0
 def adjacent_moves(self):
     """Retourne les possibilités de déplacements dans les cases adjacentes."""
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth())
     return moves
예제 #36
0
	def adjacent_moves(self):
		"""Returns all move actions for adjacent tiles"""
		moves = []
		if world.tile_exists(self.x + 1, self.y):
			moves.append(actions.MoveEast())
		if world.tile_exists(self.x - 1, self.y):
			moves.append(actions.MoveWest())
		if world.tile_exists(self.x, self.y - 1):
			moves.append(actions.MoveNorth())
		if world.tile_exists(self.x, self.y + 1):
			moves.append(actions.MoveSouth())
		return moves
예제 #37
0
 def adjacent_moves(self):
     """Returns all move actions for adjacent tiles."""
     moves = []
     if world.tile_exists(self.x + 1, self.y) and ('e' in self.directions or not self.locked):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y) and ('w' in self.directions or not self.locked):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1) and ('n' in self.directions or not self.locked):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1) and ('s' in self.directions or not self.locked):
         moves.append(actions.MoveSouth())
     return moves
 def adjacent_moves(self):
     """Returns all move actions for adjacent tiles."""
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth())
     return moves
예제 #39
0
 def adjacent_moves(self):
     """ Devuelve todas las direcciones en las que el jugador puede moverse."""
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth())
     return moves
예제 #40
0
 def adjacent_moves(self):
     #default actions a player can do
     moves = []
     #pdb.set_trace()
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveRight())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveLeft())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveUp())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveDown())
     return moves
예제 #41
0
 def possible_moves(self):
     """
     Returns all possible move actions for adjacent tiles.
     """
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveAstern())
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveFore())
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveAstarboard())
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveAport())
     return moves
예제 #42
0
    def exits(self):
        """Returns all move actions for adjacent tiles."""
        available_exits = []
        if world.tile_exists(self.x + 1, self.y):
            available_exits.append("east")
        
        if world.tile_exists(self.x - 1, self.y):
            available_exits.append("west")
        if world.tile_exists(self.x, self.y - 1):
            available_exits.append("north")
        if world.tile_exists(self.x, self.y + 1):
            available_exits.append("south")

        return available_exits
예제 #43
0
def engine():
    intro = title.choose_title()
    raw_input(intro)
    world.load_tiles()
    player = Player()
    # room_old to make sure a new room intro is given
    room_old = None
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.loc_x, player.loc_y)
        if room is not room_old:
            print room.intro_text()
            room_old = room
        room.alter_player(player)
        if player.is_alive() and not player.victory:
            available_actions = room.available_actions()
            # print '\tChoose from the following actions:'
            # for action in available_actions:
            #     print '\t\t', action.name[0]
            action_in = raw_input('\n\t> ').lower()
            # if action_in == help or other special actions?
            if action_in == 'exit' or action_in == 'quit':
                sys.exit("\n\tSEE YOU SPACE COWBOY...\n")

            for action in available_actions:
                # problem with user just hitting enter?
                if action_in in action.name:
                    player.do_action(action)
                    done = True
                    break
                else:
                    done = False
                    continue

            if not done:
                print "\n\tSorry, I don't know what that means..."
예제 #44
0
def sched(commands, available_actions, player, room):
    print type(commands)
    mapref = world.mapref()
    for k in mapref:
        print k
    print mapref[commands[2]]
    if commands[2] not in mapref:
        print "\t{} is not the name of a room.".format(commands[2])
        return
    destx, desty = mapref[commands[2]]
    
    temp = world.allrooms()
    npclist =[]
    for x, y in temp:
        tmproom= world.tile_exists(x, y)
        if tmproom and tmproom.npcs:
            for npc in tmproom.npcs:
#                if npc.shortnames[0] == commands[1]:
                if commands[1] in npc.shortnames:
                    npc.dest = True
                    # npc.destx = mapref[commands[2][0]]
                    # npc.desty = mapref[commands[2][1]]
                    npc.destx = destx
                    npc.desty = desty
                    print "destination {}, {}".format(npc.destx, npc.desty)
                    return
예제 #45
0
    def default(self, player, world):
        self.moves += 1
        self.check_sked(player, world)
        if self.dest:
            #print self.shortnames[0]
            #print self.x, self.y
            #print self.nd
            this_room = world.tile_exists(self.x, self.y)
            #print this_room.npcs
            if self.x == self.dest_x and self.y == self.dest_y: #we made it
                #print "Trip completed {}, {}".format(self.x, self.y)
                self.nd = {}
                self.dest = None
                return
            if self.moves % 2 != 0: #wait two moves before moving
                #print "WAITING~~"
                return
            else:
                #print "MOVING"
                available_exits = self.exits()
                #print "Exits: {}".format(available_exits)
                x, xdir, y, ydir = self.get_dir()
                
                #print self.nd
                if len(available_exits) == 1:
                    func = "self.move_{}(this_room, player)".format(available_exits[0])
                    exec func                     
                    return
                
                if xdir and (self.x + x, self.y) not in self.last:
                    if xdir in available_exits:
                        func = "self.move_{}(this_room, player)".format(xdir)
                        exec func                     
                        return

                elif ydir and (self.x, self.y + y) not in self.last:
                    if ydir in available_exits:
                        func = "self.move_{}(this_room, player)".format(ydir)
                        exec func                     
                        return
                
                elif xdir and self.nd[(self.x + x, self.y)] < 2:
                    if xdir in available_exits:
                        func = "self.move_{}(this_room, player)".format(xdir)
                        exec func                     
                        return

                elif ydir:
                    if (self.x, self.y + y) in self.nd:
                        #print nd
                        if self.nd[(self.x, self.y + y)] < 2:
                            if ydir in available_exits:
                                func = "self.move_{}(this_room, player)".format(xdir)
                                exec func                     
                                return
                    else:
                        if ydir in available_exits:
                            func = "self.move_{}(this_room, player)".format(xdir)
                            exec func                     
                            return
예제 #46
0
    def move_npc(self, this_room, x, y, player):
        #print "x: {} y: {}".format(x, y)
        this_room.npcs.remove(self)
        new_room = world.tile_exists(self.x + x, self.y + y)
        new_room.npcs.append(self)
        #print this_room.npcs
        self.last.append((self.x, self.y))
        self.update_nd()
        self.x += x
        self.y += y
        #print "new loc {}, {}".format(self.x, self.y)

        if player.location_x == this_room.x and player.location_y == this_room.y:
            if x != 0:
                if x > 0:
                    mydir = "east"
                else:
                    mydir = "west"
            else:
                if y > 0:
                    mydir = "south"
                else:
                    mydir = "north"
                
            print "\t{} leaves the room to the {}.".format(self.name, mydir)
            return
        elif player.location_x == new_room.x and player.location_y == new_room.y:
            #print "entering"

            print "\t{} enters the room.".format(self.name)

            return
        return
예제 #47
0
파일: tiles.py 프로젝트: jddaly2011/adv.py
 def exits_text(self):
     """Returns all move actions for adjacent tiles."""
     exits = []
     if world.tile_exists(self.x + 1, self.y):
         exits.append("east")
     if world.tile_exists(self.x - 1, self.y):
         exits.append("west")
     if world.tile_exists(self.x, self.y - 1):
         exits.append("north")
     if world.tile_exists(self.x, self.y + 1):
         exits.append("south")
     if len(exits) == 1:
         print "\tYou may exit to the {}".format(exits[0])
     elif len(exits) == 2:
         print "\tThere are exits to the {} and {}".format(exits[0], exits[1])
     elif len(exits) == 3:
         print "\tThere are exits to the {}, {}, and {}".format(exits[0], exits[1], exits[2])
     else:
         print "\tThere are exits to the {}, {}, {}, and {}".format(exits[0], exits[1], exits[2], exits[3])
예제 #48
0
파일: ex23.py 프로젝트: Owslla/PyTF
    def adjacent_moves(self):
        """Returns all move actions for adjacent tiles."""
# allows a list to be made with the name 'moves'
        moves = []
# Each 'if' statement tests if a til is present in the given direction
# if True then the direction wil will be appended to the list for latter
# display 'actions' refers to the actions.py class file. x is east/west
# and y is north/south. I'm not sure how it does it. I'll need to look
# at actions.py and world.py
        if world.tile_exists(self.x + 1, self.y):
            moves.append(actions.MoveEast())
        if world.tile_exists(self.x - 1, self.y):
            moves.append(actions.MoveWest())
        if world.tile_exists(self.x, self.y - 1):
            moves.append(actions.MoveNorth())
        if world.tile_exists(self.x, self.y + 1):
            moves.append(actions.MoveSouth())
# displays the moves that are available to the player
        return moves
예제 #49
0
	def adjacent_moves(self):
	#returns all move actions for adjacent tiles
	moves = []
	if world.tile_exists(self.x+1, self.y):
		moves.append(actions.MoveEast())
	if world.tile_exists(self.x - 1, self.y):
        moves.append(actions.MoveWest())
    if world.tile_exists(self.x, self.y - 1):
        moves.append(actions.MoveNorth())
    if world.tile_exists(self.x, self.y + 1):
        moves.append(actions.MoveSouth())
    return moves
	
	def available_actions(self):
		#returns all of the available actions in this room
		moves = self.adjacent_moves()
		moves.append(actions.ViewInventory())
		
		return moves
예제 #50
0
파일: game.py 프로젝트: vickean/textRPG
def play():
    world.load_tiles()
    player = Player()
    # These lines load the starting room and display the text.
    room = world.tile_exists(player.location_x, player.location_y)
    print room.intro_text()
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again as room could have changed the player state
        if player.is_alive() and not player.victory:
            print "Choose an action: \n"
            available_actions = room.available_actions()
            for action in available_actions:
                print action
            action_input = raw_input("Action: ")
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #51
0
def play():
    world.load_tiles()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        #loop starts here
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        #check again bc room could change player state
        if player.is_alive() and not player.victory:
            print("Choose an action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input('Action: ')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #52
0
def play():
	print ("Welcome to Josh's Dungeon Crawler! Currently this is a little game, but it is being worked on as time allows! The game begins below!")
	world.load_tiles()
	player = Player()
	#These lines load the starting room and display the text
	room = world.tile_exists(player.location_x, player.location_y)
	print(room.intro_text())
	while player.is_alive() and not player.victory:
		room = world.tile_exists(player.location_x, player.location_y)
		room.modify_player(player)
		#Check again since the room could have changed the player's state
		if player.is_alive() and not player.victory:
			print("Choose an action:\n")
			available_actions = room.available_actions()
			for action in available_actions:
				print(action)
			action_input = input('Action: ')
			for action in available_actions:
				if action_input == action.hotkey:
					player.do_action(action, **action.kwargs)
					break
예제 #53
0
파일: game.py 프로젝트: wackyzacky42/TxtAdv
def play():
    # Calls the load_tiles() method from the world module, creating the game grid.
    world.load_tiles()
    # Creates a variable named "player" that's an instance of the Player() class in the player module.
    player_one = player.Player()
    # Finds the name of the room at the player's starting location and assigns it to the variable "room".
    room = world.tile_exists(player_one.location_x, player_one.location_y)
    # Prints the intro text for the player's starting room.
    # os.system('cls')
    player_one.print_map(player_one.location_x, player_one.location_y)
    print(room.intro_text())
    # Repeats the game loop as long as the player is alive and hasn't won.
    while player_one.is_alive() and not player_one.victory:
        # Updates the "room" variable based on the player's current location.
        room = world.tile_exists(player_one.location_x, player_one.location_y)
        # Calls the modify_player() method from the room the player is currently in.
        # This applies whatever room effect will hit the player, if any.
        room.modify_player(player_one)
        # Check the While conditions again in case the modify_player() method killed the player
        # or caused them to win.
        if player_one.is_alive() and not player_one.victory:
            # Print out the UI for choosing an action.
            print("Choose an action:")
            print("=================")
            # Finds a list of the available actions in the room the player is currently in.
            available_actions = room.available_actions()
            # Prints all the available actions individually in a list.
            for action in available_actions:
                print(action)
                # Asks for the player's input and assigns it to the "action_input" variable.
            action_input = raw_input("\nAction: ")
            # Loops through all the available actions and compares the player's input
            # to the action's hotkey. If they match, the do_action() method is called to execute the action.
            for action in available_actions:
                if action_input == action.hotkey:
                    player_one.do_action(action, **action.kwargs)
                    break
예제 #54
0
def play():
    world.load_tiles()
    global player
    player = Player()
    global room
    room = world.tile_exists(player.location_x, player.location_y)
    mapref = world.mapref()
    for k in mapref:
        print k
        print mapref[k]
    print type(mapref)

    describe_room(room)

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        loc = [player.location_x, player.location_y]
#        room.modify_player(player)
        if player.is_alive() and not player.victory:
            global available_actions
            available_actions = room.available_actions()
        
            if player.moves > 0:
#                print "Running all rooms NPC default"
                room.default(player)
                temp = world.allrooms()
                npclist =[]
                for x, y in temp:
                    
                    tmproom= world.tile_exists(x, y)
                    if tmproom and tmproom.npcs:
                        for npc in tmproom.npcs:
                            if npc.name not in npclist: #we haven't called default on npc yet for this move
                                npc.default(player, world)
                                npclist.append(npc.name)
                                #print "called default on {}".format(npc.name)
        Prompt().cmdloop()
예제 #55
0
파일: player.py 프로젝트: jddaly2011/adv.py
    def move(self, dx, dy):
        self.location_x += dx
        self.location_y += dy
#        print self.location_x, self.location_y
        

        #print (world.tile_exists(self.location_x, self.location_y))
        room = world.tile_exists(self.location_x, self.location_y)

        print room.room_name()
        print room.intro_text()
        if room.inventory is not None:
            for item in room.inventory:
                print "\t{} is here.".format(item.name)
        room.exits_text()
예제 #56
0
def play():
    world.load_tiles()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        if (room in visited) and ('LootRoom' in str(room.__class__.__bases__)):
            pass
        else:
            visited.append(room)
            room.modify_player(player)
        #  check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print('Choose an action:\n')
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input('Action: ')
            print('\n')
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #57
0
def play():
    world.load_tiles()
    player = Player()
    #This line loads the player into the starting room location and displys the room text
    player.move(2,5) # starting location
    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        # Check again since the room could have changed the player's state
        if player.is_alive() and not player.victory:
            print "Choose an action:\n"
            available_actions = room.available_actions()
            for action in available_actions:
                print action
            action_input = str(raw_input("Action: "))
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    break
예제 #58
0
def play():
    world.load_tiles()
    my_character = Character()
    my_character.name = input("Initializing...\n\n\n\n\nAh! Hello\n" +\
        "What is your name, stranger?\n\nCall me ")
    while my_character.is_alive() and not (my_character.victory):
        room = world.tile_exists(my_character.location_x, my_character.location_y)
        room.modify_character(my_character)
        # Check again since the room could have changed the player's state
        if my_character.is_alive() and not my_character.victory:
            print("--------------\n--\n--------------\nChoose an action: " +"\n")
            available_actions = room.available_actions()
            print("room avail actions: %s"%room.name)
            for action in available_actions:
                print(action)
            action_input = input('Action: ')
            for action in available_actions:
                if action_input == action.hotkey:  #see world.tile_exists(x,y).room.available_actions()
                    my_character.do_action(action, **action.kwargs)
                    break
예제 #59
0
import items, enemies, actions, world

class MapTile:
	def __init__(self, x, y):
		self.x = x
		self.y = y
	def intro_text(self):
		raise NotImplementedError()
 
	def modify_player(self, player):
		raise NotImplementedError()
	def adjacent_moves(self):
    """Returns all move actions for adjacent tiles."""
    moves = []
    if world.tile_exists(self.x + 1, self.y):
        moves.append(actions.MoveEast())
    if world.tile_exists(self.x - 1, self.y):
        moves.append(actions.MoveWest())
    if world.tile_exists(self.x, self.y - 1):
        moves.append(actions.MoveNorth())
    if world.tile_exists(self.x, self.y + 1):
        moves.append(actions.MoveSouth())
    return moves
 
	def available_actions(self):
		"""Returns all of the available actions in this room."""
		moves = self.adjacent_moves()
		moves.append(actions.ViewInventory())
 
    return moves	
class StartingRoom(MapTile):
예제 #60
0
 def move(self, dx, dy):
     self.location_x += dx
     self.location_y += dy
     print(world.tile_exists(self.location_x, self.location_y).intro_text())