《付録》TetrisContext.py

# -*- coding: utf-8 -*-
#===============================================================================
#    Copyright (C) 2000-2008, 小泉ひよ子とタマゴ倶楽部
#
# Change History: Games
#    1988/05, Smalltalk
#    2004/09, Java
#    2005/02, C#
#    2005/03, Jython
# 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 
#===============================================================================

## --------------------
from System.Windows.Input import Key

Key_Right = Key.Right
Key_Left  = Key.Left
Key_Up    = Key.Up
Key_Down  = Key.Down

## --------------------
from System.Windows import Point

class XPoint:
    def __init__(self, x, y):
        self.value = Point(x, y)

## --------------------
from System.Windows.Shapes import Polygon
from System.Windows import HorizontalAlignment
from System.Windows import VerticalAlignment

class XPolygon:
    def __init__(self, Points=None, **args):
        self.value = Polygon(
            HorizontalAlignment=HorizontalAlignment.Center,
            VerticalAlignment=VerticalAlignment.Center,
            Points=Points.value,
            **args)
        
    def __iter__(self):
        for e in self.value.Points:
            yield e

    def update(self, points, *args):
        self.value.Points = points(*args).value

## --------------------
from System.Windows.Media import PointCollection

class XPointCollection:
    def __init__(self, xpoints):
        self.value = self._value(xpoints)

    def _value(self, xpoints):
        s = PointCollection()
        for e in xpoints:
            s.Add(e.value)
        return s

## --------------------               
from System.Windows.Media import Brushes

Black     = Brushes.Black
LightGray = Brushes.LightGray
Gray      = Brushes.Gray

Brown   = Brushes.Brown
Yellow  = Brushes.Yellow
Magenta = Brushes.Magenta
Purple  = Brushes.Purple
Red     = Brushes.Red
Orange  = Brushes.Orange
Cyan    = Brushes.Cyan
Blue    = Brushes.Blue
Lime    = Brushes.Lime

## --------------------