Пример #1
0
 def __init__(self, element=None, comp=None, scient=None, hexparams=get_hex_params(35)):
     if scient != None:
         Scient.__init__(self, scient.element, scient.comp, scient.name,
                         scient.weapon, scient.weapon_bonus, scient.location)
     else:
         if element == None:
             element = rand_element()
         if comp == None:
             comp = rand_comp(suit=element, kind='Scient')
         Scient.__init__(self, comp=comp, element=element)
     pygame.sprite.Sprite.__init__(self)
     self.hexparams = hexparams
     r,s,hexh,rech,size = self.hexparams
     self.size = size
     self.image = pygame.Surface(size)
     self.image.fill(COLORS[self.element])
     self.image.fill(black)
     if self.weapon.type == 'Sword':
         x = r/2
         y = hexh
         self.rect = pygame.draw.polygon(self.image, COLORS[self.element], [(x, y), (x+s, y), (x+s, y+s), (x, y+s)]) #square
     elif self.weapon.type == 'Bow':
         self.rect = pygame.draw.circle(self.image, COLORS[self.element], ((size[0]/2) + 1, (size[1]/2) + 1), size[0]/2 - hexh/2) # cirlcle
     elif self.weapon.type == 'Wand':
         self.rect  = pygame.draw.polygon(self.image, COLORS[self.element], [(r+1,3), (2*r - 1 , rech-2*hexh), (r+1, rech-3), (2, rech - 2*hexh)])
     elif self.weapon.type == 'Glove':
         self.rect = pygame.draw.polygon(self.image, COLORS[self.element], [(r,2), (2*r-2, rech-hexh-1), (2, rech - hexh-1)]) # triangle
     self.image.set_colorkey(black)
     self.text = []
Пример #2
0
 def _form_scient(self, element, stone_num, name=None):
     """Takes a stone from stronghold and turns it into a Scient."""
     #this should only be done by the production process.
     if name == None: name = rand_string()
     self.units.append(Scient(element, self.stones.pop(stone_num), name))
     self._p_changed = 1
     return transaction.commit()
Пример #3
0
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == 'tile':
        #this obviously dramatically slows down the instanciation of a
        #previously instanciated grid, but when would this be done in real-time?
        if value['contents'] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value['contents'])
            del value['contents']
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == 'grid':
        #It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value['comp']).replace("u'", "'")))
        tiles = {}
        x = value['x']
        y = value['y']
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)

    elif key == 'squad':
        squad = Squad(name=value['name'])
        data = value['data']
        for unit in data:
            squad.append(convert_dict(unit))
        return squad

    elif key == 'scient':
        scient = {}
        scient['element'] = value['element']
        scient['comp'] = value['comp']
        scient['name'] = value['name']
        scient = Scient(**scient)
        if not value['weapon'] == None:
            scient.weapon = convert_dict(value['weapon'])
        if not value['location'] == None:
            scient.location = Loc(value['location'][0], value['location'][1])
        return scient

    elif key == 'nescient':
        nescient = {}
        nescient['element'] = value['element']
        nescient['comp'] = value['comp']
        nescient['name'] = value['name']
        nescient['facing'] = value['facing']
        nescient['body'] = {}
        for part in value['body'].keys():
            nescient['body'][part] = Part(
                None, value['body'][part]['part']['location'])
        nescient = Nescient(**nescient)
        if not value['location'] == None:
            nescient.location = Loc(value['location'][0], value['location'][1])
        return nescient

    elif key == 'player':
        squads = []
        for squad in value['squads']:
            squads.append(convert_dict(squad))
        return Player(value['name'], squads)

    else:
        #for weapons
        return eval(
            key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))
Пример #4
0
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == "tile":
        # this obviously dramatically slows down the instanciation of a
        # previously instanciated grid, but when would this be done in real-time?
        if value["contents"] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value["contents"])
            del value["contents"]
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == "grid":
        # It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value["comp"]).replace("u'", "'")))
        tiles = {}
        x = value["x"]
        y = value["y"]
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value["tiles"][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)

    elif key == "squad":
        squad = Squad(name=value["name"])
        data = value["data"]
        for unit in data:
            squad.append(convert_dict(unit))
        return squad

    elif key == "scient":
        scient = {}
        scient["element"] = value["element"]
        scient["comp"] = value["comp"]
        scient["name"] = value["name"]
        scient = Scient(**scient)
        if not value["weapon"] == None:
            scient.weapon = convert_dict(value["weapon"])
        if not value["location"] == None:
            scient.location = Loc(value["location"][0], value["location"][1])
        return scient

    elif key == "nescient":
        nescient = {}
        nescient["element"] = value["element"]
        nescient["comp"] = value["comp"]
        nescient["name"] = value["name"]
        nescient["facing"] = value["facing"]
        nescient["body"] = {}
        for part in value["body"].keys():
            nescient["body"][part] = Part(None, value["body"][part]["part"]["location"])
        nescient = Nescient(**nescient)
        if not value["location"] == None:
            nescient.location = Loc(value["location"][0], value["location"][1])
        return nescient

    elif key == "player":
        squads = []
        for squad in value["squads"]:
            squads.append(convert_dict(squad))
        return Player(value["name"], squads)

    else:
        # for weapons
        return eval(key.capitalize())(**eval("".join(str(value).replace("u'", "'"))))
Пример #5
0
 def __repr__(self):
     return Scient.__repr__(self)
Пример #6
0
from binary_tactics.defs import Loc
from binary_tactics.units import Scient, Squad, Stone
from stores import yaml_store
from binary_tactics.weapons import *
from stores.store import get_persisted
from stores.yaml_store import *
from copy import deepcopy

sq1 = Squad()
s = Scient('Fire', Stone((2, 4, 0, 2)))
s.equip(Sword('Fire', Stone()))
for n in xrange(3):
    sq1.append(deepcopy(s))

s = Scient('Wind', Stone((0, 2, 2, 4)))
s.equip(Wand('Wind', Stone()))
for n in xrange(2):
    sq1.append(deepcopy(s))

i = Scient('Ice', Stone((2, 0, 4, 2)))
i.equip(Glove('Ice', Stone()))
for n in xrange(3):
    sq1.append(deepcopy(i))

sq0 = deepcopy(sq1)
sq0.name = "pt_0"
sq1.name = "pt_1"
for n in xrange(len(sq0)):
    sq0[n].location = Loc(n + 4, 4)
    sq1[n].location = Loc(n + 4, 11)
yaml.dump(get_persisted(sq0), file('pt_0.yaml', 'w'))
Пример #7
0
from binary_tactics.defs import Loc
from binary_tactics.units import Scient, Squad, Stone
from stores import yaml_store
from binary_tactics.weapons import *
from stores.store import get_persisted
from stores.yaml_store import *
from copy import deepcopy

sq1 = Squad()
s = Scient('Fire', Stone((2,4,0,2)))
s.equip(Sword('Fire', Stone()))
for n in xrange(3):
    sq1.append(deepcopy(s))

s = Scient('Wind', Stone((0,2,2,4)))
s.equip(Wand('Wind', Stone()))
for n in xrange(2):
    sq1.append(deepcopy(s))

i = Scient('Ice', Stone((2,0,4,2)))
i.equip(Glove('Ice', Stone()))
for n in xrange(3):
    sq1.append(deepcopy(i))

sq0 = deepcopy(sq1)
sq0.name = "pt_0"
sq1.name = "pt_1" 
for n in xrange(len(sq0)):
    sq0[n].location = Loc(n+4, 4)
    sq1[n].location = Loc(n+4, 11)
yaml.dump(get_persisted(sq0), file('pt_0.yaml', 'w'))
Пример #8
0
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == 'tile':
        #this obviously dramatically slows down the instanciation of a
        #previously instanciated grid, but when would this be done in real-time?
        if value['contents'] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value['contents'])
            del value['contents']
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == 'grid':
        #It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value['comp']).replace("u'", "'")))
        tiles = {}
        x = value['x']
        y = value['y']
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)
        
    elif key == 'squad':
        squad = Squad(name=value['name'])
        data = value['data']
        for unit in data:
            squad.append(convert_dict(unit))
        return squad
    
    elif key == 'scient':
        scient = {}
        scient['element'] = value['element']
        scient['comp'] = value['comp']
        scient['name'] = value['name']
        scient = Scient(**scient)
        if not value['weapon'] == None:
            scient.weapon = convert_dict(value['weapon'])
        if not value['location'] == None:
            scient.location = Loc(value['location'][0], value['location'][1])
        return scient
    
    elif key == 'nescient':
        nescient = {}
        nescient['element'] = value['element']
        nescient['comp'] = value['comp']
        nescient['name'] = value['name']
        nescient['facing'] = value['facing']
        nescient['body'] = {}
        for part in value['body'].keys():
            nescient['body'][part] = Part(None, value['body'][part]['part']['location'])
        nescient = Nescient(**nescient)
        if not value['location'] == None:
            nescient.location = Loc(value['location'][0], value['location'][1])
        return nescient
    
    elif key == 'player':
        squads = []
        for squad in value['squads']:
            squads.append(convert_dict(squad))
        return Player(value['name'], squads)
    
    else:
        #for weapons
        return eval(key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))