Rock-paper-scissors: Difference between revisions

→‎{{header|Tcl}}: Small correction to show error handling
(→‎Tcl: Added implementation)
(→‎{{header|Tcl}}: Small correction to show error handling)
Line 433:
# How to ask for a move from the human player
proc getHumanMove {} {
puts -nonewline "Your move? \[R\]ock, \[P\]aper, \[S\]cissors: "
flush stdout
while 1 {
puts -nonewline "Your move? \[R\]ock, \[P\]aper, \[S\]cissors: "
flush stdout
gets stdin line
if {[eof stdin]} {
Line 443:
set len [string length $line]
foreach play {0 1 2} name {"rock" "paper" "scissors"} {
if {$len && [string equal -nocase -length $len $line $name]} {
return $play
}
Line 489:
Sample run:
<pre>
Your move? [R]ock, [P]aper, [S]cissors: rrock
I play "Scissors"
You win!
Line 501:
You win!
Cumulative scores: 2 to you, 1 to me
Your move? [R]ock, [P]aper, [S]cissors: ssciss
I play "Paper"
You win!
Line 509:
A draw!
Cumulative scores: 3 to you, 1 to me
Your move? [R]ock, [P]aper, [S]cissors: zaphod beeblebrox
Sorry, I don't understand that. Try again please.
Your move? [R]ock, [P]aper, [S]cissors: r
I play "Scissors"
Anonymous user