コード例 #1
0
def move(target):
    message = ""
    success = False
    if target in sql.get_rooms():
        target_room_id = sql.get_room_id(target)
        adjacent_rooms = sql.get_adjacent_rooms(player.location)
        if target_room_id in adjacent_rooms:
            player.location = target_room_id
            message = 'Moved to the {0}'.format(format_room(target))
            success = True
        else:
            message = "You can't move there from this room!"

    elif target in sql.get_all_directions():
        available_directions = sql.get_available_directions(player.location)
        if target in available_directions:
            player.location = sql.get_room_in_direction(
                player.location, target)
            message = 'Moved to the {0}'.format(
                format_room(sql.room_name_from_id(player.location)))
            success = True
        else:
            message = "You try to go in that direction and hit your face against the wall, ouch!"

    else:
        message = "That is not somewhere you can go!"

    return (success, message)
コード例 #2
0
def ask_other(target1, target2):
	target = target1 or target2

	if target in sql.get_rooms():
		destination_id = sql.room_id_from_name(target)
	
		if destination_id == player.location:
			message = "You are already there!"
	
		else:
			path = sql.find_path(player.location, destination_id)	
			npcs = sql.live_npcsid_in_room(player.location)
			if len(npcs) > 0:
				name = format_npc(sql.npc_name_from_id(random.choice(npcs)))
				message = "{0} tells you the way:\n".format(name)
				for item in path:
					room_name = format_room(sql.room_name_from_id(item[0]))
					direction = sql.to_long_direction(item[1])
					message += "@i\t{0:20} {1}\n".format(room_name, direction)
			else:
				room_name = format_room(sql.room_name_from_id(path[0][0]))
				message = "There's no one here to help you, but you feel you should go first to the {0}.".format(room_name)
				
	elif target in sql.all_npcs():
		
		target_alive = target in sql.live_npcs()
		target_present = target in sql.npcs_in_room(player.location)
		player_has_clue = sql.npc_id_from_name(target) in sql.column_as_list(sql.run_query("SELECT DISTINCT victim FROM player_clue;"), 0)

		if target1:
			if target_alive and target_present:
				message = "Who do you want to ask about from {0}?".format(format_npc(target))
				
			elif not target_present and (target_alive or not player_has_clue):
				message = "{0} is not here. Go ask somebody else.".format(format_npc(target))
			
			elif not target_alive and target_present:
				message = "You see {0} dead on ground. They don't say anything.".format(format_npc(target))
			
			elif not target_alive and not target_present and player_has_clue:
				message = "{0} is not here. As well as not alive.".format(format_npc(target))
		
		else:	
			message = "Whom do you want to ask about {0}?".format(format_npc(target))
	
	elif target in sql.get_all_directions():
	
		target = sql.to_long_direction(target)
		if target1:
			if  target == 'up':
				if sql.room_name_from_id(player.location) in ['front yard', 'back yard']:
					target = 'sky'
				else:
					target = 'ceiling'
			elif target == 'down':
				target = 'floor'
			message = "{0} doesn't tell you anything.".format(target.title())
		else:
			message = "But... Why? Don't do that."
	
	elif target in sql.get_specials():
		if target == 'notes':
			message = "You keep notes of clues you have collected. Type 'memo' or 'notes' to view them."
	
	else:
		message == "This is secret development question. You shold not ever again ask it."
	
	return message


	
	
	
	
	
	
コード例 #3
0
	
def print_all(messages):
	for item in messages:
		fprint (item)
		print()



	
## VOCABULARY =================================================================
# Get verbs and prepositions from database
verbs = sql.get_verbs()
prepositions = sql.get_prepositions()

# Get targets as well. Also store them in invidual arrays to further parse commands. 
rooms = sql.get_rooms()

# sql.get_npcs returns a list where [0] is first names and [1] is last names
sql_npcs = sql.get_npcs_names()
first_names = sql_npcs [0]
last_names = sql_npcs [1]
npcs = sql.all_npcs()

# sql.get_directions returns list, [0] is shortcut, [1] is full name
directions = sql.get_directions()
short_directions = directions [0]
long_directions = directions [1]
directions = short_directions + long_directions

specials = sql.get_specials()
targets = rooms + npcs + directions + specials
コード例 #4
0
def look(target):

    live_npcsid_in_room = sql.live_npcsid_in_room(player.location)
    dead_npcsid_in_room = sql.dead_npcsid_in_room(player.location)
    arrested = arrested_npcs()
    escaped = escaped_npcs()

    message = ""
    if (target in sql.get_rooms()):

        room_id = sql.get_room_id(target)
        if (room_id == player.location):
            message = look_around()
            if message == None:
                message = "{0} is rather nice.".format(target)
        else:
            message = "You cannot see there from here."

    elif (target in sql.all_npcs()):

        target_id = sql.npc_id_from_name(target)
        if (target_id in live_npcsid_in_room):

            message = single_npc_description(target_id)

            details = single_npc_details(target_id)
            if len(details) > 0:
                message += "\nYou immediately notice these striking details about them:"
                for detail in details:
                    message += "\n@i\t{0}".format(detail)

        elif (target_id in dead_npcsid_in_room):
            message = "Here lies the dead body of " + format_npc(
                target) + ". How sad indeed..."

        elif (target_id in arrested):
            message = "They've already been arrested and taken away."

        elif (target_id in escaped):
            message = "Oh no looks like they've escaped."

        else:
            message = "They're not here."

    elif (target in sql.get_all_directions()):
        room_in_direction = sql.get_room_in_direction(player.location, target)
        if room_in_direction:
            room_name = format_room(sql.room_name_from_id(room_in_direction))
            message = "You see the {0} in {1}.".format(
                room_name, sql.long_direction(target))
        else:
            message = "There's some tastefully arranged interior art there. Very apprecietable!"

    elif target == 'notes':
        notes = sql.get_notes()
        message = "NOTES:\n"
        if len(notes) > 0:
            for entry in notes:
                if entry[3]:
                    message += "\nSOLVED" + expired_colour
                victim_name = format_npc(sql.npc_name_from_id(entry[0]))
                room_name = format_room(sql.room_name_from_id(entry[1]))
                message += "\n{0} was killed in the {1}.".format(
                    victim_name, room_name)
                if entry[2]:
                    message += " Clues about their killer:"
                    for item in entry[2]:
                        message += "\n@i\t{0}".format(
                            sql.detail_name_from_id(item))

                if entry[3]:
                    message += default_colour
                message += "\n"

            # Slice away last newline
            message = message[:-1]

        else:
            message += "@i\tno notes yet"

    elif (target == 'hell'):
        message = "Looks like you looked right into your future."

    else:
        message = "Why would you look at that?"

    return message