def __init__(self):
        """
        
        """
        super(TaskRunner, self).__init__()
        # Attributes:
        self._state_stack = None  # ([State])

        self.running = True
        self._tasks = []  # [(prio, instance)]
        self._task_updates = []

        self.return_data = None

        self.gametime = GameTime()
Beispiel #2
0
def generateBasisPaths(projectConfig, analyzerLocation):
    """Demonstrates how to generate the :class:`~gametime.path.Path` objects
    that represent the basis paths of the code specified in a GameTime project
    configuration, represented by a
    :class:`~gametime.projectConfiguration.ProjectConfiguration` object.

    The function saves the information from the :class:`~gametime.path.Path`
    objects to different files in a temporary directory called `analysis`,
    created in the directory that contains the code being analyzed.
    The :class:`~gametime.analyzer.Analyzer` object that is used for analysis
    is saved to the location provided.

    Arguments:
        projectConfig:
            :class:`~gametime.projectConfiguration.ProjectConfiguration`
            object that represents the configuration of a GameTime project.
        analyzerLocation:
            Location where the :class:`~gametime.analyzer.Analyzer` object
            will be saved.
    """
    # Create a new :class:`~gametime.analyzer.Analyzer` object
    # for this analysis.
    analyzer = GameTime.analyze(projectConfig)

    # Generate a list of the :class:`~gametime.path.Path` objects that
    # represent the basis paths of the code specified in the XML file.
    basisPaths = analyzer.generateBasisPaths()

    # To keep the filesystem clean, create a directory for the basis paths
    # within the temporary directory called `analysis`. Write
    # the information contained in the :class:`~gametime.path.Path` objects
    # to this directory.
    analysisDir = os.path.join(projectConfig.locationOrigDir, "analysis")
    basisDir = os.path.join(analysisDir, "basis")
    createDir(basisDir)
    analyzer.writePathsToFiles(paths=basisPaths,
                               writePerPath=False,
                               rootDir=basisDir)

    # Save the analyzer for later use.
    analyzer.saveToFile(analyzerLocation)
Beispiel #3
0
from item import Item, HealingItem, DirtPlotEffector
from monster import Monster

from plant import Plant, Seed, CompletedPlant, plantGrades
from garden import Garden
from gametime import GameTime
import events
from fieldOffice import FieldOffice
from pets import PetEgg, Pet

import os
import updater
import json

player = Player()
gT = GameTime()
#seeds = {}

#    TODO: make more seeds/plants in seeds.json;
# TODO: go through JSON -> seed -> plant -> CompletePlant process and check for bugs;
#TODO: Add pet functionality; supplement gardening gameplay
#TODO: Make bounty hunting more viable
#TODO: add some sort of reward for rare plants (rudimentary exhibitions? maybe an internet forum :D!!);
#TODO: debug all inputs;
#TODO: make EVERYTHING more intuitive (write guide? maybe just for this beta)
#TODO: make universal, contextual tutorial() function to explain the particular context's actions


