# -*- coding: utf-8 -*-
#===============================================================================
# Copyright (C) 2000-2008, 小泉ひよ子とタマゴ倶楽部
#
# Change History: WPF examples
# 2008/01/25, IronPython 1.1.1 (download)
# 2008/08/22, IronPython 1.1.2 (download)
# 2008/03/16, ver.2.0, WPF
# 2008/00/00, ver.2.1, IronPython 1.1.2
# Change History: Games
# 1988/05, Smalltalk
# 2004/09, Java
# 2005/02, C#
# 2005/03, Jython
#===============================================================================
from _ant import *
from System.Windows import *
from HoneyComb2 import *
from HoneyCell import *
## --------------------
class ExWindow(Window):
def __init__(self, Content=None, **args):
self.InitializeComponent(Content)
self.init()
def InitializeComponent(self, Content):
self.Content = LoadXaml(Content)
def init(self):
target = "canvas",
self._Controls(target)
self.comb = CombCell()
self.addCells()
def _Controls(self, target):
controls = xaml_controls(self)
for e in target:
setattr(self, e, controls[e])
def addCells(self):
self.addNull()
self.addComb()
self.addBlack()
self.addWhite()
def addNull(self):
for n, x, y in [
(7, 2, -2),
(7, 2, 18),
]:
for e in range(n):
cell = NullStone(self, e*2+x, y)
self.addShape(cell.shape)
for x, y in [
( 1, 0), (15, 0),
( 0, 2), (16, 2),
(-1, 4), (17, 4),
(-2, 6), (18, 6),
(-1, 8), (17, 8),
(-2, 10), (18, 10),
(-1, 12), (17, 12),
( 0, 14), (16, 14),
( 1, 16), (15, 16),
]:
cell = NullStone(self, x, y)
self.addShape(cell.shape)
def addComb(self):
for n, x, y in [
(6, 3, 0),
(7, 2, 2),
(8, 1, 4),
(9, 0, 6),
(8, 1, 8),
(9, 0, 10),
(8, 1, 12),
(7, 2, 14),
(6, 3, 16),
]:
for e in range(n):
cell = CombStone(self, e*2+x, y)
self.addShape(cell.shape)
self.comb.addCell(cell)
def addBlack(self):
self._addStone(BlackStone, [( 6,6), (9,8), ( 6,10)])
def addWhite(self):
self._addStone(WhiteStone, [(10,6), (7,8), (10,10)])
def _addStone(self, species, points):
for x, y in points:
cell = species(self, x, y)
self.addShape(cell.shape)
self.comb.addNeighbors(cell, x, y)
def addShape(self, shape):
return self.canvas.Children.Add(shape)
## --------------------
if __name__ == "__main__":
import sys
xaml = sys.argv[1]
win = ExWindow(
Title=__file__,
Width=298, Height=286,
Content=xaml,
)
Application().Run(win)
## --------------------