Author Topic: QB64 10-Liner programs or games  (Read 13642 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #30 on: March 21, 2022, 04:25:52 pm »
Here's Charlie's (who was coloning all over the place):
Code: QB64: [Select]
  1. _Title "Test Skeleton Screen 0" ' b+ 2022-03-21
  2. ' screen 0 is (8 * 80 = 640) X (16 * 25 = 400) dont need constants for that
  3. Dim Shared As Long Mx, My, ClsTF, done
  4. Dim Shared k$, Lim
  5.  
  6. MainSetupCode ' call setup
  7.     If ClsTF Then Cls
  8.     Mx = _MouseX: My = _MouseY
  9.     k$ = InKey$
  10.     MainLoopCode ' read and execute your 10 liner here
  11.     _Display
  12.     If Lim Then _Limit Lim ' let coder set Lim
  13. Loop Until done
  14.  
  15. Sub MainSetupCode ' try Charlie's code  https://qb64forum.alephc.xyz/index.php?topic=4732.msg141491#msg141491
  16.     ClsTF = -1 '  clear screen
  17.     Lim = .75 ' use limit
  18.  
  19. Sub MainLoopCode ' try Charlie's code https://qb64forum.alephc.xyz/index.php?topic=4732.msg141491#msg141491
  20.     Static i, score%
  21.     If i Then '  before we change test letter score the last
  22.         key_pressed$ = UCase$(k$)
  23.         If InStr("AEI", Chr$(i)) And (key_pressed$ = Chr$(i)) Then
  24.             Sound 2000, 1
  25.             score% = score% + 1
  26.         ElseIf InStr("AEI", Chr$(i)) And (key_pressed$ <> Chr$(i)) Then
  27.             Sound 40, 1
  28.             score% = score% - 2
  29.         End If
  30.     End If
  31.     Print "Catch the aei vowels!" + Chr$(10) + "Press the vowel's key when you see it." + Chr$(10) + "Don't make a mistake !" + Chr$(10)
  32.     Print "Score:" + Str$(score%)
  33.     i = Int(Rnd * 9) + 65
  34.     Print
  35.     Print Chr$(i) + "    "
  36.  
  37.  
  38.  

note: This game forces you to put your hands in very awkward position over a, e, i in order to hit letters fast enough.

Also note I moved Lim to single type for Charlies's game that needs more than a second between loops.
« Last Edit: March 21, 2022, 04:34:11 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #31 on: March 21, 2022, 04:53:33 pm »
Here is Pete's Guess Number, didn't save on a single line!
Code: QB64: [Select]
  1. _Title "Test Skeleton Screen 0" ' b+ 2022-03-21
  2. ' screen 0 is (8 * 80 = 640) X (16 * 25 = 400) dont need constants for that
  3. Randomize Timer ' new this code
  4. Dim Shared As Long Mx, My, ClsTF, done
  5. Dim Shared k$, Lim
  6.  
  7. MainSetupCode ' call setup
  8.     If ClsTF Then Cls
  9.     Mx = _MouseX: My = _MouseY
  10.     k$ = InKey$
  11.     MainLoopCode ' read and execute your 10 liner here
  12.     _Display
  13.     If Lim Then _Limit Lim ' let coder set Lim
  14. Loop Until done
  15.  
  16. Sub MainSetupCode ' try Pete's code  https://qb64forum.alephc.xyz/index.php?topic=4732.msg141465#msg141465
  17.     ClsTF = 0 '  clear screen
  18.     Lim = 0 ' use limit
  19.  
  20. Sub MainLoopCode ' try Pete's code  https://qb64forum.alephc.xyz/index.php?topic=4732.msg141465#msg141465
  21.     Static x$, try
  22.     If x$ = "" Then x$ = LTrim$(Str$(Int(Rnd * 10 + 1)))
  23.     try = try + 1
  24.     Line Input "Guess a number between 1 and 10 "; num$
  25.     If x$ < num$ Then j = 1 Else j = 10
  26.     If num$ <> x$ Then Print Mid$("Too high!Too Low!", j, 9)
  27.     If num$ = x$ Then Print "Yes! Number of tries to guess it was:"; try
  28.     If num$ = x$ Then done = -1
  29.  

Note added Randomize Timer to the Skeleton.

Offline CharlieJV

  • Newbie
  • Posts: 89
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #32 on: March 21, 2022, 04:58:48 pm »
Here's Charlie's (who was coloning all over the place):
(SNIP!)
note: This game forces you to put your hands in very awkward position over a, e, i in order to hit letters fast enough.

(SNIP!)

I just spent the last five minutes trying to figure out what "coloning" means.  Took me a while to figure out it has nothing to do with my intestines...

What do you mean put your hands in very awkward position?  (I'm a typist, so all fingers positioned for typing anything.)

Not only is the game good for the cognitive side of things, but it is about typing dexterity too.  Well, for those three keys.
(https://oakdome.com/k5/lesson-plans/word/images/proper-finger-placement-for-keyboarding-550.gif)

« Last Edit: March 21, 2022, 05:14:30 pm by CharlieJV »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #33 on: March 21, 2022, 05:08:04 pm »
"Coloning" is my expression for using : for multiple statements on single line. I also call it double parking.

@CharlieJV I did not learn typing, what fingers are you suppose to use for a, e and i?

Ha! Everytime I saw an H, I wanted to press an i!

Offline CharlieJV

  • Newbie
  • Posts: 89
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #34 on: March 21, 2022, 05:13:45 pm »
"Coloning" is my expression for using : for multiple statements on single line. I also call it double parking.

@CharlieJV I did not learn typing, what fingers are you suppose to use for a, e and i?


"Coloning":  Yeah, I had managed to clue in earlier, but only after I studied your code.  I'm just happy I wasn't semi-coloning or perioding all over the place...

My earlier post has a link to a nice image on the web for typing hand/finger positioning, which I had totally botched and have just now fixed.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #35 on: March 21, 2022, 05:27:53 pm »
LOL! I am glad too!

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #36 on: March 21, 2022, 06:28:54 pm »
@bplus You have a lot of tricks up your sleeve, but I'll bet DIMming k$ as "LONG" is not one of them. :D

I completely agree about the line challenge and non-use of colons. Every colon is another line, in my opinion. Oh course, characters could be counted, but that's not entirely fair either, as certain keywords are longer than others.

I use the same approach to most of my larger programs. Make a central hub, and run sub-routines from it. This method allowed me to always know the program flow would continuously be cycled through that hub. Back in the old days, it provided a way to time the program, and evoke a screen saver. Other advantages existed, too.

@Dav Speaking of screen savers, in the paragraph above, I would have loved to have the plasma one you posted! Very cool!

@Kiara87 I get it, more of a discussion concerning optimization of BASIC code, rather than the use of BASIC libraries to develop OOP. Most of what I see of a practical aspect of this is the use of creative algorithms, mostly math formulas, like Dav and Bill posted in their 10-liners. The downside of "optimization" when it comes to limiting lines of code, ironically, results in obfuscation, much the same too many lines of convoluted code produce. Use of GOTO statements, for example, to cut down on a loop line code. I consider that bad coding practice, especially to introduce it, in a positive way, to a beginner. I consider BASIC best for coders who like to build things from the foundation up. All I ever heard from C communities is "You need a library for that." That was their response to me trying to write a keyboard function in C. I eventually accomplished it, because it was possible with C/C++ statements, but I was not too happy that such a large community completely lost track of how to build a program from the foundation up.

Pete

PS @Dimster That was just a typo on Mark's part. He was just giving a skeleton, almost pseudo-code, example of how to set up a 10-line hub to run a program. Sorry for the late reply, you posted while I was writing.

obviously you are right it is all obfuscated and illegible code it is to jump with the goto it is not good to learn about this I agree
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: QB64 10-Liner programs or games
« Reply #37 on: March 21, 2022, 06:37:17 pm »
Yeah what I am finding is these things are really 100 lines or less:
https://www.vitoco.cl/atari/10liner/MNPUZZLE/

  [ You are not allowed to view this attachment ]  

I say make it 100 lines with no colons and get something as enjoyable to read as to play!

That would be way more educational and inspiring for all levels of hobbiests.

in fact the colon creates illegible code as peter quoted is obfuscated code

like this example you proposed of 100 lines
but maybe other people would put rules each line should not contain more than 100 characters
however in any case as you have mentioned it would not be worth it
as you pointed out in the post everything can be adapted with a sub (subrutine)
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione