コード例 #1
0
ファイル: hex.py プロジェクト: duelafn/tabletop-traders
        super(Hex,self).__init__(**kwargs)
        self.map.bind(unit=self.on_change_unit)
        self.map.bind(x=self.on_change_pos,y=self.on_change_pos)

    def on_change_unit(self, obj, unit):
        self.width  = SQRT3 * unit
        self.height = 2 * unit
        self.rel_pos = self.map.address2local(self.i, self.j, size=self.size)
        self.on_change_pos(self,1)

    def on_change_pos(self, obj, unit):
        self.x = self.map.x_off + self.rel_pos[0]
        self.y = self.map.y_off + self.rel_pos[1]


tttraders_kv("hex.kv")


# Gold, Wood, Wheat, Sheep, Stone, Brick
# Paper, Cloth, Coin
class DesertHex(Hex):
    pass
register_hex("Desert", DesertHex)

class FarmlandHex(Hex):
    pass
register_hex("Farmland", FarmlandHex)

class ForestHex(Hex):
    pass
register_hex("Forest", ForestHex)
コード例 #2
0
ファイル: newgame.py プロジェクト: duelafn/tabletop-traders
from ttlib.ttsettingint import TTSettingInt

from tttraders import tttraders_kv, tttraders_user_conf
from tttraders.tradersgame import TradersGame


class NewGame(AnchorLayout):
    app = ObjectProperty(None)
    config = ObjectProperty(None)
    settings = ObjectProperty(None)

    def __init__(self, **kwargs):
        super(NewGame, self).__init__(**kwargs)
        self.config = ConfigParser()
        self.config.read(tttraders_user_conf('tttraders.ini'))

        self.settings.register_type("int", TTSettingInt)

        for tab in TradersGame.ConfigTabs:
            lst  = TradersGame.Config[tab]
            for c in lst:
                if c.get("key", None):
                    self.config.adddefaultsection(c['section'])
                    self.config.setdefault(c['section'], c['key'], c.get("default", None))
            self.settings.add_json_panel(tab, self.config, data=json.dumps(lst))


Factory.register("NewGame", NewGame)
tttraders_kv("newgame.kv")
コード例 #3
0
ファイル: __init__.py プロジェクト: duelafn/tabletop-traders
                if last_state != self.states[-1]:
                    print("remove_state: Re-entering state", self.states[-1])
                    self.dispatch("on_current_state_"+self.states[-1])
            else:
                self.step_phase()
        else:
            raise Exception("Attempt to remove non-existant state "+state)

    def step_phase(self):
        new_turn = False
        if self.phases:
            self.phase = self.phases.pop()
            print("step_phase: Entering phase", self.phase)
        else:
            self.new_turn()
        self.dispatch("on_step_phase")

    def next_turn(self):
        self.current_player_nr = (self.current_player_nr + 1) % self.nr_players
        print("next_turn:", self.current_player_nr)
        self.phases = TradersGame.Phases.reversed()
        self.phase = self.phases.pop()
        self.dispatch("on_new_turn")


import tttraders.tradersgame.base
import tttraders.tradersgame.core

Factory.register("TradersGame", TradersGame)
tttraders_kv("tradersgame.kv")
コード例 #4
0
ファイル: map.py プロジェクト: duelafn/tabletop-traders
        """Returns local screen coordinates of addresss (i,j).
        If size is specified, coordinates will be offset by half of the size."""
        # print( str((i,j)), "at xy =", str(self.hexmap.address2xy(i, j)) )
        pos = self._unit2local( *self.hexmap.address2xy(i, j) )
        return [ pos[0] - size[0] / 2, pos[1] - size[1] / 2 ]

    def address2screen(self, i, j, size=(0,0)):
        """Returns absolute screen coordinates of addresss (i,j).
        If size is specified, coordinates will be offset by half of the size."""
        # print( str((i,j)), "at xy =", str(self.hexmap.address2xy(i, j)) )
        pos = self._unit2screen( *self.hexmap.address2xy(i, j) )
        return [ pos[0] - size[0] / 2, pos[1] - size[1] / 2 ]


    def _local2unit(self, x, y):
        """Transform a local screen coordinate (x,y) to unit coordinate (x',y')"""
        return ( self.hexmap.width - y / self.unit, x / self.unit )
    def _screen2unit(self, x, y):
        """Transform an absolute screen coordinate (x,y) to unit coordinate (x',y')"""
        return ( self.hexmap.width - (y - self.y_off) / self.unit, (x - self.x_off) / self.unit )

    def _unit2local(self, xp, yp):
        """Transform a unit coordinate (x',y') to local screen coordinate (x,y)"""
        return ( self.unit * yp, self.unit * ( self.hexmap.width  - xp ) )
    def _unit2screen(self, xp, yp):
        """Transform a unit coordinate (x',y') to absolute screen coordinate (x,y)"""
        return ( self.unit * yp + self.x_off, self.unit * ( self.hexmap.width - xp ) + self.y_off )


tttraders_kv("map.kv")