Exemplo n.º 1
0
    def gen_feature_dict(self):
        """
            iterates through all the room files.  Collects all the aliases
            for feature 1 and feature 2.  puts them into a dict 
            {
            alias: feature 1 official title
            alias: feature 2 official title
            }
            writes that out to the feature_dict file in /data
        """
        feature_dir = room_info().get_feature_dict_dir()
        room_dir = room_info().get_dir()
        rooms = room_info().get_titles()
        features_dict = OrderedDict()
        room = OrderedDict()

        #open all the room files and gather up each features aliases
        for title in rooms:
            new_dir = os.path.join(room_dir, title)
            with open(new_dir, 'r') as room_file:
                room = json.load(room_file, object_pairs_hook=OrderedDict)
                room_file.close()
            for feature in room['features']:
                feature_1 = room["features"][feature]['title']
                features_dict.update({feature_1:feature_1})
                aliases_1 = room["features"][feature]['aliases']

                for alias in aliases_1:
                    if alias not in features_dict:
                        features_dict.update({alias:feature_1})

        with open(feature_dir, 'w') as features_file:
            json.dump(features_dict, features_file, indent=1)
            features_file.close()
        print("Done making features alias dict")
Exemplo n.º 2
0
    def add_exit_alias(self, title, alias):
        """
            given a room title and alias
            adds the alias if it does not exist to all room files that hold
            the room passed in as a possible exit
            and generates the exit dict file upon exit

        """
        room_connections = room_info().get_connection_list()
        room_dir = room_info().get_dir()

        if title not in room_connections:
            print 'Invalid room name'
            return
        for key, value in room_connections.items():
            if title in value:
                #if the room has a connection to our desired room
                #open the room with the connection
                new_dir = os.path.join(room_dir, key)
                with open(new_dir, 'r') as room_file:
                    room_data = json.load(room_file, object_pairs_hook=OrderedDict)
                    room_file.close()
                #the title we passed in is the key of the dict in connected_rooms
                room = room_data['connected_rooms'][title]
                if alias not in room['aliases']:
                    room['aliases'].append(alias)
                    print("Added alias:"+alias+" to room:"+title+" in file:"+key)
                    #if we are adding data overwrite the previous room file
                    with open(new_dir, 'w') as room_file:
                        json.dump(room_data, room_file, indent=1)
                        room_file.close()
                else:
                    print 'Alias already exists'
        update().gen_exit_dict()
Exemplo n.º 3
0
    def gen_exit_dict(self):
        """
            generates the alias files for room names.  used in the 
            connected_room field of the room file in the possible exits
            and their aliases
            writes the dict to file in /data
        """
        room_dir = room_info().get_dir()
        room_titles = room_info().get_titles()

        exits = OrderedDict()
        try:
            with open(room_info().get_dir_dict(), 'r') as exit_file:
                exits = json.load(exit_file, object_pairs_hook=OrderedDict)
                exit_file.close()
        except Exception, e:
            pass
Exemplo n.º 4
0
def make_rooms():
    rooms = room_info()
    room_titles = rooms.get_titles()
    room_titles = ["cave"]
    room_connections = rooms.get_connection_amount()
    for room in room_titles:
        room_dir = "../data/rooms"
        room_template = create_room(room, room_titles.index(room),
                                    room_connections[room_titles.index(room)])
        room_dir = os.path.join(room_dir, room)
        with open(room_dir, 'w') as outfile:
            json.dump(room_template, outfile, indent=4)
            outfile.close()
Exemplo n.º 5
0
    def add_feature_alias(self):
        """
            asks the user for the room and the feature, then the alias to add
            opens the room file, gets the appropriate feature. adds the alias to
            the feature if it does not exist
            closes the files
            DOES NOT regenerate the features_dict
        """
        room_title = raw_input("Enter offical room title where feature is located: ")
        feature_title = raw_input("Enter feature title: ")
        alias = self.get_alias()
        room_dir = room_info().get_dir()
        room_titles = room_info().get_titles()
        result = "Added " + alias + " to " + feature_title + " in room " + room_title

        if room_title in room_titles:
            new_dir = os.path.join(room_dir, room_title)
            with open(new_dir, 'r') as room_file:
                room = json.load(room_file, object_pairs_hook=OrderedDict)
                room_file.close()
                if feature_title in room['features']:
                    if alias not in room['features'][feature_title]['aliases']:
                        room['features'][feature_title]['aliases'].append(alias)
                        result = alias + " added to room " + room_title + "'s " + feature_title
                        with open(new_dir, 'w') as room_file:
                            json.dump(room, room_file, indent = 1)
                            room_file.close()

                    else:
                        result = alias + " already exists"
                else:
                    result = "Feature does not exist"
        else:
            result = "Room does not exist"

        print(result)
Exemplo n.º 6
0
class update():
    def gen_exit_dict(self):
        """
            generates the alias files for room names.  used in the 
            connected_room field of the room file in the possible exits
            and their aliases
            writes the dict to file in /data
        """
        room_dir = room_info().get_dir()
        room_titles = room_info().get_titles()

        exits = OrderedDict()
        try:
            with open(room_info().get_dir_dict(), 'r') as exit_file:
                exits = json.load(exit_file, object_pairs_hook=OrderedDict)
                exit_file.close()
        except Exception, e:
            pass

        room_file_exits = []

        #sync room files to rooms_dict
        for room in room_titles:
            new_dir = os.path.join(room_dir, room)
            with open(new_dir, 'r') as infile:
                room = json.load(infile, object_pairs_hook=OrderedDict)
                connected_rooms = room["connected_rooms"]
                for conn in connected_rooms:
                    connection = room['connected_rooms'][conn]
                    for alias in connection["aliases"]:
                        room_file_exits.append(alias)
                        if alias not in exits:
                            exits.update({alias:connection["title"]})
                infile.close()

        #sync the rooms_dict to all possible room aliases so we don't get out of sync
        for exit in exits:
            if exit not in room_file_exits:
                print(exit + " not found in list of room exits, removing.")
                del exits[exit]
                

        exits = OrderedDict(sorted(exits.items()))

        with open(room_info().get_dir_dict(), 'w') as outfile:
            json.dump(exits, outfile, indent = 1)
            outfile.close()
        print("Done making exits alias dictionary")
