QB64.org Forum

Active Forums => Programs => Topic started by: bplus on June 27, 2021, 04:17:45 pm

Title: Simple Simon
Post by: bplus 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)

Title: Re: Simple Simon
Post by: Juan Tamarit 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.
Title: Re: Simple Simon
Post by: Dav 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
Title: Re: Simple Simon
Post by: bplus 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 :)
Title: Re: Simple Simon
Post by: FellippeHeitor 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.
Title: Re: Simple Simon
Post by: bplus 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.