def createWorld():

    bedtime = events.SleepEvent(
Beispiel #4
0
    def __init__(self, parent):
        self.parent = parent
        self.entities = {}
        self.colonists = []
        self.animals = []
        self.items = []
        self.families = []
        self.event_hours = [8, 20]

        self.time_frame = TimeFrame(self)
        self.time = GameTime(self)

        self.register_items = {
            "wood":
            colony.Item(self, name="Wood", stack_size=100),
            "stone":
            colony.Item(self, name="Stone", stack_size=100),
            # Iron
            "ore_iron":
            colony.Item(self, name="Iron Ore", stack_size=100),
            "ingot_iron":
            colony.Item(self, name="Iron Ingot", stack_size=100),
            # Marble
            "crushed_marble":
            colony.Item(self, name="Crushed Marble", stack_size=100),
            "brick_marble":
            colony.Item(self, name="Marble Bricks", stack_size=100),
            # Limestone
            "crushed_limestone":
            colony.Item(self, name="Crushed Limestone", stack_size=100),
            "brick_limestone":
            colony.Item(self, name="Limestone Bricks", stack_size=100)
        }

        self.register_animals = {
            "cat":
            colony.Animal(self, species="Cat", tame_chance=80, highest_age=10),
            "babirusa":
            colony.Animal(self,
                          species="Babirusa",
                          tame_chance=30,
                          highest_age=10),

            # Extinct
            "castoroides":
            colony.Animal(self,
                          species="Castoroides",
                          tame_chance=20,
                          highest_age=23),
            "dodo":
            colony.Animal(self, species="Dodo", tame_chance=20, highest_age=7)
        }

        self.register_resources = {
            "tree":
            colony.Resource(self,
                            name="Tree",
                            health=50,
                            resource=self.register_items["wood"],
                            resource_amount=50),
            "marble":
            colony.Resource(self,
                            name="Marble",
                            health=80,
                            resource=self.register_items["crushed_marble"],
                            resource_amount=1,
                            type_="Rock"),
            "limestone":
            colony.Resource(self,
                            name="Limestone",
                            health=80,
                            resource=self.register_items["crushed_limestone"],
                            resource_amount=1,
                            type_="Rock")
        }

        self.canvas = self.parent.canvas
        self.canvas.configure(background="light gray")
        self.canvas.bind("<Configure>", self.draw_widgets, "+")
        self.game_area = tk.Canvas(self.canvas,
                                   width=self.parent.game_width + 1,
                                   height=self.parent.game_height + 1,
                                   scrollregion=(0, 0, self.parent.game_width,
                                                 self.parent.game_height))

        self.grid_dictionary = {}

        # self.selected_entity = None
        self.selected_entity = []

        self.selected_tool = None
        self.select_area = None
        self.game_area.bind("<Button-1>", self.check_tool, "+")
        self.game_area.bind("<ButtonRelease-3>", self.reset_tool, "+")
        self.game_area.bind("<Motion>", self.select_grid_cell, "+")

        self.game_scrollbar_x = ttk.Scrollbar(self.parent,
                                              orient="horizontal",
                                              command=self.game_area.xview)
        self.game_scrollbar_y = ttk.Scrollbar(self.parent,
                                              command=self.game_area.yview)
        self.game_area.configure(xscrollcommand=self.game_scrollbar_x.set,
                                 yscrollcommand=self.game_scrollbar_y.set)

        self.colonist_bar = ColonistBar(self)
        self.taskbar = TaskBar(self.parent, self)
        self.debug = DeBug(self)

        self.draw_widgets()
        self.draw_grid()
class TaskRunner(object):
    """
    Class TaskRunner
    """

    def __init__(self):
        """
        
        """
        super(TaskRunner, self).__init__()
        # Attributes:
        self._state_stack = None  # ([State])

        self.running = True
        self._tasks = []  # [(prio, instance)]
        self._task_updates = []

        self.return_data = None

        self.gametime = GameTime()

    def _set_denied(self, val):
        raise "task attribute is read only!"

    def add_task(self, task, prio, attr_name=None):
        """
        A task is an instance that must have a method called update(gdt, gt, rt).
        They will we run in priority order, smaller prio is excecuted first.
        If two tasks have same prio then it depends on the order you add them.
        If attr_name already exists then it is overridden.
        """
        task_ = (prio, task, attr_name)
        self._tasks.append(task_)
        self._tasks.sort()
        self._task_updates = [task_[1].update for task_ in self._tasks]
        if attr_name:
            setattr(TaskRunner, attr_name, property(lambda self: task, TaskRunner._set_denied))

    def remove_task(self, task=None, attr_name=None):
        """
        
        """
        if task:
            idxes = [idx for idx, tas in enumerate(self._tasks) if tas[1] == task]
            dx = 0
            for idx in idxes:
                deltask = self._tasks.pop(idx - dx)
                self._task_updates.pop(idx - dx)
                dx += 1
                if deltask[2]:
                    delattr(TaskRunner, deltask[2])
        elif attr_name:
            self.remove_task(getattr(self, attr_name, None))
        else:
            # TODO: make it a log entry
            import warnings

            warnings.warn("Scene.remove_task: either task or attr_name must be given!")

    def init(self, *args, **kwargs):
        """
        To be overridden.
        Called automatically by run() method.
        """
        print "init scene", self, id(self)
        pass

    def quitting(self):
        """
        To be overridden.
        Called when main loop is left.
        """
        print "quitting scene", self, id(self)
        pass

    def run(self, *args, **kwargs):
        """
        The args and kwargs are passe to the init() method.
        """
        global current_scene
        global scenes
        current_scene = self
        scenes.append(self)
        self.init(*args, **kwargs)
        while self.running:
            gdt, gt, rt = self.gametime.update()
            [update(gdt, gt, rt) for update in self._task_updates]
        self.quitting()
        scenes.pop()
        if len(scenes):
            current_scene = scenes[-1]
        else:
            current_scene = None
        return self.return_data