Version 12 of Domino

Updated 2005-12-11 15:19:05

if 0 {Richard Suchenwirth 2004-11-14 - Domino is a popular game. In this weekend fun project, I wanted to have it in Tcl/Tk too.

http://mini.net/files/domino.gif

The real multiplayer game can't be implemented, as there's no way for one player to see a piece, while another doesn't - but at least one can use this for mathematical games with dominoes, as described in Martin Gardner's "Mathematical Circus". Drag a piece with left mouse button down, rotate it (counterclockwise 90 degrees) with right-click. }

 package require Tk

 namespace eval domino {
    variable bg black  fg white  size 30
    #-- "Visual" definition of dot patterns - "sugared lists"
    variable pattern
    array set pattern {
        0 {0 0 0
             0
           0 0 0}
        1 {0 0 0
             1
           0 0 0}
        2 {1 0 0
             0
           0 0 1}
        3 {1 0 0
             1
           0 0 1}
        4 {1 0 1
             0
           1 0 1}
        5 {1 0 1
             1
           1 0 1}
        6 {1 1 1
             0
           1 1 1}
    }
    variable points {1 1  1 2  1 3  2 2  3 1  3 2  3 3}
 }

if 0 {This "constructor" creates a domino piece on the canvas w, landscape oriented, with top left corner at x/y and the specified two point values (0..6). For allowing motion, all canvas items belonging to a piece with values p|q are tagged with

  • mv (so motion bindings have a common target)
  • d-$p$q for unique identification (assuming no duplicate pieces)

The bd-$p$q tags aren't used yet - in future one might use them for reverting a piece, i.e. raising or lowering the rectangle. }

 proc domino::create {w x y val1 val2} {
    variable bg; variable fg; variable size
    set tags [list mv d-$val1$val2]
    set x1 [expr {$x+$size-0.5}]
    set y1 [expr {$y+$size}]
    $w create rect $x $y [expr {$x+2*$size}] $y1 \
        -fill $bg -tags [linsert $tags 0 bd-$val1$val2]
    $w create line $x1 $y $x1 $y1 -fill $fg -tags $tags
    dots $w $x $y $val1 $tags
    dots $w [expr {$x+$size}] $y $