Games for children

  • 3 Replies
  • 73 Views
*

d.k

  • Apprentice
  • **
  • 32
Games for children
« on: April 09, 2017, 09:06:49 »
Hi!

I've written a simple guessing game for my 6-year-old daughter:

Code: [Select]
\ Simple guessing game.

with: con

: guess \ secret try-number -- secret
  . ". guess. What is the secret? " print
  dup
  100 null accept cr
  s:= if
    "Yippee! You got it! " print cr bye
  else
    "Nope. " print cr
  then ;

: app:main
  "Please, enter the secret: " print
  100 accept-pwd cr cr null? if bye then
 
  "You have got 10 tries..." print cr
  ' guess 1 10 loop
  "Ok, I'll tell you the secret: " print print cr

  bye ;

Maybe, I'm a little bit to early to show her how to program. 
But now she has some understanding of the stack...

Do you have any ideas for simple games or puzzles?
She loves puzzles! :)

Best regards,
d.k

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Games for children
« Reply #1 on: April 09, 2017, 10:56:25 »
Excellent!  Now you can add localization so it asks in English or German...

*

d.k

  • Apprentice
  • **
  • 32
Re: Games for children
« Reply #2 on: April 09, 2017, 14:01:30 »
That would be a nice puzzle for me, though.  Still, I'm looking for more puzzles for her! ;)

*

d.k

  • Apprentice
  • **
  • 32
Re: Games for children
« Reply #3 on: April 11, 2017, 20:02:52 »
Hi again -

couldn't resist the puzzle: a new game (now with localization! ;))
The translations can be found in lang.zip.

Code: [Select]
\ Simple randomized word guessing game.

\ with localization
"en" s:lang
\ possible words
[]
"story" s:intl a:push
"tree house" s:intl a:push
"car" s:intl a:push
"friend" s:intl a:push
"street" s:intl a:push
"summer" s:intl a:push
"holiday" s:intl a:push


with: con

: guess-word \ word try-nr -- word
  . "try-count-question" s:intl print
  dup
  100 null accept cr
  s:= if
    "right-answer" s:intl print cr bye
  else
    "wrong-answer" s:intl print cr
  then
  ;

: rand-num \ n -- rand(0,n-1)
  rand n:abs swap n:mod ;

: rand-char \ rand-word word -- rand-word' word'
  s:len rand-num
  dup -rot s:@ 
  -rot swap 1 s:-
  -rot s:+
  swap ;

: rand-word \ word -- rand-word
  s:len "" -rot ' rand-char swap times
  drop ;


: app:main
  "task" s:intl print
  a:len rand-num a:@ dup rand-word . cr cr
 
  10 "try-count-msg" s:intl s:strfmt print cr
  ' guess-word 1 10 loop
  "solution" s:intl print print cr
 
  bye ;