蜂の巣:敷地の形状

オリジナル仕様(正方形)とは異なり、先手後手の領地は6角形を基調とします。

class Ostone(object):
    def __init__(self, client, x, y, state, Stroke=None, Fill=None):
        self.name = "_%d_%d"%(x, y)
        self.shape = self._shape(x, y)       ;
        if Stroke: self.shape.Stroke = Stroke;
        if Fill  : self.shape.Fill   = Fill  ;

各領地は、座標値 (x, y) をもとに生成した、文字列 self.name によって識別されます。

    def _shape(self, x, y):
        gap = 1
        x = HexStone._dx + x * (HexStone._width +gap)
        y = HexStone._dy + y * (HexStone._height+gap)

        s = Polygon(
            Name=self.name,
            HorizontalAlignment=HorizontalAlignment.Center,
            VerticalAlignment=VerticalAlignment.Center,
            Points=self.pointCollection([Point(x+dx*2, y+dy*2)
                for dx, dy in HexStone(x, y, False).vertices]),
            )
        s.MouseUp += self.mouseUp
        return s

6角形の領地 Polygon を構成するとともに、マウス操作に呼応するイベントハンドラー self.mouseUp を登録します。

    def mouseUp(self, sender, e):
        print ">>>", sender.Name, sender.Fill

領地を選択(クリック)すると、次のように、

>>> _6_6 #FF000000
>>> _8_6 #FF008000
>>> _10_6 #FFFFFFFF

その識別情報と領域の色を出力します。ここでは、上から順に、白、緑、黒に相当します。