Exemplo n.º 7
0
Group Members - Emily Caveness, Alexander Laquitara, Johannes Pikel
Class - CS467-400 Capstone
Term - Fall 2017
Description - Allows the adding of aliases and creating the dict files
of all aliases, for room/exits, verbs, and features
"""


import json
from collections import OrderedDict
from name_lists import room_info
from name_lists import item_info
from name_lists import verb_info
import os

ROOM_TITLES = room_info().get_titles()

class update():
    def gen_exit_dict(self):
        """
            generates the alias files for room names.  used in the 
            connected_room field of the room file in the possible exits
            and their aliases
            writes the dict to file in /data
        """
        room_dir = room_info().get_dir()
        room_titles = room_info().get_titles()

        exits = OrderedDict()
        try:
            with open(room_info().get_dir_dict(), 'r') as exit_file:
Exemplo n.º 8
0
def create_room(room_name, index, connections):
    """
        returns OrderedDict that is the room structure in json
    """
    connection_titles = room_info().get_connection_list()
    room_template = OrderedDict()
    room_template.update({"id": index + 1})
    room_template.update({"title": room_name})
    room_template.update({"visited": False})
    room_template.update(
        {"long_description": "Long Description: " + room_name})
    room_template.update(
        {"short_description": "Short Description: " + room_name})
    room_template.update({
        "features": {
            "1": {
                "title": "feature_1_title",
                "aliases": ["feature_1_aliases"],
                "verbs": {
                    "look at": {
                        "description":
                        "look at description for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "use": {
                        "description":
                        "use description for feature 1 " + room_name,
                        "deactivate_description":
                        "use deactivate for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "eat": {
                        "description":
                        "eat description for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "pull": {
                        "description":
                        "pull description for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "read": {
                        "description": "read for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "search": {
                        "description": "read for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "take": {
                        "description": "take for feature 1 " + room_name,
                        "modifiers": {}
                    },
                    "drop": {
                        "description": "drop for feature 1" + room_name,
                        "modifiers": {}
                    }
                }
            },
            "2": {
                "title": "feature_2_title",
                "aliases": ["feature_2_aliases"],
                "verbs": {
                    "look at": {
                        "description":
                        "look at description for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "use": {
                        "description":
                        "use description for feature 2 " + room_name,
                        "deactivate_description":
                        "use deactivate for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "eat": {
                        "description":
                        "eat description for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "pull": {
                        "description":
                        "pull description for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "read": {
                        "description": "read for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "search": {
                        "description": "read for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "take": {
                        "description": "take for feature 2 " + room_name,
                        "modifiers": {}
                    },
                    "drop": {
                        "description": "drop for feature 2" + room_name,
                        "modifiers": {}
                    }
                }
            }
        }
    })
    room_template.update({
        "connected_rooms": [{
            connection_titles[room_name][0]: {
                "id": 0,
                "title": connection_titles[room_name][0],
                "aliases": [connection_titles[room_name][0]],
                "compass_direction": "",
                "item_required": False,
                "item_required_title": "",
                "pre_item_description": "",
                "accessible": True,
                "distance_from_room": 1,
            }
        }]
    })
    for x in range(0, connections):
        room_template["connected_rooms"].append({
            connection_titles[room_name][x]: {
                "id": 0,
                "title": connection_titles[room_name][x],
                "aliases": [connection_titles[room_name][x]],
                "compass_direction": "",
                "item_required": False,
                "item_required_title": "",
                "pre_item_description": "",
                "accessible": True,
                "distance_from_room": 1,
            }
        })
    room_template.update({"items_in_room": []})
    room_template.update({"feature_searched": False})
    room_template.update({"room_hazards": False})
    room_template.update({"room_hazard_description": ""})
    room_template.update({"room_hazard_item": ""})
    room_template.update({"room_hazard_occurs_description": ""})
    room_template.update({"room_hazard_attributes_affected": ""})
    room_template.update({"room_hazard_safe_description": ""})

    return room_template
Exemplo n.º 9
0
the save game and load game when it comes to moving the files into their appropriate
locations for use by the game engine.
"""
#from __future__ import print_function
import shutil  #for file handling
import json
import os
import logging
import sys
from collections import OrderedDict
from name_lists import save_info
from name_lists import room_info
from name_lists import item_info

IGNORE = ["TempSaveGame.md", "Rooms.md", "Items.md"]
ROOM_TITLES = room_info().get_titles()
ITEM_TITLES = item_info().get_titles()
ROOM_DIR = room_info().get_dir()
TEMP_ROOM_DIR = save_info().get_temp_save_dir_rooms()
ITEM_DIR = item_info().get_dir()
TEMP_ITEM_DIR = save_info().get_temp_save_dir_items()
SAVE_DIR = save_info().get_save_dir()
SAVE_ROOM_DIR = save_info().get_save_dir_rooms()
SAVE_ITEM_DIR = save_info().get_save_dir_items()
DEBUG_SAVE_LOAD = 0


def new_game():
    """
    First cleans both the rooms and items folders in the temporary save
    directory.  Then copies the original template files from