Author Topic: Simple Simon  (Read 3072 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Simple Simon
« on: June 27, 2021, 04:17:45 pm »
Code: QB64: [Select]
  1. _Title "Simple Simon"  'b+ 2021-06-27
  2.     b$ = b$ + _Trim$(Str$(Int(Rnd * 4) + 1))
  3.     For i = 1 To Len(b$)
  4.         Cls
  5.         Print Space$(i - 1); Mid$(b$, i, 1)
  6.         _Delay 1
  7.     Next
  8.     Cls
  9.     Print "Simon says repeat all that:"
  10.     For i = 1 To Len(b$)
  11.         k$ = InKey$
  12.         While k$ = ""
  13.             k$ = InKey$
  14.         Wend
  15.         Print k$;
  16.         If k$ <> Mid$(b$, i, 1) Then
  17.             Beep
  18.             Print
  19.             Print b$
  20.             Exit While
  21.         End If
  22.     Next

No Double Parking (with colons)

« Last Edit: June 27, 2021, 04:19:55 pm by bplus »

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Simple Simon
« Reply #1 on: June 27, 2021, 04:35:23 pm »
Very impressive, bro. WHILE 1 is a very interesting line, since you are leaving with an EXIT, very clever. Im interested in the double check of INKEY$. Can you explain me why this was needed? It always was hard to me to get the difference between WHILEs and LOOPs.

Cheers bro.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Simple Simon
« Reply #2 on: June 27, 2021, 05:05:09 pm »
Pretty compact one!  I was trying to shorten it more though for fun, using k$ = INPUT$(1) gained 3 lines (can ditch WHILE/INKEY$/WEND after).

Makes me remember a childhood song/poem called 'Simple Simon'.  Hadn't thought of that in years.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple Simon
« Reply #3 on: June 27, 2021, 05:49:07 pm »
@Juan Tamarit

Looks like Dav has pointed to a better method for getting a keypress than
Code: QB64: [Select]
  1.         k$ = InKey$
  2.         While k$ = ""
  3.             k$ = InKey$
  4.         Wend
  5.  

so all the above does is get a keypress that something as opposed to nothing...

Thanks both of you :)

FellippeHeitor

  • Guest
Re: Simple Simon
« Reply #4 on: June 27, 2021, 05:58:40 pm »
Now that's minimalistic. Interestingly, with numbers I got much farther than with colors/sounds. We are probably more wired to make logical connections with them.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple Simon
« Reply #5 on: June 27, 2021, 09:07:53 pm »
Now that's minimalistic. Interestingly, with numbers I got much farther than with colors/sounds. We are probably more wired to make logical connections with them.

Yeah numbers hold patterns, not sure alphabetic characters would hold up as well.

@FellippeHeitor thanks for inspiration from Genius.