<commit_before>#!/usr/bin/env python
# textventure.py
#################
## Textventure ##
## ckjbgames ####
## 2017 #########
#################

## Imports
import random  # Map randomization, eventually
import pickle  # For game saving
import sys     # Various uses
import socket  # Eventually for connections
import _mysql  # For connecting to MySQL
import MySQLdb # Also for MySQL
## Classes
class gameItem(object):
    """
    An in-game item that can
    be used by the player and will
    be placed randomly in the rooms
    Instances are stored in the Inventory class
    Name is the item's name
    Effect should be an instance of the Effect class
    If Uses is set to true, an item lasts forever
    If Uses is set to one, an item has one use, etc.
    Uses should NOT be set to false!
    Description is self-explainatory
    """
    def __init__(self, name = None, effect = None, uses = None, description = None, movable = True, can_hold = True):
        """
        This is just an initialzer with a docstring
        """
        self.name = name
        self.effect = effect
        self.uses = uses
        self.description = description
        self.movable = movable
        self.can_hold = can_hold
    def __repr__(self):
        """
        Prints out an item's attributes in an actually readable format
        See the main docstring for more info on the main attributes
        """
        uses = self.uses
        if uses == True:
            uses = "*lasts forever*"
        template = "\n%s" +\
        "\nEffect:" +\
        "\n%s" +\
        "\nUses:" +\
        "\n%s" +\
        "\nDescription:" +\
        "\n%s"
        return template%(self.name, self.effect, uses, self.description)
    def itemName(self):
        """
        Used for returning only the item's name (for room descriptions and
        inventory listings)
        """
        return self.name
class Inventory(object):
    """
    The player's inventory
    Contains instances of the gameItem class
    """
    def __init__(self):
        """
        Initialize the inventory to an empty list
        """
        self.player_inventory = {}
    def __repr__(self):
        """
        A separate __repr__ method so that all the
        full attributes of each item are not shown
        in the inventory listing.
        Basically a plain old inventory listing
        """
        if self.player_inventory == {}:
            eggs = "You're not carrying anything."
        else:
            eggs = ''
            for spam in self.player_inventory:
                eggs = eggs + '\n' + spam.itemName()
        return eggs
    def addItem(self, item_to_add):
        """
        Adds an item to the inventory
        item_to_add should be an instance of
        the gameItem class
        """
        self.player_inventory[item_to_add.itemName()] = item_to_add
    def viewItem(self,item_name):
        """
        View an item in the inventory
        Should be the name of an item
        """
        try:
            return self.player_inventory[item_name]
        except (NameError, KeyError):
            return "You don't have that item!"
class Room(object):
    """
    A room with a description, other rooms that it leads to,
    and contents
    name is self-explainatory
    items_room is a dictionary containing instances of the gameItem class that are in a room
    If items_room is set to false, the room contains no items.
    description is also self-explainatory
    in_room is a flag for if you are in the room or not
    """
    def __init__(self, name = None, items_room = False, description = None, in_room = False):
        """
        Initializes attributes described in the main docstring
        """
        self.name = name
        self.items_room = items_room
        self.description = description
        self.in_room = in_room
class allRooms(object):
    """
    A map-type arrangement of all rooms as a 2-dimensional list/array
    More effective than having a really, really complicated
    initializer method for the Room class
    The player will never actually view this unless they have a map
    There is a __repr__ method in case they do
    """
    def __init__(self, rooms = [],coords = (0,0)):
        """
        Initializer method
        rooms should be a list containing other lists, which
        should be a combination of instances of Room and
        the False value
        See the main docstring for more info
        """
        self.rooms = rooms
        self.coords = coords
        if self.rooms[self.coords[0]][self.coords[1]].in_room != True:
            self.rooms[self.coords[0]][self.coords[1]].in_room = True
    def __repr__(self):
        """
        Kind of displays a map
        # - A room, but you are not in it
        Space - There is no room here
        @ - You are here
        """
        map_of = ''<commit_msg>Deleted an if statement<commit_after>#!/usr/bin/env python
