Created
May 11, 2012 04:43
-
-
Save gwang/2657589 to your computer and use it in GitHub Desktop.
Multiplication Bingo in Tcl Using SAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{0 {{0 0} {0 1} {0 2} {0 3} {0 4} {0 5} {0 6} {0 7} {0 8} {0 9} {0 10} {0 11} {0 12} {1 0} {2 0} {3 0} {4 0} {5 0} {6 0} {7 0} {8 0} {9 0} {10 0} {11 0} {12 0}}} | |
{1 {{1 1}}} | |
{2 {{1 2} {2 1}}} | |
{3 {{1 3} {3 1}}} | |
{4 {{1 4} {2 2} {4 1}}} | |
{5 {{1 5} {5 1}}} | |
{6 {{1 6} {2 3} {3 2} {6 1}}} | |
{7 {{1 7} {7 1}}} | |
{8 {{1 8} {2 4} {4 2} {8 1}}} | |
{9 {{1 9} {3 3} {9 1}}} | |
{10 {{1 10} {2 5} {5 2} {10 1}}} | |
{11 {{1 11} {11 1}}} | |
{12 {{1 12} {2 6} {3 4} {4 3} {6 2} {12 1}}} | |
{14 {{2 7} {7 2}}} | |
{16 {{2 8} {4 4} {8 2}}} | |
{18 {{2 9} {3 6} {6 3} {9 2}}} | |
{20 {{2 10} {4 5} {5 4} {10 2}}} | |
{22 {{2 11} {11 2}}} | |
{24 {{2 12} {3 8} {4 6} {6 4} {8 3} {12 2}}} | |
{15 {{3 5} {5 3}}} | |
{21 {{3 7} {7 3}}} | |
{27 {{3 9} {9 3}}} | |
{30 {{3 10} {5 6} {6 5} {10 3}}} | |
{33 {{3 11} {11 3}}} | |
{36 {{3 12} {4 9} {6 6} {9 4} {12 3}}} | |
{28 {{4 7} {7 4}}} | |
{32 {{4 8} {8 4}}} | |
{40 {{4 10} {5 8} {8 5} {10 4}}} | |
{44 {{4 11} {11 4}}} | |
{48 {{4 12} {6 8} {8 6} {12 4}}} | |
{25 {{5 5}}} | |
{35 {{5 7} {7 5}}} | |
{45 {{5 9} {9 5}}} | |
{50 {{5 10} {10 5}}} | |
{55 {{5 11} {11 5}}} | |
{60 {{5 12} {6 10} {10 6} {12 5}}} | |
{42 {{6 7} {7 6}}} | |
{54 {{6 9} {9 6}}} | |
{66 {{6 11} {11 6}}} | |
{72 {{6 12} {8 9} {9 8} {12 6}}} | |
{49 {{7 7}}} | |
{56 {{7 8} {8 7}}} | |
{63 {{7 9} {9 7}}} | |
{70 {{7 10} {10 7}}} | |
{77 {{7 11} {11 7}}} | |
{84 {{7 12} {12 7}}} | |
{64 {{8 8}}} | |
{80 {{8 10} {10 8}}} | |
{88 {{8 11} {11 8}}} | |
{96 {{8 12} {12 8}}} | |
{81 {{9 9}}} | |
{90 {{9 10} {10 9}}} | |
{99 {{9 11} {11 9}}} | |
{108 {{9 12} {12 9}}} | |
{100 {{10 10}}} | |
{110 {{10 11} {11 10}}} | |
{120 {{10 12} {12 10}}} | |
{121 {{11 11}}} | |
{132 {{11 12} {12 11}}} | |
{144 {{12 12}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package require tcom | |
proc load_data {file} { | |
global mylist | |
set fp [ open $file ] | |
while { [ gets $fp line ] >= 0 } { | |
if { [ string trim $line ] == "" } { | |
continue | |
} | |
set sum [ lindex [ lindex $line 0 ] 0 ] | |
set content [ lindex [ lindex $line 0 ] 1 ] | |
set mylist($sum) $content | |
} | |
close $fp | |
} | |
proc say { text } { | |
global voice | |
puts "saying : $text" | |
$voice Speak $text 1 | |
} | |
proc get_text {} { | |
global mylist | |
set sums [ array names mylist ] | |
set r1 [ expr int(rand() * [ llength $sums ]) ] | |
set s [ lindex $sums $r1 ] | |
set r2 [ expr int(rand()*[llength $mylist($s)]) ] | |
set tmp [ lindex $mylist($s) $r2 ] | |
set n1 [ lindex $tmp 0 ] | |
set n2 [ lindex $tmp 1 ] | |
say "$n1 times $n2" | |
unset mylist($s) | |
} | |
set voice [ ::tcom::ref createobject Sapi.SpVoice ] | |
load_data "bingo.txt" | |
for { set i 0 } { $i < 60 } { incr i } { | |
get_text | |
after 6000 | |
} | |
exit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment