view gamelib/gamestate.py @ 16:af1bfeb648cb

Sketch in gamestate
author Neil Muller <drnlmuller@gmail.com>
date Sun, 06 May 2012 17:12:40 +0200
parents
children 296ce36fa7d9
line wrap: on
line source

# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4

"""The actual game state object"""

from gamelib import missions, lab, products


class Game(object):

    def __init__(self):
        self.lab = lab.Lab()
        # FIXME: Generate the initial tech set
        self.money = 1000
        # Will be updated on the next turn
        self.points = 0
        self.reputation = 0
        # instantiate the available missions
        self.missions = [cls() for cls in missions.Mission.__subclasses__()]
        # Missions being attempted
        self.cur_missions = []
        # Science allocation for the current turn
        self.cur_allocation = []

    def start_turn(self):
        # Make more flexible?
        self.points += 3
        self.cur_missions = []
        self.cur_allocation = []

    def get_available_equipment(self):
        """Return a list of equipment we can produce and afford"""
        available = [x for x in lab.science
                if isinstance(x, products.Product) and x.COST <= self.money]
        return available

    def end_turn(self):
        # Attempt the missions
        mission_results = []
        for mission, equipment in self.cur_missions:
            mission_results.appned(mission.attempt(equipment, self))
        # Do the science
        self.points -= len(self.cur_allocation)
        if self.points < 0:
            raise RuntimeError('Spent too many points')
        new_stuff = self.lab.spend_points(self.cur_allocation, self.points)
        # Process mission results
        for result in mission_results:
            result.apply(self)
        # Update the science state with result of spend_points
        for science in new_stuff:
            self.lab.science.append(science)
        # FIXME: Update UI