# textventure.py
#################
## Textventure ##
## ckjbgames ####
## 2017 #########
#################

## Imports
import random  # Map randomization, eventually
import pickle  # For game saving
import sys     # Various uses
import socket  # Eventually for connections
import _mysql  # For connecting to MySQL
import MySQLdb # Also for MySQL
## Classes
class gameItem(object):
    """
    An in-game item that can
    be used by the player and will
    be placed randomly in the rooms
    Instances are stored in the Inventory class
    Name is the item's name
    Effect should be an instance of the Effect class
    If Uses is set to true, an item lasts forever
    If Uses is set to one, an item has one use, etc.
    Uses should NOT be set to false!
    Description is self-explainatory
    """
    def __init__(self, name = None, effect = None, uses = None, description = None, movable = True, can_hold = True):
        """
        This is just an initialzer with a docstring
        """
        self.name = name
        self.effect = effect
        self.uses = uses
        self.description = description
        self.movable = movable
        self.can_hold = can_hold
    def __repr__(self):
        """
        Prints out an item's attributes in an actually readable format
        See the main docstring for more info on the main attributes
        """
        uses = self.uses
        if uses == True:
            uses = "*lasts forever*"
        template = "\n%s" +\
        "\nEffect:" +\
        "\n%s" +\
        "\nUses:" +\
        "\n%s" +\
        "\nDescription:" +\
        "\n%s"
        return template%(self.name, self.effect, uses, self.description)
    def itemName(self):
        """
        Used for returning only the item's name (for room descriptions and
        inventory listings)
        """
        return self.name
class Inventory(object):
    """
    The player's inventory
    Contains instances of the gameItem class
    """
    def __init__(self):
        """
        Initialize the inventory to an empty list
        """
        self.player_inventory = {}
    def __repr__(self):
        """
        A separate __repr__ method so that all the
        full attributes of each item are not shown
        in the inventory listing.
        Basically a plain old inventory listing
        """
        if self.player_inventory == {}:
            eggs = "You're not carrying anything."
        else:
            eggs = ''
            for spam in self.player_inventory:
                eggs = eggs + '\n' + spam.itemName()
        return eggs
    def addItem(self, item_to_add):
        """
        Adds an item to the inventory
        item_to_add should be an instance of
        the gameItem class
        """
        self.player_inventory[item_to_add.itemName()] = item_to_add
    def viewItem(self,item_name):
        """
        View an item in the inventory
        Should be the name of an item
        """
        try:
            return self.player_inventory[item_name]
        except (NameError, KeyError):
            return "You don't have that item!"
class Room(object):
    """
    A room with a description, other rooms that it leads to,
    and contents
    name is self-explainatory
    items_room is a dictionary containing instances of the gameItem class that are in a room
    If items_room is set to false, the room contains no items.
    description is also self-explainatory
    in_room is a flag for if you are in the room or not
    """
    def __init__(self, name = None, items_room = False, description = None, in_room = False):
        """
        Initializes attributes described in the main docstring
        """
        self.name = name
        self.items_room = items_room
        self.description = description
        self.in_room = in_room
class allRooms(object):
    """
    A map-type arrangement of all rooms as a 2-dimensional list/array
    More effective than having a really, really complicated
    initializer method for the Room class
    The player will never actually view this unless they have a map
    There is a __repr__ method in case they do
    """
    def __init__(self, rooms = [],coords = (0,0)):
        """
        Initializer method
        rooms should be a list containing other lists, which
        should be a combination of instances of Room and
        the False value
        See the main docstring for more info
        """
        self.rooms = rooms
        self.coords = coords
    def __repr__(self):
        """
        Kind of displays a map
        # - A room, but you are not in it
        Space - There is no room here
        @ - You are here
        """
        map_of = ''
{'fraction_non_alphanumeric': 0.08625168866257923, 'fraction_numerical': 0.0018705185493089473, 'mean_word_length': 2.07968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2588413', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2542, 'n_words': 1044}