Dear Tom and Peter,

Thank you both very much for your suggestions and code fragments. I had =20
tried something like
either ans/:i =3D=3D target/:i

but must have got it wrong, and had thought of parsing as my next option.=
 =20
I still might, but for now ... success!!! So here is "Bull and Shots" a =20
little game we played at school when things got dull.

Thank you again, Rosemary


rebol [Title: "Bulls and Shots" File: %bulls-and-shots.r]

random/seed now
digits: [1 2 3 4 5 6 7 8 9 0]
target: copy []

main: layout [
origin 30x30
backdrop water effect [gradient 0x1]
box "Bulls and Shots" 360x30 font-size 20 water white edge [size: 1x1 =20
color: pewter]
at 50x100 guide
btn 100x25 tan "New Game" #"n" [new-game]
num: field 100x25 font-size 16 center middle
btn 100x25 tan "Guess" #"g" [get-answer show-answer]
btn 100x25 tan "Quit" #"q" [quit]

at 30x230 guide
text as-is white bold {

H O W   T O   P L A Y
*  Hit New Game or "n"
*  Enter four digits 0 - 9
*  Hit Guess or "g"
*  Maximum tries =3D 12
*  There are no repeat digits
*  B U L L  - right digit, right place
*  S H O T - right digit, wrong place}

at 220x75 guide
h4 "Try: Guess Bulls Shots" 165x20 snow water
pad 0x-8
results: area 165x240 font-size 17 wrap
pad 80x10
box "Peek" 80x25 font-size 16 water white edge [size: 1x1 color: tan]
feel [over: func [face act pos] [
face/text: either act [copy target]["Peek"] show face ]]
]

new-game: does [
clear results/text
results/line-list: none
show results
tries: 0
target: copy []
target: to-string random/secure digits
remove/part target 6
focus num
]

get-answer: does [
ans: to-string num/text
answer: copy []
bulls: shots: 0

repeat i 4 [
if find target ans/:i [
either ans/:i =3D=3D target/:i
[bulls: bulls + 1]
[shots: shots + 1]
]]

tries: tries + 1
either ( tries <=3D 9 )
[answer: rejoin ["0" tries ": " ans "   " bulls "     " shots]]
[answer: rejoin [tries ":  " ans "   " bulls "     " shots]]
]

show-answer: does [
append results/text answer
append results/text newline
show results
if bulls =3D 4 [alert form ["Bravo - you guessed it !"]]
if tries =3D 12 [alert form ["Game over - no guesses left."]]
clear num/text
focus num
]

center-face main
view main
do-events


--=20

Formix Australia - www.formix.com.au

613 9354 9585
PO Box 261 Nth Carlton Vic 3054
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to