QB64.org Forum

Active Forums => Programs => Topic started by: bplus on October 04, 2021, 09:18:14 am

Title: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 04, 2021, 09:18:14 am
The Cryptogram Puzzle I presented in Discussion Board was really sadistic in the way you had to input letters. I came up with a better algorithm yesterday morning, I call it "Binary Select".

Here is the test code you can play with to get familiar with inputting letters. It's like the computer is playing a little guessing game showing you a group of letters and you press spacebar (or any key in test demo) if your letter is in the group... just wait if it's not your letter in group, repeat... until computer knows your letter. The computer then displays letter on next line and on next line you must confirm YN (another little guessing game pressing spacebar (or any key) on the Y display to confirm, indeed, that is the intended letter or not ie, you did not confirm the Y display.

So here is the main engine for getting user input for the game:
Code: QB64: [Select]
  1. _Title "Binary Select test demo" 'b+ 2021-10-03  Aha!
  2.  
  3.     test$ = bChoice$(10, 5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234")
  4.     Cls
  5.     Print "bChoice$ returned > "; test$
  6.     Do
  7.         Print: Print "Do you want to try another?"
  8.         test$ = ""
  9.         test$ = bChoice$(CsrLin, 1, "YNM")
  10.     Loop Until Len(test$)
  11.     Cls
  12. Loop Until test$ <> "Y"
  13.  
  14. Function bChoice$ (row, col, select$) ' this is a wrapper function for confirming the BinarySelect$ choice since so easy to mess up
  15.     'this function needs 3 lines from screen, starting at row parameter.
  16.     'the first line, at row, is dedicated to the BinarySelect$ function
  17.     'the next 2 lines confirm the select
  18.     ' All this makes it possible to continuous poll for a selection, if the user is away from computer for awhile
  19.     ' no problem because he wont be there to confirm the choice and so no progress is made in program using BinarySelect$
  20.  
  21.     'clear 3 dedicated lines
  22.     copySelect$ = select$
  23.     For i = 0 To 2 ' clear lines
  24.         Locate row + i, col: Print Space$(_Width - col + 1);
  25.     Next
  26.     c$ = BinarySelect$(row, col, copySelect$) ' the last choice is like a cancel
  27.     'Locate 20, 10: Print "debug print c$: "; c$;
  28.     Locate row + 1, col: Print "Confirming your choice > " + c$;
  29.     check$ = BinarySelect$(row + 2, col, "YN")
  30.     If check$ = "Y" Then bChoice$ = c$
  31.     Print "bChoice$ = "; c$
  32.  
  33.  
  34. Function BinarySelect$ (row, col, select$) ' this is recursive part of Binary Select Algo
  35.     ls = Len(select$)
  36.     If ls = 0 Then Beep: Exit Function ' no choices
  37.     If ls = 1 Then BinarySelect$ = select$: Exit Function ' only one choice
  38.     hls = Int(ls / 2)
  39.     s1$ = Mid$(select$, 1, hls): s2$ = Mid$(select$, hls + 1)
  40.     Locate row, col: Print Space$(_Width - col + 1);
  41.     Locate row, col: Print "Press key if you see your choice > " + s1$;
  42.     t = Timer(.001)
  43.     _KeyClear
  44.     k$ = InKey$
  45.     While Len(k$) = 0 And Timer(.001) - t < 3 + .25 * Len(s1$)
  46.         k$ = InKey$
  47.         _Limit 60
  48.     Wend
  49.     If Len(k$) Then
  50.         If Len(s1$) = 1 Then BinarySelect$ = s1$ Else BinarySelect$ = BinarySelect$(row, col, s1$)
  51.     Else
  52.         BinarySelect$ = BinarySelect$(row, col, s2$)
  53.     End If
  54.  
  55.  

It's still something that needs a little practice with but it is much easier to use than my first idea.

On the confirmation for trying again, it still catches me by surprise the first Y for confirming to try again.
No worries, if there is no confirmation for any letter, it will cycle around and offer the groups over and over again.

For the Game, I put an Ecs keypress in there to quit game as it was in Full Screen mode with no top right window X to close.


Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 04, 2021, 09:57:17 am
And here is the first version of the Game that I submit for our Challenge here with Screen 0 and hope to work in graphics for Syntax Competition maybe. Credits for jokes are listed right under Title at beginning. The whole thing is under 300 LOC.
Code: QB64: [Select]
  1. _Title "Halloween Challenge: Crypt-O-Gram Puzzle" ' b+  started One Key Challenge 2021-09-25
  2. ' from One Key Challenge - Cryptogram Puzzle   2021-10-02
  3.  
  4. ' 2021-09-07 Jokes are intended for QB64 home programming entertainment use only.
  5. ' Thank you CountryLiving 1-33
  6. ' https://www.countryliving.com/entertaining/a32963261/halloween-jokes/
  7. ' Thank you GoodHousekeeping 34-72
  8. ' https://www.goodhousekeeping.com/holidays/halloween-ideas/a32998753/halloween-jokes/
  9.  
  10. ' 2021-10-03 install new set of jokes and new Binary Select Input Algorithm
  11. ' Redo Mode system to fix differences of input methods.
  12. ' Recolor green background has me seeing Red!
  13.  
  14. Dim Shared Answer$ '  beginning phrase to be guessed    '   3 stages of the Puzzle
  15. Dim Shared Coded$ '   hidden in code
  16. Dim Shared Working$ ' decoded and solved when working$ becomes = ucase$(answer$)
  17. Dim Shared Letters$(1 To 26) ' for coding and highlited letters
  18. Dim Shared LCodes$(1 To 26) '  for code and decode by number 1 to 26
  19. Dim Shared Guesses$(1 To 26) ' track all the guess to decode
  20. Dim Shared HighLited ' cursor over letters to guess
  21. Dim Shared Mode
  22. _FullScreen 'I guess it does make it easier to tell E from F...
  23. Dim jokes$(1 To 100)
  24. For i = 1 To 100
  25.     Read r$
  26.     If r$ <> "EOD" Then jokes$(i) = r$: jCount = jCount + 1 Else Exit For
  27. restart:
  28. Answer$ = jokes$(Int(Rnd * jCount) + 1)
  29. For i = 1 To 26: Guesses$(i) = "-": Next 'setup the display guesses array
  30. For i = 1 To 26 ' use letters for display of letters to pick second and to create a code
  31.     Letters$(i) = Chr$(i + 64)
  32.     LCodes$(i) = Letters$(i) ' these will convert between each other by index number
  33. For i = 26 To 2 Step -1 ' shuffle the letters in LCode$()
  34.     Swap LCodes$(i), LCodes$(Int(Rnd * i) + 1)
  35. Coded$ = "": Working$ = "" ' reset for next go around
  36. For i = 1 To Len(Answer$) 'third: put the phrase in coded$ and hide it in working$
  37.     a = Asc(UCase$(Answer$), i)
  38.     If a >= 65 And a <= 90 Then
  39.         Coded$ = Coded$ + LCodes$(a - 64)
  40.         Working$ = Working$ + "*"
  41.     Else
  42.         Coded$ = Coded$ + Mid$(Answer$, i, 1)
  43.         Working$ = Working$ + Mid$(Answer$, i, 1)
  44.     End If
  45. HighLited = 1 'setup done start game
  46. Mode = 0
  47.     DisplayScreen
  48.     k$ = bChoice$(23, 33, "1234ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  49.     If k$ <> "" Then
  50.         If Mode = 0 Then ' highlight a letter
  51.             'm replaces arrows and mouse select of highlited 1 to 26 for letters
  52.             test = InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", k$)
  53.             If test > 0 Then
  54.                 HighLited = test
  55.                 Mode = 1
  56.             Else
  57.                 test = InStr("1234", k$)
  58.                 If test > 0 Then
  59.                     Select Case test
  60.                         Case 1: GoSub do1
  61.                         Case 2: GoSub do2
  62.                         Case 3: GoSub do3
  63.                         Case 4: GoSub do4
  64.                     End Select
  65.                 Else
  66.                     Mode = 0
  67.                 End If
  68.             End If
  69.         Else
  70.             Select Case k$
  71.                 Case "1": GoSub do1
  72.                 Case "2": GoSub do2
  73.                 Case "3": GoSub do3
  74.                 Case "4": GoSub do4
  75.                 Case "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
  76.                     Guesses$(HighLited) = k$ ' for screen updates
  77.                     For i = 1 To Len(Working$)
  78.                         If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = k$
  79.                     Next
  80.                     Mode = 0
  81.             End Select
  82.         End If
  83.     End If
  84.     _Limit 60
  85. Loop Until Working$ = UCase$(Answer$)
  86. DisplayScreen
  87. Color 9, 8
  88. cp 17, "You got it!    5 secs to next puzzle..."
  89. GoTo restart
  90.  
  91. do1: ' display answer
  92. Working$ = UCase$(Answer$) ' show the answer$ guesses correct moves to next puzzle
  93. DisplayScreen
  94. Mode = 0
  95.  
  96. do2: ' get decode letter for highlighted Letter
  97. For i = 1 To 26
  98.     If LCodes$(i) = Letters$(HighLited) Then c$ = Chr$(i + 64): Exit For
  99. Guesses$(HighLited) = c$ ' for screen updates
  100. For i = 1 To Len(Working$)
  101.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = c$
  102. Mode = 0
  103.  
  104. do3: ' find a uncoded letter
  105. Color 15, 8: Locate 24, 40: Print "Select Find Letter"
  106. d$ = bChoice$(23, 33, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  107. If d$ <> "" Then
  108.     c$ = LCodes$(Asc(d$) - 64)
  109.     Guesses$(Asc(c$) - 64) = d$
  110.     For i = 1 To Len(Working$)
  111.         If c$ = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = d$
  112.     Next
  113.     Mode = 0
  114.  
  115. do4: ' clear guess letter from code letter
  116. Guesses$(HighLited) = "-"
  117. For i = 1 To Len(Working$)
  118.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = "*" ' clear the letter
  119. Mode = 0
  120.  
  121. 'one liners
  122. Data "Why do ghosts go on diets? So they can keep their ghoulish figures"
  123. Data "Where does a ghost go on vacation? Mali-boo."
  124. Data "Why did the ghost go into the bar? For the Boos."
  125. Data "What is in a ghost's nose? Boo-gers."
  126. Data "Why did the policeman ticket the ghost on Halloween? It didn't have a haunting license."
  127. Data "Why do demons and ghouls hang out together? Because demons are a ghoul's best friend!"
  128. Data "Why did the ghost starch his sheet? He wanted everyone scared stiff."
  129. Data "What does a panda ghost eat? Bam-BOO!"
  130. Data "What's a ghost's favorite dessert? I-Scream!"
  131. Data "Where do ghosts buy their food? At the ghost-ery store!"
  132. Data "How do you know when a ghost is sad? He starts boo hooing."
  133. Data "Why don't mummies take time off? They're afraid to unwind."
  134. Data "Why did the headless horseman go into business? He wanted to get ahead in life."
  135. Data "What kind of music do mummies like listening to on Halloween? Wrap music."
  136. Data "Why don't mummies have friends? Because they're too wrapped up in themselves."
  137. Data "Why did the vampire read the newspaper? He heard it had great circulation."
  138. Data "How do vampires get around on Halloween? On blood vessels."
  139. Data "What's it like to be kissed by a vampire? It's a pain in the neck."
  140. Data "What's it called when a vampire has trouble with his house? A grave problem."
  141. Data "How can you tell when a vampire has been in a bakery? All the jelly has been sucked out of the jelly doughnuts."
  142. Data "What do you get when you cross a vampire and a snowman? Frostbite."
  143. Data "Why do skeletons have low self-esteem? They have no body to love."
  144. Data "Know why skeletons are so calm? Because nothing gets under their skin."
  145. Data "What do you call a cleaning skeleton? The grim sweeper."
  146. Data "What do skeletons order at a restaurant? Spare ribs."
  147. Data "What do you call a witch's garage? A broom closet."
  148. Data "What kind of food would you find on a haunted beach? A sand-witch!"
  149. Data "What was the witch's favorite subject in school? Spelling."
  150. Data "What do you call two witches who live together? Broom-mates!"
  151. Data "What's a witch's favorite makeup? Ma-scare-a."
  152. Data "Who helps the little pumpkins cross the road safely? The crossing gourd."
  153. Data "What treat do eye doctors give out on Halloween? Candy corneas."
  154. Data "What type of plants do well on all Hallow's Eve? Bam-BOO!"
  155. Data "What do birds say on Halloween? Trick or tweet!"
  156. Data "Why don't skeletons ever go trick or treating? Because they have no-body to go with."
  157. Data "Where do ghosts buy their Halloween candy? At the ghost-ery store!"
  158. Data "What do owls say when they go trick or treating? 'Happy Owl-ween!'"
  159. Data "What do ghosts give out to trick or treaters? Booberries!"
  160. Data "Who did Frankenstein go trick or treating with? His ghoul friend."
  161. Data "What Halloween candy is never on time for the party? Choco-LATE!"
  162. Data "What do witches put on to go trick or treating? Mas-scare-a."
  163. Data "What does Bigfoot say when he asks for candy?  'Trick-or-feet!'"
  164. Data "Which type of pants do ghosts wear to trick or treat? Boo jeans."
  165. Data "What makes trick or treating with twin witches so challenging? You never know which witch is which!"
  166. Data "What happens when a vampire goes in the snow? Frost bite!"
  167. Data "What do you call two witches living together? Broommates"
  168. Data "What position does a ghost play in hockey? Ghoulie."
  169. Data "What do mummies listen to on Halloween? Wrap music."
  170. Data "How do you make a skeleton laugh? You tickle his funny bone!"
  171. Data "Which Halloween monster is good at math? Count Dracula!"
  172. Data "Why did the Cyclops give up teaching? He only had one pupil!"
  173. Data "Why didn't the skeleton go to see a scary movie? He didn't have the guts."
  174. Data "What did the boy ghost say to the girl ghost? 'You sure are boo-tiful!'"
  175. Data "Where does Dracula keep his money? In a blood bank."
  176. Data "Why are ghosts terrible liars? You can see right through them!"
  177. Data "Why don't mummies take vacations? They're afraid to unwind."
  178. Data "What is a vampire's favorite holiday, besides Halloween? Fangs-giving!"
  179. Data "Where do fashionable ghosts shop? Bootiques!"
  180. Data "What's a monster's favorite play? Romeo and Ghouliet!"
  181. Data "What room does a ghost not need? A living room."
  182. Data "What monster plays tricks on Halloween? Prank-enstein!"
  183. Data "What's a ghost's favorite dessert? I scream."
  184. Data "What does the skeleton chef say when he serves you a meal? 'Bone Appetit!'"
  185. Data "What is a vampire's favorite fruit? A neck-tarine!"
  186. Data "What do witches put on their bagels? Scream cheese."
  187. Data "What do ghosts eat for dinner? Spook-ghetti!"
  188. Data "What do skeletons order at restaurants? Spare ribs."
  189. Data "What does a panda ghost eat? Bam-BOO!"
  190. Data "What tops off a mummy's ice cream sundae? Whipped scream."
  191. Data "What's a ghost's favorite yogurt flavor? Boo-berry!"
  192. Data "What's a vampire's least favorite meal? A steak!"
  193. Data "Why was the candy corn booed off the stage? All of his jokes were too corny!"
  194. Data "EOD"
  195.  
  196. Sub DisplayScreen
  197.     Color 9, 8: Cls
  198.     cp 2, "*** Halloween Challenge - Cryptogram Puzzle ***"
  199.     Color 6
  200.     cp 4, "Solve puzzle by selecting a Code letter then selecting a Guess letter for it."
  201.     cp 5, "All selections are made by pressing spacebar when you see your letter or digit."
  202.     cp 6, "You will need to verify your selection by pressing spacebar again when see Y for Yes."
  203.     cp 7, "Use the escape key to quit immediately (an X box in top right is not accessible)."
  204.     cp 9, "To get the answer and move onto next puzzle, select 1."
  205.     cp 10, "To decode current highlighted letter, select 2."
  206.     cp 11, "To solve a letter, select 3 and then select letter to find."
  207.     cp 12, "To clear a guess at highlighted Code letter, select 4."
  208.     Color 14
  209.     Locate 15, (120 - Len(Answer$)) / 2: Print Coded$
  210.     Color 15
  211.     Locate 16, (120 - Len(Answer$)) / 2
  212.     For i = 1 To Len(Answer$)
  213.         w$ = Mid$(Working$, i, 1): c$ = Mid$(Coded$, i, 1)
  214.         a$ = Mid$(Answer$, i, 1): h$ = Letters$(HighLited)
  215.         If w$ = "*" Then
  216.             pc$ = "*": If h$ = c$ Then Color 15, 9 Else Color 15, 8
  217.         Else
  218.             Color 15, 8: If w$ = UCase$(a$) Then pc$ = a$ Else pc$ = w$
  219.         End If
  220.         Print pc$;
  221.     Next
  222.     spaces = 9
  223.     For i = 1 To 26 'blue background highlighter
  224.         If i = HighLited Then Color 14, 9 Else Color 14, 8
  225.         Locate 19, spaces: Print Letters$(i)
  226.         If i = HighLited Then Color 14, 9 Else Color 15, 8
  227.         Locate 20, spaces: Print Guesses$(i)
  228.         spaces = spaces + 4
  229.     Next
  230.     If Mode = 1 Then
  231.         Color 15, 8
  232.         cp 22, "Guess Solve Letter or Menu #"
  233.     Else
  234.         Color 14, 8
  235.         cp 22, "Select Code Letter or Menu #"
  236.     End If
  237.  
  238. Sub cp (row, text$) ' center text on text screen
  239.     Locate row, (_Width - Len(text$)) / 2: Print text$
  240.  
  241. Function bChoice$ (row, col, select$) ' this is a wrapper function for confirming the BinarySelect$ choice since so easy to mess up
  242.     ' This will return "" if user never confirms a choice, otherwise some letter in Select$ is returned.
  243.     ' Row and Col setup for Locate that works on any screen not like x, y for _PrintString when want to work in graphics or screen 0
  244.     ' The first line, at row, is dedicated to the BinarySelect$ function
  245.     ' the next 2 lines confirm the select using another YN for Yes No Bianary Select.
  246.     ' All this makes it possible to continuous poll for a selection, if the user is away from computer for awhile
  247.     ' no problem because he wont be there to confirm the choice and so no progress is made in program using BinarySelect$.
  248.  
  249.     'clear 3 dedicated lines for Row, Col to end of line
  250.     copySelect$ = select$
  251.     For i = 0 To 2 ' clear lines
  252.         Locate row + i, col: Print Space$(_Width - col + 1);
  253.     Next
  254.     c$ = BinarySelect$(row, col, copySelect$) ' the last choice is like a cancel
  255.     Locate row + 1, col: Print "Confirming your choice > " + c$;
  256.     check$ = BinarySelect$(row + 2, col, "YN")
  257.     If check$ = "Y" Then bChoice$ = c$
  258.  
  259. Function BinarySelect$ (row, col, select$) ' this is recursive part of Binary Select Algo
  260.     ls = Len(select$)
  261.     If ls = 0 Then Beep: Exit Function ' no choices
  262.     If ls = 1 Then BinarySelect$ = select$: Exit Function ' only one choice
  263.     hls = Int(ls / 2)
  264.     s1$ = Mid$(select$, 1, hls): s2$ = Mid$(select$, hls + 1)
  265.     Locate row, col: Print Space$(_Width - col + 1);
  266.     Locate row, col: Print "Press spacebar if you see your choice > " + s1$;
  267.     t = Timer(.001)
  268.     _KeyClear
  269.     k$ = InKey$
  270.     While k$ <> " " And Timer(.001) - t < 3 + .25 * Len(s1$) 'modified for just spacebar
  271.         If _KeyDown(27) Then System ' quit
  272.         k$ = InKey$
  273.         _Limit 60
  274.     Wend
  275.     If Len(k$) Then
  276.         If Len(s1$) = 1 Then BinarySelect$ = s1$ Else BinarySelect$ = BinarySelect$(row, col, s1$)
  277.     Else
  278.         BinarySelect$ = BinarySelect$(row, col, s2$)
  279.     End If
  280.  

Some hints for playing:
* These are all one liner Halloween jokes, so most start with W for What, When, Where, Why sometimes H for How.

Think of them as walking through a cemetery reading grave stones and learning, "The pun that knocked 'em dead"

* When your decode letter is correct, it will show in lower case in the joke unless starts a sentence or is Proper Name, a bad guess will leave the letter capitalized.

* How many one letter words are there? How many 2?

* Frequent double letters are ee ll in Halloween, oo in Boo.

* Frequent words and subjects of the one liners: ghost, witch, skeleton, mummy, monsters.

* If you want the current coded highlighted letter solved without guessing, select (menu item) 2.

* If you have to have an E, S, T, R...  then select (menu item) 3, you will be prompted for the letter in the guessing game way like all the other letters.

* If you want to just clear the highlighted letter guess that is clearly wrong, select (menu item) 4.

* If you totally give up and want to see the solution, select (menu item) 1.

* Coded Letters and prompts are color coded Yellow. Guess-to-Solve letters and prompts are color coded White.



Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 04, 2021, 05:00:27 pm
OK here is v2021-10-04 with mod of Steve's user input system plus real orange color:
Code: QB64: [Select]
  1. _Title "Halloween Challenge: Crypt-O-Gram Puzzle" ' b+  started One Key Challenge 2021-09-25
  2. ' from One Key Challenge - Cryptogram Puzzle   2021-10-02
  3.  
  4. ' 2021-09-07 Jokes are intended for QB64 home programming entertainment use only.
  5. ' Thank you CountryLiving 1-33
  6. ' https://www.countryliving.com/entertaining/a32963261/halloween-jokes/
  7. ' Thank you GoodHousekeeping 34-72
  8. ' https://www.goodhousekeeping.com/holidays/halloween-ideas/a32998753/halloween-jokes/
  9.  
  10. ' 2021-10-03 install new set of jokes and new Binary Select Input Algorithm
  11. ' Redo Mode system to fix differences of input methods.
  12. ' Recolor green background has me seeing Red!
  13. ' 2021-10-04 Steve McNeill came up with an easier to understand and use input system.
  14. ' Installing new Function and updating Game. Steve also told me how to change color palette,
  15. ' now we have some real Orange! for #12 meant for high red.
  16.  
  17. _PaletteColor 12, _RGB32(255, 128, 0) ' Orange
  18. Dim Shared Answer$ '  beginning phrase to be guessed    '   3 stages of the Puzzle
  19. Dim Shared Coded$ '   hidden in code
  20. Dim Shared Working$ ' decoded and solved when working$ becomes = ucase$(answer$)
  21. Dim Shared Letters$(1 To 26) ' for coding and highlited letters
  22. Dim Shared LCodes$(1 To 26) '  for code and decode by number 1 to 26
  23. Dim Shared Guesses$(1 To 26) ' track all the guess to decode
  24. Dim Shared HighLited ' cursor over letters to guess
  25. Dim Shared Mode
  26. _FullScreen 'I guess it does make it easier to tell E from F...
  27. Dim jokes$(1 To 100)
  28. For i = 1 To 100
  29.     Read r$
  30.     If r$ <> "EOD" Then jokes$(i) = r$: jCount = jCount + 1 Else Exit For
  31. restart:
  32. Answer$ = jokes$(Int(Rnd * jCount) + 1)
  33. For i = 1 To 26: Guesses$(i) = "-": Next 'setup the display guesses array
  34. For i = 1 To 26 ' use letters for display of letters to pick second and to create a code
  35.     Letters$(i) = Chr$(i + 64)
  36.     LCodes$(i) = Letters$(i) ' these will convert between each other by index number
  37. For i = 26 To 2 Step -1 ' shuffle the letters in LCode$()
  38.     Swap LCodes$(i), LCodes$(Int(Rnd * i) + 1)
  39. Coded$ = "": Working$ = "" ' reset for next go around
  40. For i = 1 To Len(Answer$) 'third: put the phrase in coded$ and hide it in working$
  41.     a = Asc(UCase$(Answer$), i)
  42.     If a >= 65 And a <= 90 Then
  43.         Coded$ = Coded$ + LCodes$(a - 64)
  44.         Working$ = Working$ + "*"
  45.     Else
  46.         Coded$ = Coded$ + Mid$(Answer$, i, 1)
  47.         Working$ = Working$ + Mid$(Answer$, i, 1)
  48.     End If
  49. HighLited = 1 'setup done start game
  50. Mode = 0
  51.     DisplayScreen
  52.     k$ = choice$(25, 44, " 1234ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  53.     If k$ <> " " Then
  54.         If Mode = 0 Then ' highlight a letter
  55.             'm replaces arrows and mouse select of highlited 1 to 26 for letters
  56.             test = InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", k$)
  57.             If test > 0 Then
  58.                 HighLited = test
  59.                 Mode = 1
  60.             Else
  61.                 test = InStr("1234", k$)
  62.                 If test > 0 Then
  63.                     Select Case test
  64.                         Case 1: GoSub do1
  65.                         Case 2: GoSub do2
  66.                         Case 3: GoSub do3
  67.                         Case 4: GoSub do4
  68.                     End Select
  69.                 Else
  70.                     Mode = 0
  71.                 End If
  72.             End If
  73.         Else
  74.             Select Case k$
  75.                 Case "1": GoSub do1
  76.                 Case "2": GoSub do2
  77.                 Case "3": GoSub do3
  78.                 Case "4": GoSub do4
  79.                 Case "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
  80.                     Guesses$(HighLited) = k$ ' for screen updates
  81.                     For i = 1 To Len(Working$)
  82.                         If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = k$
  83.                     Next
  84.                     Mode = 0
  85.             End Select
  86.         End If
  87.     End If
  88.     _Limit 60
  89. Loop Until Working$ = UCase$(Answer$)
  90. DisplayScreen
  91. Color 12, 8
  92. cp 19, "You got it!    5 secs to next puzzle..."
  93. GoTo restart
  94.  
  95. do1: ' display answer
  96. Working$ = UCase$(Answer$) ' show the answer$ guesses correct moves to next puzzle
  97. DisplayScreen
  98. Mode = 0
  99.  
  100. do2: ' get decode letter for highlighted Letter
  101. For i = 1 To 26
  102.     If LCodes$(i) = Letters$(HighLited) Then c$ = Chr$(i + 64): Exit For
  103. Guesses$(HighLited) = c$ ' for screen updates
  104. For i = 1 To Len(Working$)
  105.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = c$
  106. Mode = 0
  107.  
  108. do3: ' find a uncoded letter
  109. Color 15, 8: cp 24, "Select Letter to Find"
  110. Locate 25, 1: Print Space$(_Width) ' clear out old line
  111. d$ = choice$(25, 46, " ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  112. If d$ <> " " Then
  113.     c$ = LCodes$(Asc(d$) - 64)
  114.     Guesses$(Asc(c$) - 64) = d$
  115.     For i = 1 To Len(Working$)
  116.         If c$ = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = d$
  117.     Next
  118.     Mode = 0
  119.  
  120. do4: ' clear guess letter from code letter
  121. Guesses$(HighLited) = "-"
  122. For i = 1 To Len(Working$)
  123.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = "*" ' clear the letter
  124. Mode = 0
  125.  
  126. 'one liners
  127. Data "Why do ghosts go on diets? So they can keep their ghoulish figures"
  128. Data "Where does a ghost go on vacation? Mali-boo."
  129. Data "Why did the ghost go into the bar? For the Boos."
  130. Data "What is in a ghost's nose? Boo-gers."
  131. Data "Why did the policeman ticket the ghost on Halloween? It didn't have a haunting license."
  132. Data "Why do demons and ghouls hang out together? Because demons are a ghoul's best friend!"
  133. Data "Why did the ghost starch his sheet? He wanted everyone scared stiff."
  134. Data "What does a panda ghost eat? Bam-BOO!"
  135. Data "What's a ghost's favorite dessert? I-Scream!"
  136. Data "Where do ghosts buy their food? At the ghost-ery store!"
  137. Data "How do you know when a ghost is sad? He starts boo hooing."
  138. Data "Why don't mummies take time off? They're afraid to unwind."
  139. Data "Why did the headless horseman go into business? He wanted to get ahead in life."
  140. Data "What kind of music do mummies like listening to on Halloween? Wrap music."
  141. Data "Why don't mummies have friends? Because they're too wrapped up in themselves."
  142. Data "Why did the vampire read the newspaper? He heard it had great circulation."
  143. Data "How do vampires get around on Halloween? On blood vessels."
  144. Data "What's it like to be kissed by a vampire? It's a pain in the neck."
  145. Data "What's it called when a vampire has trouble with his house? A grave problem."
  146. Data "How can you tell when a vampire has been in a bakery? All the jelly has been sucked out of the jelly doughnuts."
  147. Data "What do you get when you cross a vampire and a snowman? Frostbite."
  148. Data "Why do skeletons have low self-esteem? They have no body to love."
  149. Data "Know why skeletons are so calm? Because nothing gets under their skin."
  150. Data "What do you call a cleaning skeleton? The grim sweeper."
  151. Data "What do skeletons order at a restaurant? Spare ribs."
  152. Data "What do you call a witch's garage? A broom closet."
  153. Data "What kind of food would you find on a haunted beach? A sand-witch!"
  154. Data "What was the witch's favorite subject in school? Spelling."
  155. Data "What do you call two witches who live together? Broom-mates!"
  156. Data "What's a witch's favorite makeup? Ma-scare-a."
  157. Data "Who helps the little pumpkins cross the road safely? The crossing gourd."
  158. Data "What treat do eye doctors give out on Halloween? Candy corneas."
  159. Data "What type of plants do well on all Hallow's Eve? Bam-BOO!"
  160. Data "What do birds say on Halloween? Trick or tweet!"
  161. Data "Why don't skeletons ever go trick or treating? Because they have no-body to go with."
  162. Data "Where do ghosts buy their Halloween candy? At the ghost-ery store!"
  163. Data "What do owls say when they go trick or treating? 'Happy Owl-ween!'"
  164. Data "What do ghosts give out to trick or treaters? Booberries!"
  165. Data "Who did Frankenstein go trick or treating with? His ghoul friend."
  166. Data "What Halloween candy is never on time for the party? Choco-LATE!"
  167. Data "What do witches put on to go trick or treating? Mas-scare-a."
  168. Data "What does Bigfoot say when he asks for candy?  'Trick-or-feet!'"
  169. Data "Which type of pants do ghosts wear to trick or treat? Boo jeans."
  170. Data "What makes trick or treating with twin witches so challenging? You never know which witch is which!"
  171. Data "What happens when a vampire goes in the snow? Frost bite!"
  172. Data "What do you call two witches living together? Broommates"
  173. Data "What position does a ghost play in hockey? Ghoulie."
  174. Data "What do mummies listen to on Halloween? Wrap music."
  175. Data "How do you make a skeleton laugh? You tickle his funny bone!"
  176. Data "Which Halloween monster is good at math? Count Dracula!"
  177. Data "Why did the Cyclops give up teaching? He only had one pupil!"
  178. Data "Why didn't the skeleton go to see a scary movie? He didn't have the guts."
  179. Data "What did the boy ghost say to the girl ghost? 'You sure are boo-tiful!'"
  180. Data "Where does Dracula keep his money? In a blood bank."
  181. Data "Why are ghosts terrible liars? You can see right through them!"
  182. Data "Why don't mummies take vacations? They're afraid to unwind."
  183. Data "What is a vampire's favorite holiday, besides Halloween? Fangs-giving!"
  184. Data "Where do fashionable ghosts shop? Bootiques!"
  185. Data "What's a monster's favorite play? Romeo and Ghouliet!"
  186. Data "What room does a ghost not need? A living room."
  187. Data "What monster plays tricks on Halloween? Prank-enstein!"
  188. Data "What's a ghost's favorite dessert? I scream."
  189. Data "What does the skeleton chef say when he serves you a meal? 'Bone Appetit!'"
  190. Data "What is a vampire's favorite fruit? A neck-tarine!"
  191. Data "What do witches put on their bagels? Scream cheese."
  192. Data "What do ghosts eat for dinner? Spook-ghetti!"
  193. Data "What do skeletons order at restaurants? Spare ribs."
  194. Data "What does a panda ghost eat? Bam-BOO!"
  195. Data "What tops off a mummy's ice cream sundae? Whipped scream."
  196. Data "What's a ghost's favorite yogurt flavor? Boo-berry!"
  197. Data "What's a vampire's least favorite meal? A steak!"
  198. Data "Why was the candy corn booed off the stage? All of his jokes were too corny!"
  199. Data "EOD"
  200.  
  201. Sub DisplayScreen
  202.     Color 12, 8: Cls
  203.     cp 4, "*** Halloween Challenge - Cryptogram Puzzle ***"
  204.     Color 6
  205.     cp 6, "Solve puzzle by selecting a Code letter then selecting a Guess letter for it."
  206.     cp 7, "All selections are made by pressing spacebar when you see your letter or digit."
  207.     cp 8, "You will need to verify your selection by pressing spacebar again when see Y for Yes."
  208.     cp 9, "Use the escape key to quit immediately (an X box in top right is not accessible)."
  209.     Color 12
  210.     cp 11, "To get the answer and move onto next puzzle, select 1."
  211.     cp 12, "To decode current highlighted letter, select 2."
  212.     cp 13, "To solve a letter, select 3 and then select letter to find."
  213.     cp 14, "To clear a guess at highlighted Code letter, select 4."
  214.     Color 14
  215.     Locate 17, (120 - Len(Answer$)) / 2: Print Coded$
  216.     Color 15
  217.     Locate 18, (120 - Len(Answer$)) / 2
  218.     For i = 1 To Len(Answer$)
  219.         w$ = Mid$(Working$, i, 1): c$ = Mid$(Coded$, i, 1)
  220.         a$ = Mid$(Answer$, i, 1): h$ = Letters$(HighLited)
  221.         If w$ = "*" Then
  222.             pc$ = "*": If h$ = c$ Then Color 15, 9 Else Color 15, 8
  223.         Else
  224.             Color 15, 8: If w$ = UCase$(a$) Then pc$ = a$ Else pc$ = w$
  225.         End If
  226.         Print pc$;
  227.     Next
  228.     spaces = 9
  229.     For i = 1 To 26 'blue background highlighter
  230.         If i = HighLited Then Color 14, 9 Else Color 14, 8
  231.         Locate 21, spaces: Print Letters$(i)
  232.         If i = HighLited Then Color 14, 9 Else Color 15, 8
  233.         Locate 22, spaces: Print Guesses$(i)
  234.         spaces = spaces + 4
  235.     Next
  236.     If Mode = 1 Then
  237.         Color 15, 8
  238.         cp 24, "Guess Solve Letter or Menu #"
  239.     Else
  240.         Color 14, 8
  241.         cp 24, "Select Code Letter or Menu #"
  242.     End If
  243.  
  244. Sub cp (row, text$) ' center text on text screen
  245.     Locate row, 1: Print Space$(_Width) ' clear out old line in case the next is shorter
  246.     Locate row, (_Width - Len(text$)) / 2: Print text$
  247.  
  248. Function choice$ (row, col, selection$)
  249.     fg~& = _DefaultColor: bg~& = _BackgroundColor
  250.     saveRow = CsrLin: saveCol = Pos(0): t = Timer
  251.     GoSub show
  252.     Do
  253.         k$ = InKey$
  254.         If k$ = Chr$(27) Then System ' emergency exit
  255.         GoSub show:
  256.         If k$ = " " Then
  257.             t = Timer: place = (place + 1) Mod Len(selection$)
  258.         Else ' watch out for midnight!
  259.             If Timer - t > 4 Then choice$ = Mid$(selection$, place + 1, 1): Locate saveRow, saveCol: Exit Function
  260.         End If
  261.         _Limit 7 'so can hold down spacebar, nice
  262.     Loop
  263.     show:
  264.     Locate row, col
  265.     For i = 1 To Len(selection$)
  266.         If i = place + 1 Then Color bg~&, fg~& Else Color fg~&, bg~&
  267.         Locate row, col - 1 + i: Print Mid$(selection$, i, 1);
  268.     Next
  269.     Color fg~&, bg~&
  270.     Return
  271.  
  272.  

It's allot easier to play now! Thanks Steve
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: SMcNeill on October 04, 2021, 05:09:47 pm
I’d use _KEYDOWN or INP, over the other input methods like INKEY$, INPUT$, or _KEYHIT.  Reason being?  You don't need to worry over any keyboard buffers screwing things up with those!
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 04, 2021, 06:44:10 pm
OK _KeyDown will replace InKey$ in next update. Seems to not get so carried away when holding down the Spacebar.

Thanks Steve!
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 04, 2021, 06:46:57 pm
Here is the replacement Function in case anyone can't wait to try out:
Code: QB64: [Select]
  1. Function choice$ (row, col, selection$) ' replace InKey$ with _KeyDown()
  2.     fg~& = _DefaultColor: bg~& = _BackgroundColor
  3.     saveRow = CsrLin: saveCol = Pos(0): t = Timer
  4.     GoSub show
  5.     Do
  6.         If _KeyDown(27) Then System ' emergency exit
  7.         GoSub show:
  8.         If _KeyDown(32) Then
  9.             t = Timer: place = (place + 1) Mod Len(selection$)
  10.         Else ' watch out for midnight!
  11.             If Timer - t > 4 Then choice$ = Mid$(selection$, place + 1, 1): Locate saveRow, saveCol: Exit Function
  12.         End If
  13.         _Limit 7 'so can hold down spacebar, nice
  14.     Loop
  15.     show:
  16.     Locate row, col
  17.     For i = 1 To Len(selection$)
  18.         If i = place + 1 Then Color bg~&, fg~& Else Color fg~&, bg~&
  19.         Locate row, col - 1 + i: Print Mid$(selection$, i, 1);
  20.     Next
  21.     Color fg~&, bg~&
  22.     Return
  23.  
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 06, 2021, 11:53:12 am
I had real problem using _Keydown(32) for detecting the spacebar press. Sometimes it would not move at all on a press and sometimes it would jump 2 letters on a press.

I slept on problem and came up with theory: the polling for keypress at 5 times a sec (_Limit 5) is too course a polling, causing the misses or the 2 jumps. So I added an inner loop for polling with _Limit 200 and that seems to remove the erratic behavior and smooth out scrolling down a line of letters.

Here is the updated function:
Code: QB64: [Select]
  1. Function choice$ (row, col, selection$) ' replace InKey$ with _KeyDown()
  2.     fg~& = _DefaultColor: bg~& = _BackgroundColor
  3.     saveRow = CsrLin: saveCol = Pos(0): t = Timer
  4.     GoSub show
  5.     Do
  6.         If _KeyDown(27) Then System ' emergency exit
  7.         GoSub show:
  8.         ' 2021-10-06 fix for polling erratic behavior: misses or jumps, check for spacebar way more often
  9.         While Timer - t < 4 ' smooth out the jumpiness sometimes no response, sometimes jumps 2x' on one press????
  10.             If _KeyDown(27) Then System ' emergency exit
  11.             If _KeyDown(32) Then t = Timer: place = (place + 1) Mod Len(selection$): Exit While
  12.             _Limit 200 '<<<< fine tune the polling for spacebar!!!
  13.         Wend
  14.         If Timer - t >= 4 Then choice$ = Mid$(selection$, place + 1, 1): Locate saveRow, saveCol: Exit Function
  15.         _Limit 5 'so can hold down spacebar, nice
  16.     Loop
  17.     show:
  18.     Locate row, col
  19.     For i = 1 To Len(selection$)
  20.         If i = place + 1 Then Color bg~&, fg~& Else Color fg~&, bg~&
  21.         Locate row, col - 1 + i: Print Mid$(selection$, i, 1);
  22.     Next
  23.     _Display
  24.     Color fg~&, bg~&
  25.     Return
  26.  

Much smoother scroll action, way way less over scroll that Inkey$ would have. I think I have it just right now.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: johnno56 on October 06, 2021, 03:39:20 pm
Very cool... Selection, as you rightly stated, requires a little practice... But still a cool game. Well done!

So... The xmas version... Will it be shades of red, white and green? Hmm...

You could start a series! There are SO many holidays!

Do you do requests? How about a version dedicated to the Hairy-nosed Wombat? Oh. What about the Emu or Red-backed Spider or the Platypus?

If you are "really" desperate for ideas, you can always fall back on, famous quotes; trivia etc... But seriously.... How can you turn down a Wombat?
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 07, 2021, 11:21:33 am
Thanks @johnno56

Still have ways to go with graphics, how are the sounds coming?

I have worms almost done, ran into a some odd problems, a couple solved very late last night one stubborn one remains.
1. Using colors to poison worms, Point recognizes colors set by _RGB32 but apparently not &HFF.... ?

2. Blunder on my part where I clear WormYard (screen section worms are allowed) whenever I send Reset signal with default back color but later want to use image as background so clearing WormYard wipes out image. I see now that could be solved with two different values for reset as opposed to just Yes/No, T/F.

3. I switch to Full Screen Mode in second part of test and demo code and the worms insist on coming in at the old screen size. I think it is some sort of racing problem getting _Width and _Height reset when I run a WorkYard update. Something, it was so late with blurry eyes and mind...
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: SMcNeill on October 07, 2021, 11:57:48 am
@bplus there shouldn't be any issues with &HFF... colors.   Can you share some simplified code highlighting the issue you're speaking of?

The only issue I know you might run into with point and &HFF is of unspecified variable type incompatibility.

Red = &HFFFF0000.   Right??

Maybe not!   Is that value signed or unsigned?  Integer, or Single?  If Red is SINGLE, I doubt it'll match POINT values of _RGB32(255,0,0) as the variable value loses precision.  If RED is LONG, it's not going to match a _RGB32(255,0,0) POINT, as it'll be a negative value and the POINT is positive.

Try this, for instance:

SCREEN _NEWIMAGE(640,480,32)
PSET (0,0), -1&
PRINT -1&, POINT(0,0)

The -1& is a long value color.  The POINT is an unsigned long.  In hex, both would be &HFFFFFFFF, but in decimal mode they're -1 and (some big number).

If you're going to use POINT, make certain all colors are unsigned, or you may get issues in your code.

This includes using &HFFFFFFFF~& instead of just &HFFFFFFFF.   ;D
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 07, 2021, 12:06:45 pm
Hi Steve,

I posted the code I was testing last night with another change that might solve racing problem with a delay before I call NewWormYard to get _Width and _Height updated ? (might be misdiagnosed problem but the extra delay seems to fix the last big bug I had last night.
see https://www.qb64.org/forum/index.php?topic=4266.msg136529#msg136529

As far as color and point goes, fixed when switched to _RGB32 instead og &HFF.... for colors ie,
Set poison boxes with &HFFFFFFFF or &HFFFFFF00 White and Yellow then compared POINT(x,y) to same &HFFFFFFFF or &HFFFFFF00 and no worky. Changed to _RGB32 both setting the boxes and then comparing Point returns to _RGB32 success!
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 07, 2021, 12:15:13 pm
Quote
This includes using &HFFFFFFFF~& instead of just &HFFFFFFFF.   ;D

Oh!! that's probably it then! I never think of the &H numbers as negative, where is the sign?! ;-))

Well there's an important practical lesson, thanks! @SMcNeill
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 07, 2021, 09:45:03 pm
OK DrawWorms installed into Crypt-O-Gram Puzzle, how good are you working with distractions? Moo ha ha

v2021-10-07
Code: QB64: [Select]
  1. _Title "Halloween Challenge: Crypt-O-Gram Puzzle" ' b+  started One Key Challenge 2021-09-25
  2. ' from One Key Challenge - Cryptogram Puzzle   2021-10-02
  3.  
  4. ' 2021-09-07 Jokes are intended for QB64 home programming entertainment use only.
  5. ' Thank you CountryLiving 1-33
  6. ' https://www.countryliving.com/entertaining/a32963261/halloween-jokes/
  7. ' Thank you GoodHousekeeping 34-72
  8. ' https://www.goodhousekeeping.com/holidays/halloween-ideas/a32998753/halloween-jokes/
  9.  
  10. ' 2021-10-03 install new set of jokes and new Binary Select Input Algorithm
  11. ' Redo Mode system to fix differences of input methods.
  12. ' Recolor green background has me seeing Red!
  13.  
  14. ' 2021-10-04 Steve McNeill came up with an easier to understand and use input system.
  15. ' Installing new Function and updating Game. Steve also told me how to change color palette,
  16. ' now we have some real Orange! for #12 meant for high red.
  17.  
  18. ' Next version: Follow Steve's advice to use _KeyDown in stead of InKey$
  19. ' Improved Choice to reduce no response to keypress or double jumping.
  20. ' v 2021-10-07 install DrawWorms subroutines and get working.
  21.  
  22. 'Fall letters and background
  23. Const Orange = &HFFFF8800 ' 12 d
  24. Const White = &HFFFFFFFF ' 15 d
  25. Const Back = &HFF302010 ' 8 ? d
  26. Const Red = &HFFFF2222 ' print under title
  27. Const Yellow = &HFFFFFF00 ' 14 d
  28. Const Blue = &HFF0000FF ' 9 light blue
  29. Const BB = &HFF33BB33 ' 6 blue brown ?
  30. Const Xmax = 120 * 8 ' started with text screen _width 120, 30
  31. Const Ymax = 30 * 16
  32.  
  33. 'for Graphic effects
  34. Const nWorms = 30
  35.  
  36. 'for graphics effects
  37. Type Object
  38.     X As Single ' usu top left corner   could be center depending on object
  39.     Y As Single ' ditto
  40.     W As Single ' width   or maybe radius
  41.     H As Single ' height
  42.     DX As Single ' moving opjects
  43.     DY As Single ' ditto
  44.     DIR As Single ' short for direction or heading usu a radian angle
  45.     Sz As Single ' perhaps a scaling factor
  46.     Act As Integer ' lives countdown or just plain ACTive TF
  47.     C1 As _Unsigned Long ' a foreground color
  48.     C2 As _Unsigned Long ' a background or 2nd color     OR C1 to c2 Range?
  49.  
  50. Screen _NewImage(Xmax, Ymax, 32)
  51. Randomize Timer ': Width 120, 30
  52.  
  53. Dim Shared Answer$ '  beginning phrase to be guessed    '   3 stages of the Puzzle
  54. Dim Shared Coded$ '   hidden in code
  55. Dim Shared Working$ ' decoded and solved when working$ becomes = ucase$(answer$)
  56. Dim Shared Letters$(1 To 26) ' for coding and highlited letters
  57. Dim Shared LCodes$(1 To 26) '  for code and decode by number 1 to 26
  58. Dim Shared Guesses$(1 To 26) ' track all the guess to decode
  59. Dim Shared HighLited ' cursor over letters to guess
  60. Dim Shared Mode
  61.  
  62. ' adding graphics effects
  63. Dim Shared Worms(1 To nWorms) As Object
  64. Dim Shared WormYard As Object
  65.  
  66. _FullScreen 'I guess it does make it easier to tell E from F...
  67.  
  68. Dim jokes$(1 To 100) ' load jokes one time from data statements in program
  69. For i = 1 To 100
  70.     Read r$
  71.     If r$ <> "EOD" Then jokes$(i) = r$: jCount = jCount + 1 Else Exit For
  72.  
  73. restart:
  74.  
  75. 'setup Puzzle and code it
  76. Answer$ = jokes$(Int(Rnd * jCount) + 1)
  77. For i = 1 To 26: Guesses$(i) = "-": Next 'setup the display guesses array
  78. For i = 1 To 26 ' use letters for display of letters to pick second and to create a code
  79.     Letters$(i) = Chr$(i + 64)
  80.     LCodes$(i) = Letters$(i) ' these will convert between each other by index number
  81. For i = 26 To 2 Step -1 ' shuffle the letters in LCode$()
  82.     Swap LCodes$(i), LCodes$(Int(Rnd * i) + 1)
  83. Coded$ = "": Working$ = "" ' reset for next go around
  84. For i = 1 To Len(Answer$) 'third: put the phrase in coded$ and hide it in working$
  85.     a = Asc(UCase$(Answer$), i)
  86.     If a >= 65 And a <= 90 Then
  87.         Coded$ = Coded$ + LCodes$(a - 64)
  88.         Working$ = Working$ + "*"
  89.     Else
  90.         Coded$ = Coded$ + Mid$(Answer$, i, 1)
  91.         Working$ = Working$ + Mid$(Answer$, i, 1)
  92.     End If
  93.  
  94. HighLited = 1 'setup done start game
  95. Mode = 0
  96.  
  97. 'select a grahics effect  on timer
  98. GE = 1 ' <<< convert to pick at random from N effects
  99. nTimer% = _FreeTimer
  100. If GE = 1 Then
  101.     NewWormYard 0, 0, _Width, _Height
  102.     resetWorms% = -1
  103.     DrawWorms resetWorms% ' get draw worms started on a new set o worms
  104.     resetWorms% = 0 ' dont reset while running on timer
  105.     On Timer(0.5) DrawWorms resetWorms%
  106.     Timer On
  107.  
  108. DisplayInstructions '<< this part can be eaten by worms
  109. Update ' this part is critical to continue work on puzzle
  110.     DrawWorms resetWorms
  111.     k$ = choice$(25, 44, " 1234ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  112.     If k$ <> " " Then
  113.         If Mode = 0 Then ' highlight a letter
  114.             'm replaces arrows and mouse select of highlited 1 to 26 for letters
  115.             test = InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", k$)
  116.             If test > 0 Then
  117.                 HighLited = test
  118.                 Mode = 1
  119.             Else
  120.                 test = InStr("1234", k$)
  121.                 If test > 0 Then
  122.                     Select Case test
  123.                         Case 1: GoSub do1
  124.                         Case 2: GoSub do2
  125.                         Case 3: GoSub do3
  126.                         Case 4: GoSub do4
  127.                     End Select
  128.                 Else
  129.                     Mode = 0
  130.                 End If
  131.             End If
  132.         Else
  133.             Select Case k$
  134.                 Case "1": GoSub do1
  135.                 Case "2": GoSub do2
  136.                 Case "3": GoSub do3
  137.                 Case "4": GoSub do4
  138.                 Case "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
  139.                     Guesses$(HighLited) = k$ ' for screen updates
  140.                     For i = 1 To Len(Working$)
  141.                         If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = k$
  142.                     Next
  143.                     Mode = 0
  144.             End Select
  145.         End If
  146.     End If
  147.     Update
  148.     _Limit 60
  149. Loop Until Working$ = UCase$(Answer$)
  150. Update
  151. Color Orange, Back
  152. cp 19, "You got it!    5 secs to next puzzle..."
  153. GoTo restart
  154.  
  155. do1: ' display answer
  156. Working$ = UCase$(Answer$) ' show the answer$ guesses correct moves to next puzzle
  157. Mode = 0
  158. Update
  159.  
  160. do2: ' get decode letter for highlighted Letter
  161. For i = 1 To 26
  162.     If LCodes$(i) = Letters$(HighLited) Then c$ = Chr$(i + 64): Exit For
  163. Guesses$(HighLited) = c$ ' for screen updates
  164. For i = 1 To Len(Working$)
  165.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = c$
  166. Update
  167. Mode = 0
  168.  
  169. do3: ' find a uncoded letter
  170. Color White, Back
  171. cp 24, "     Select Letter to Find     "
  172. Locate 25, 1: Print Space$(100); ' clear out old line
  173. d$ = choice$(25, 46, " ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  174. If d$ <> " " Then
  175.     c$ = LCodes$(Asc(d$) - 64)
  176.     Guesses$(Asc(c$) - 64) = d$
  177.     For i = 1 To Len(Working$)
  178.         If c$ = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = d$
  179.     Next
  180.     Mode = 0
  181.     Update
  182.  
  183. do4: ' clear guess letter from code letter
  184. Guesses$(HighLited) = "-"
  185. For i = 1 To Len(Working$)
  186.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = "*" ' clear the letter
  187. Mode = 0
  188. Update
  189.  
  190. 'one liners
  191. Data "Why do ghosts go on diets? So they can keep their ghoulish figures"
  192. Data "Where does a ghost go on vacation? Mali-boo."
  193. Data "Why did the ghost go into the bar? For the Boos."
  194. Data "What is in a ghost's nose? Boo-gers."
  195. Data "Why did the policeman ticket the ghost on Halloween? It didn't have a haunting license."
  196. Data "Why do demons and ghouls hang out together? Because demons are a ghoul's best friend!"
  197. Data "Why did the ghost starch his sheet? He wanted everyone scared stiff."
  198. Data "What does a panda ghost eat? Bam-BOO!"
  199. Data "What's a ghost's favorite dessert? I-Scream!"
  200. Data "Where do ghosts buy their food? At the ghost-ery store!"
  201. Data "How do you know when a ghost is sad? He starts boo hooing."
  202. Data "Why don't mummies take time off? They're afraid to unwind."
  203. Data "Why did the headless horseman go into business? He wanted to get ahead in life."
  204. Data "What kind of music do mummies like listening to on Halloween? Wrap music."
  205. Data "Why don't mummies have friends? Because they're too wrapped up in themselves."
  206. Data "Why did the vampire read the newspaper? He heard it had great circulation."
  207. Data "How do vampires get around on Halloween? On blood vessels."
  208. Data "What's it like to be kissed by a vampire? It's a pain in the neck."
  209. Data "What's it called when a vampire has trouble with his house? A grave problem."
  210. Data "How can you tell when a vampire has been in a bakery? All the jelly has been sucked out of the jelly doughnuts."
  211. Data "What do you get when you cross a vampire and a snowman? Frostbite."
  212. Data "Why do skeletons have low self-esteem? They have no body to love."
  213. Data "Know why skeletons are so calm? Because nothing gets under their skin."
  214. Data "What do you call a cleaning skeleton? The grim sweeper."
  215. Data "What do skeletons order at a restaurant? Spare ribs."
  216. Data "What do you call a witch's garage? A broom closet."
  217. Data "What kind of food would you find on a haunted beach? A sand-witch!"
  218. Data "What was the witch's favorite subject in school? Spelling."
  219. Data "What do you call two witches who live together? Broom-mates!"
  220. Data "What's a witch's favorite makeup? Ma-scare-a."
  221. Data "Who helps the little pumpkins cross the road safely? The crossing gourd."
  222. Data "What treat do eye doctors give out on Halloween? Candy corneas."
  223. Data "What type of plants do well on all Hallow's Eve? Bam-BOO!"
  224. Data "What do birds say on Halloween? Trick or tweet!"
  225. Data "Why don't skeletons ever go trick or treating? Because they have no-body to go with."
  226. Data "Where do ghosts buy their Halloween candy? At the ghost-ery store!"
  227. Data "What do owls say when they go trick or treating? 'Happy Owl-ween!'"
  228. Data "What do ghosts give out to trick or treaters? Booberries!"
  229. Data "Who did Frankenstein go trick or treating with? His ghoul friend."
  230. Data "What Halloween candy is never on time for the party? Choco-LATE!"
  231. Data "What do witches put on to go trick or treating? Mas-scare-a."
  232. Data "What does Bigfoot say when he asks for candy?  'Trick-or-feet!'"
  233. Data "Which type of pants do ghosts wear to trick or treat? Boo jeans."
  234. Data "What makes trick or treating with twin witches so challenging? You never know which witch is which!"
  235. Data "What happens when a vampire goes in the snow? Frost bite!"
  236. Data "What do you call two witches living together? Broommates"
  237. Data "What position does a ghost play in hockey? Ghoulie."
  238. Data "What do mummies listen to on Halloween? Wrap music."
  239. Data "How do you make a skeleton laugh? You tickle his funny bone!"
  240. Data "Which Halloween monster is good at math? Count Dracula!"
  241. Data "Why did the Cyclops give up teaching? He only had one pupil!"
  242. Data "Why didn't the skeleton go to see a scary movie? He didn't have the guts."
  243. Data "What did the boy ghost say to the girl ghost? 'You sure are boo-tiful!'"
  244. Data "Where does Dracula keep his money? In a blood bank."
  245. Data "Why are ghosts terrible liars? You can see right through them!"
  246. Data "Why don't mummies take vacations? They're afraid to unwind."
  247. Data "What is a vampire's favorite holiday, besides Halloween? Fangs-giving!"
  248. Data "Where do fashionable ghosts shop? Bootiques!"
  249. Data "What's a monster's favorite play? Romeo and Ghouliet!"
  250. Data "What room does a ghost not need? A living room."
  251. Data "What monster plays tricks on Halloween? Prank-enstein!"
  252. Data "What's a ghost's favorite dessert? I scream."
  253. Data "What does the skeleton chef say when he serves you a meal? 'Bone Appetit!'"
  254. Data "What is a vampire's favorite fruit? A neck-tarine!"
  255. Data "What do witches put on their bagels? Scream cheese."
  256. Data "What do ghosts eat for dinner? Spook-ghetti!"
  257. Data "What do skeletons order at restaurants? Spare ribs."
  258. Data "What does a panda ghost eat? Bam-BOO!"
  259. Data "What tops off a mummy's ice cream sundae? Whipped scream."
  260. Data "What's a ghost's favorite yogurt flavor? Boo-berry!"
  261. Data "What's a vampire's least favorite meal? A steak!"
  262. Data "Why was the candy corn booed off the stage? All of his jokes were too corny!"
  263. Data "EOD"
  264.  
  265. Sub Update ' preserve from ravages of graphics effects ;-))
  266.     Color Yellow
  267.     Locate 17, (120 - Len(Answer$)) / 2: Print Coded$;
  268.     Color White
  269.     Locate 18, (120 - Len(Answer$)) / 2
  270.     For i = 1 To Len(Answer$)
  271.         w$ = Mid$(Working$, i, 1): c$ = Mid$(Coded$, i, 1)
  272.         a$ = Mid$(Answer$, i, 1): h$ = Letters$(HighLited)
  273.         If w$ = "*" Then
  274.             pc$ = "*": If h$ = c$ Then Color White, Blue Else Color White, Back
  275.         Else
  276.             Color White, Back: If w$ = UCase$(a$) Then pc$ = a$ Else pc$ = w$
  277.         End If
  278.         Print pc$;
  279.     Next
  280.     spaces = 9
  281.     For i = 1 To 26 'blue background highlighter
  282.         If i = HighLited Then Color Yellow, Blue Else Color Yellow, Back
  283.         Locate 21, spaces: Print Letters$(i);
  284.         If i = HighLited Then Color Yellow, Blue Else Color White, Back
  285.         Locate 22, spaces: Print Guesses$(i);
  286.         spaces = spaces + 4
  287.     Next
  288.     If Mode = 1 Then
  289.         Color White, Back
  290.         cp 24, "  Guess Solve Letter or Menu # "
  291.     Else
  292.         Color Yellow, Back
  293.         cp 24, "  Select Code Letter or Menu # "
  294.     End If
  295.     _Display
  296.  
  297. Sub DisplayInstructions ' only once let worms eat them up as game goes on
  298.     Color Orange, Back: Cls
  299.     cp 4, "*** Halloween Challenge - Crypt-O-Gram Puzzle ***"
  300.     Color Red
  301.     cp 6, "Solve puzzle by selecting a Code letter then selecting a Guess letter for it."
  302.     cp 7, "All selections are made by pressing spacebar when you see your letter or digit."
  303.     cp 8, "You will need to verify your selection by pressing spacebar again when see Y for Yes."
  304.     cp 9, "Use the escape key to quit immediately (an X box in top right is not accessible)."
  305.     Color BB
  306.     cp 11, "To get the answer and move onto next puzzle, select 1."
  307.     cp 12, "To decode current highlighted letter, select 2."
  308.     cp 13, "To solve a letter, select 3 and then select letter to find."
  309.     cp 14, "To clear a guess at highlighted Code letter, select 4."
  310.     _Display
  311.  
  312. Sub cp (row, text$) ' center text on text screen
  313.     'Locate row, 1: Print Space$(_Width) ' clear out old line in case the next is shorter
  314.     'Locate row, 1: Print Space$(Xmax / 8);  'text screen
  315.     ' clear old line was interferring with worm trails
  316.     Locate row, (Xmax / 8 - Len(text$)) / 2: Print text$;
  317.  
  318. Function choice$ (row, col, selection$) ' replace InKey$ with _KeyDown()
  319.     fg~& = _DefaultColor: bg~& = _BackgroundColor
  320.     saveRow = CsrLin: saveCol = Pos(0): t = Timer
  321.     GoSub show
  322.     Do
  323.         If _KeyDown(27) Then System ' emergency exit
  324.         GoSub show:
  325.         ' 2021-10-06 fix for polling erratic behavior: misses or jumps, check for spacebar way more often
  326.         While Timer - t < 4 ' smooth out the jumpiness sometimes no response, sometimes jumps 2x' on one press????
  327.             If _KeyDown(27) Then System ' emergency exit
  328.             If _KeyDown(32) Then t = Timer: place = (place + 1) Mod Len(selection$): Exit While
  329.             _Limit 200 '<<<< fine tune the polling for spacebar!!!
  330.         Wend
  331.         If Timer - t >= 4 Then choice$ = Mid$(selection$, place + 1, 1): Locate saveRow, saveCol: Exit Function
  332.         _Limit 5 'so can hold down spacebar, nice
  333.     Loop
  334.     show:
  335.     Locate row, col
  336.     For i = 1 To Len(selection$)
  337.         If i = place + 1 Then Color bg~&, fg~& Else Color fg~&, bg~&
  338.         Locate row, col - 1 + i: Print Mid$(selection$, i, 1);
  339.     Next
  340.     _Display
  341.     Color fg~&, bg~&
  342.     Return
  343.  
  344. Sub DrawWorms (DrawReset As Integer) ' one frame in main loop
  345.     Static x(1 To nWorms, 1 To 20), y(1 To nWorms, 1 To 20)
  346.     If DrawReset Then
  347.         For i = 1 To nWorms
  348.             NewWorm i
  349.             For j = 1 To 20
  350.                 x(i, j) = 0: y(i, j) = 0
  351.             Next
  352.         Next
  353.         DrawReset = 0
  354.     End If
  355.     For i = 1 To nWorms
  356.         Fcirc Worms(i).X, Worms(i).Y, 8, &HFF000000 ' fix 2021-10-07 to prevent program hangs
  357.         If _KeyDown(27) Then Exit Sub
  358.         For j = 1 To Worms(i).Sz ' blackout old segments
  359.             If x(i, j) And y(i, j) Then Fcirc x(i, j), y(i, j), 8, &HFF000000
  360.         Next
  361.         tryAgain:
  362.         If _KeyDown(27) Then Exit Sub
  363.         If Rnd < .3 Then Worms(i).DX = Worms(i).DX + .8 * Rnd - .4 Else Worms(i).DY = Worms(i).DY + .8 * Rnd - .4
  364.         If Abs(Worms(i).DX) > 2 Then Worms(i).DX = Worms(i).DX * .5
  365.         If Abs(Worms(i).DY) > 2 Then Worms(i).DY = Worms(i).DY * .5
  366.         x = Worms(i).X + Worms(i).DX * 2.0: y = Worms(i).Y + Worms(i).DY * 2.0
  367.         good = -1
  368.         If x >= WormYard.X + 6 And x <= WormYard.X + WormYard.W - 6 Then
  369.             If y >= WormYard.Y + 6 And y <= WormYard.Y + WormYard.H - 6 Then
  370.                 For yy = y - 6 To y + 6
  371.                     For xx = x - 6 To x + 6
  372.                         If Point(xx, yy) = _RGB32(255, 255, 255) Or Point(xx, yy) = _RGB32(255, 255, 0) Then good = 0: Exit For
  373.                     Next
  374.                     If good = 0 Then Exit For
  375.                 Next
  376.             Else
  377.                 good = 0
  378.             End If
  379.         Else
  380.             good = 0
  381.         End If
  382.         If good = 0 Then 'turn the worm
  383.             'Beep: Locate 1, 1: Print x, y
  384.             'Input "enter >", w$
  385.             If Rnd > .5 Then 'change dx
  386.                 If Worms(i).DX Then
  387.                     Worms(i).DX = -Worms(i).DX
  388.                 Else
  389.                     If Rnd > .5 Then Worms(i).DX = 1 Else Worms(i).DX = -1
  390.                 End If
  391.             Else
  392.                 If Worms(i).DY Then
  393.                     Worms(i).DY = -Worms(i).DY
  394.                 Else
  395.                     If Rnd > .5 Then Worms(i).DY = 1 Else Worms(i).DY = -1
  396.                 End If
  397.             End If
  398.             GoTo tryAgain
  399.         End If
  400.         For j = Worms(i).Sz To 2 Step -1
  401.             x(i, j) = x(i, j - 1): y(i, j) = y(i, j - 1)
  402.             If x(i, j) And y(i, j) Then DrawBall x(i, j), y(i, j), 6, Worms(i).C1
  403.         Next
  404.         x(i, 1) = x: y(i, 1) = y
  405.         DrawBall x(i, 1), y(i, 1), 6, Worms(i).C1
  406.         Worms(i).X = x: Worms(i).Y = y
  407.     Next i 'worm index
  408.     _Display
  409.  
  410. Sub NewWormYard (x, y, w, h)
  411.     WormYard.X = x: WormYard.Y = y: WormYard.W = w: WormYard.H = h
  412.     For i = 1 To nWorms
  413.         NewWorm i
  414.     Next
  415.  
  416. Sub NewWorm (i)
  417.     'pick which side to enter, for dx, dy generally headed towards inner screen
  418.     side = Int(Rnd * 4)
  419.     Select Case side
  420.         Case 0 ' left side
  421.             Worms(i).X = WormYard.X + 6
  422.             Worms(i).Y = WormYard.Y + 6 + (WormYard.H - 12) * Rnd
  423.             Worms(i).DX = 1
  424.             Worms(i).DY = 0
  425.         Case 1 'right side
  426.             Worms(i).X = WormYard.X + WormYard.W - 6
  427.             Worms(i).Y = WormYard.Y + 6 + (WormYard.H - 12) * Rnd
  428.             Worms(i).DX = -1
  429.             Worms(i).DY = 0
  430.         Case 2 ' top
  431.             Worms(i).Y = WormYard.Y + 6
  432.             Worms(i).X = WormYard.X + 6 + (WormYard.W - 12) * Rnd
  433.             Worms(i).DX = 0
  434.             Worms(i).DY = 1
  435.         Case 3 'bottom
  436.             Worms(i).Y = WormYard.Y + WormYard.H - 6
  437.             Worms(i).X = WormYard.X + 6 + (WormYard.W - 12) * Rnd
  438.             Worms(i).DX = 0
  439.             Worms(i).DY = -1
  440.     End Select
  441.     Worms(i).Sz = Int(Rnd * 11) + 10
  442.     side = Int(Rnd * 4): lev = Int(Rnd * 10)
  443.     If side = 0 Then
  444.         Worms(i).C1 = _RGB32(255 - 20 * lev + 50, 180 - 15 * lev, 180 - 15 * lev)
  445.     ElseIf side = 1 Then
  446.         Worms(i).C1 = _RGB32(255 - 20 * lev, 180 - 15 * lev + 50, 180 - 15 * lev)
  447.     ElseIf side = 2 Then
  448.         Worms(i).C1 = _RGB32(255 - 20 * lev, 180 - 15 * lev, 180 - 15 * lev + 20)
  449.     ElseIf side = 3 Then
  450.         Worms(i).C1 = _RGB32(255 - 20 * lev, 180 - 15 * lev, 180 - 15 * lev)
  451.     End If
  452.  
  453. Sub Fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  454.     Dim Radius As Long, RadiusError As Long
  455.     Dim X As Long, Y As Long
  456.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  457.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  458.     Line (CX - X, CY)-(CX + X, CY), C, BF
  459.     While X > Y
  460.         RadiusError = RadiusError + Y * 2 + 1
  461.         If RadiusError >= 0 Then
  462.             If X <> Y + 1 Then
  463.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  464.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  465.             End If
  466.             X = X - 1
  467.             RadiusError = RadiusError - X * 2
  468.         End If
  469.         Y = Y + 1
  470.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  471.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  472.     Wend
  473.  
  474. Sub DrawBall (x, y, r, c As _Unsigned Long)
  475.     Dim rred As Long, grn As Long, blu As Long, rr As Long, f
  476.     rred = _Red32(c): grn = _Green32(c): blu = _Blue32(c)
  477.     For rr = r To 0 Step -1
  478.         f = 1.25 - rr / r
  479.         Fcirc x, y, rr, _RGB32(rred * f, grn * f, blu * f)
  480.     Next
  481.  

Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 08, 2021, 07:14:51 am
The GoSub routine do3: was clearing a line across the screen which cut into the worm trails looking funky. Here is the fix for do3:
Code: QB64: [Select]
  1. do3: ' find a uncoded letter
  2. Color White, Back
  3. cp 24, "     Select Letter to Find     "
  4. Locate 25, 44: Print Space$(31); ' clear out old line
  5. d$ = choice$(25, 46, " ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  6. If d$ <> " " Then
  7.     c$ = LCodes$(Asc(d$) - 64)
  8.     Guesses$(Asc(c$) - 64) = d$
  9.     For i = 1 To Len(Working$)
  10.         If c$ = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = d$
  11.     Next
  12.     Mode = 0
  13.     Update
  14.  

This just clears the exact text length that needed clearing, instead of the whole line.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: johnno56 on October 08, 2021, 10:10:38 am
I am testing single word comments. Seems to be a little easier to understand. Give them a try.... If you can think of any others just let me know.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: Pete on October 08, 2021, 06:18:02 pm
Let's go Brandon!

I wonder what that would dcryptify to?

Okay, neat looking screen presentation and I have to admit, the "Demons are a ghoul's best friend made me chuckle. Hey, didn't Steve have some word game in the works for this challenge? What was it called again, The Alphabator? You keep pulling letters and... Never mind.

Hey Mark, you could marry that to POWERSHELL and get the computer to give the answer over the speaker. Text to Speech is a nice feature. Just a thought.

    t
Pe e
   ^ (Word bump this!)
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 08, 2021, 09:51:37 pm
Quote
"Demons are a ghoul's best friend

@Pete oh ha! I thought you were talking about @johnno56 comments, that's a joke I haven't gotten to yet!
Nice idea of using speech to text, I can and have done that in for windows apps. I had an app, "Henny pecked", that told one-liners Henny Youngman style, actually allot of Steve Write jokes.

Yeah @johnno56 take a break on the sounds, letters and selections probably will get boring, I think I have some Halloween music and sound effects might be better. (PS those words were not so clear to me, letters and multiple words seemed better to me?)

When trying to add spiders to graphics effects I had a hell of a time with multiple timers basically wasted the morning.

2 steps forward one back, I rewrote Choice$ function again! This time to use the main Loop and no extracurricular excursions into indy loops. It is actually working really sweet making input go much smoother. Now with some adjustments I can add effects much easier without timers.

Here is spiders added to worms with new Choice$ and allot of other rework.
v2021-10-08
Code: QB64: [Select]
  1. _Title "Halloween Challenge: Crypt-O-Gram Puzzle" ' b+  started One Key Challenge 2021-09-25
  2. ' from One Key Challenge - Cryptogram Puzzle   2021-10-02
  3.  
  4. ' 2021-09-07 Jokes are intended for QB64 home programming entertainment use only.
  5. ' Thank you CountryLiving 1-33
  6. ' https://www.countryliving.com/entertaining/a32963261/halloween-jokes/
  7. ' Thank you GoodHousekeeping 34-72
  8. ' https://www.goodhousekeeping.com/holidays/halloween-ideas/a32998753/halloween-jokes/
  9.  
  10. ' 2021-10-03 install new set of jokes and new Binary Select Input Algorithm
  11. ' Redo Mode system to fix differences of input methods.
  12. ' Recolor green background has me seeing Red!
  13.  
  14. ' 2021-10-04 Steve McNeill came up with an easier to understand and use input system.
  15. ' Installing new Function and updating Game. Steve also told me how to change color palette,
  16. ' now we have some real Orange! for #12 meant for high red.
  17.  
  18. ' Next version: Follow Steve's advice to use _KeyDown in stead of InKey$
  19. ' Improved Choice to reduce no response to keypress or double jumping.
  20. ' v 2021-10-07 install DrawWorms subroutines and get working.
  21.  
  22. ' v 2021-10-08: fix do3, blanking whole line or nearly, it disturbs worm trails.
  23. ' Add a spider screen for overlaying spiders wo changing the background.
  24. ' Man this is so screwed up... I'm taking another approach.
  25. ' ... rewrites and tests
  26. ' Now do3 completely rewritten as mode 3 along with Choice$ function
  27. ' Much better!! rewrote the way Choice works, no time consuming loops outside main loop,
  28. ' so no delaysin graphics effects so no need for timers. Only one side screen needed
  29. ' for tracking Worm Trails. Had to slow worms and Spider dowm for a _Limit 30 for everything.
  30.  
  31.  
  32. 'Fall letters and background
  33. Const Orange = &HFFFF8800 ' 12 d
  34. Const Back = &HFF302010 ' 8 ? d
  35. Const Red = &HFFFF2222 ' print under title
  36. Const Blue = &HFF0000FF ' 9 light blue
  37. Const BB = &HFF33BB33 ' 6 blue brown ?
  38. Const Xmax = 120 * 8 ' started with text screen _width 120, 30
  39. Const Ymax = 30 * 16
  40.  
  41. 'for Graphic effects
  42. Const nWorms = 30
  43. Const nSpiders = 15
  44.  
  45. 'for graphics effects
  46. Type Object
  47.     X As Single ' usu top left corner   could be center depending on object
  48.     Y As Single ' ditto
  49.     W As Single ' width   or maybe radius
  50.     H As Single ' height
  51.     DX As Single ' moving opjects
  52.     DY As Single ' ditto
  53.     DIR As Single ' short for direction or heading usu a radian angle
  54.     Sz As Single ' perhaps a scaling factor
  55.     Act As Integer ' lives countdown or just plain ACTive TF
  56.     C1 As _Unsigned Long ' a foreground color
  57.     C2 As _Unsigned Long ' a background or 2nd color     OR C1 to c2 Range?
  58. Dim Shared As _Unsigned Long White, Yellow
  59. White = _RGB32(255, 255, 255): Yellow = _RGB32(255, 255, 0) ' I give up, yellow and white aren't stopping the worms
  60. Dim Shared Answer$ '  beginning phrase to be guessed    '   3 stages of the Puzzle
  61. Dim Shared Coded$ '   hidden in code
  62. Dim Shared Working$ ' decoded and solved when working$ becomes = ucase$(answer$)
  63. Dim Shared Letters$(1 To 26) ' for coding and highlited letters
  64. Dim Shared LCodes$(1 To 26) '  for code and decode by number 1 to 26
  65. Dim Shared Guesses$(1 To 26) ' track all the guess to decode
  66. Dim Shared HighLited ' cursor over letters to guess
  67. Dim Shared Mode ' what are we getting a coded letter =0, a guess for that letter =1, a letter to find and decode=3
  68. Dim Shared KeyTimer
  69. Dim Shared Place
  70.  
  71. ' adding graphics effects
  72. ReDim Shared Worms(1 To nWorms) As Object
  73. Dim Shared WormYard As Object
  74. ReDim Shared S(1 To nSpiders) As Object ' Spider 0 is a spinner?
  75. Dim Shared WT As Long ' worm screen to track Worm Trails
  76.  
  77. ' main declares
  78. Dim jokes$(1 To 100) ' load jokes one time from data statements in program
  79. Dim As Integer i, resetWorms, si, jCount, a, lc, test
  80. Dim r$, k$, c$
  81.  
  82. Screen _NewImage(Xmax, Ymax, 32)
  83. Randomize Timer ': Width 120, 30 converted to graphics screen
  84. _FullScreen 'I guess it does make it easier to tell E from F...
  85.  
  86. WS = _NewImage(Xmax, Ymax, 32)
  87. For i = 1 To 100 'ready jokes
  88.     Read r$
  89.     If r$ <> "EOD" Then jokes$(i) = r$: jCount = jCount + 1 Else Exit For
  90. restart:
  91.  
  92. 'setup Puzzle and code it
  93. Answer$ = jokes$(Int(Rnd * jCount) + 1)
  94. For i = 1 To 26: Guesses$(i) = "-": Next 'setup the display guesses array
  95. For i = 1 To 26 ' use letters for display of letters to pick second and to create a code
  96.     Letters$(i) = Chr$(i + 64)
  97.     LCodes$(i) = Letters$(i) ' these will convert between each other by index number
  98. For i = 26 To 2 Step -1 ' shuffle the letters in LCode$()
  99.     Swap LCodes$(i), LCodes$(Int(Rnd * i) + 1)
  100. Coded$ = "": Working$ = "" ' reset for next go around
  101. For i = 1 To Len(Answer$) 'third: put the phrase in coded$ and hide it in working$
  102.     a = Asc(UCase$(Answer$), i)
  103.     If a >= 65 And a <= 90 Then
  104.         Coded$ = Coded$ + LCodes$(a - 64)
  105.         Working$ = Working$ + "*"
  106.     Else
  107.         Coded$ = Coded$ + Mid$(Answer$, i, 1)
  108.         Working$ = Working$ + Mid$(Answer$, i, 1)
  109.     End If
  110. If WT Then _FreeImage WT ' clear WormTrails for new game
  111. WT = _NewImage(Xmax, Ymax, 32)
  112. ReDim Worms(1 To nWorms) As Object ' clear old arrays
  113. NewWormYard 0, 0, Xmax, Ymax
  114. resetWorms = -1
  115. ReDim S(1 To nSpiders) As Object
  116. si = 0: lc = 0
  117. HighLited = 1 'setup done start game
  118. Mode = 0
  119.  
  120. KeyTimer = Timer
  121.     Color , Back: Cls
  122.     DisplayInstructions '<< this part can be eaten by worms very bottom of drawing
  123.     _PutImage , WT, 0 ' the worm trails
  124.     Update ' need yellow and white to slow worms
  125.     DrawWorms resetWorms ' yellow and white not working???
  126.     lc = lc + 1
  127.     If lc Mod 300 = 299 Then 'drawSpiders
  128.         If si < nSpiders Then si = si + 1: newSpinner si
  129.     End If
  130.     For i = 1 To si
  131.         drawSpinner S(i).X, S(i).Y, S(i).Sz, _Atan2(S(i).DY, S(i).DX), S(i).C1
  132.         S(i).X = S(i).X + S(i).DX: S(i).Y = S(i).Y + S(i).DY
  133.         If S(i).X < -100 Or S(i).X > Xmax + 100 Or S(i).Y < -100 Or S(i).Y > Ymax + 100 Then newSpinner i
  134.     Next
  135.     'Update ' on top of every thing sets color to mode
  136.     If Mode = 3 Then
  137.         k$ = choice$(25, 33, " A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ")
  138.     Else
  139.         k$ = choice$(25, 29, " 1 2 3 4 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ")
  140.     End If
  141.     If k$ <> "" And k$ <> " " Then
  142.         If Mode = 0 Then ' highlight a letter
  143.             'm replaces arrows and mouse select of highlited 1 to 26 for letters
  144.             test = InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", k$)
  145.             If test > 0 Then
  146.                 HighLited = test
  147.                 Mode = 1
  148.             Else
  149.                 test = InStr("1234", k$)
  150.                 If test > 0 Then
  151.                     Select Case test
  152.                         Case 1: GoSub do1
  153.                         Case 2: GoSub do2
  154.                         Case 3: Mode = 3
  155.                         Case 4: GoSub do4
  156.                     End Select
  157.                 Else
  158.                     Mode = 0
  159.                 End If
  160.             End If
  161.         ElseIf Mode = 1 Then
  162.             Select Case k$
  163.                 Case "1": GoSub do1
  164.                 Case "2": GoSub do2
  165.                 Case "3": Mode = 3
  166.                 Case "4": GoSub do4
  167.                 Case "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
  168.                     Guesses$(HighLited) = k$ ' for screen updates
  169.                     For i = 1 To Len(Working$)
  170.                         If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = k$
  171.                     Next
  172.                     Mode = 0
  173.             End Select
  174.         ElseIf Mode = 3 Then
  175.             Locate 25, 44: Print Space$(31); ' clear out old line
  176.             c$ = LCodes$(Asc(k$) - 64)
  177.             Guesses$(Asc(c$) - 64) = k$
  178.             For i = 1 To Len(Working$)
  179.                 If c$ = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = k$
  180.             Next
  181.             Mode = 0
  182.         End If
  183.     End If
  184.     _Limit 30
  185.     _Display
  186. Loop Until Working$ = UCase$(Answer$)
  187. Update
  188. Color Orange, Back
  189. cp 19, "You got it!    5 secs to next puzzle..."
  190. GoTo restart
  191.  
  192. do1: ' display answer
  193. Working$ = UCase$(Answer$) ' show the answer$ guesses correct moves to next puzzle
  194. Mode = 0
  195.  
  196. do2: ' get decode letter for highlighted Letter
  197. For i = 1 To 26
  198.     If LCodes$(i) = Letters$(HighLited) Then c$ = Chr$(i + 64): Exit For
  199. Guesses$(HighLited) = c$ ' for screen updates
  200. For i = 1 To Len(Working$)
  201.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = c$
  202. Mode = 0
  203.  
  204. do4: ' clear guess letter from code letter
  205. Guesses$(HighLited) = "-"
  206. For i = 1 To Len(Working$)
  207.     If Letters$(HighLited) = Mid$(Coded$, i, 1) Then Mid$(Working$, i, 1) = "*" ' clear the letter
  208. Mode = 0
  209. Update
  210.  
  211. 'one liners
  212. Data "Why do ghosts go on diets? So they can keep their ghoulish figures"
  213. Data "Where does a ghost go on vacation? Mali-boo."
  214. Data "Why did the ghost go into the bar? For the Boos."
  215. Data "What is in a ghost's nose? Boo-gers."
  216. Data "Why did the policeman ticket the ghost on Halloween? It didn't have a haunting license."
  217. Data "Why do demons and ghouls hang out together? Because demons are a ghoul's best friend!"
  218. Data "Why did the ghost starch his sheet? He wanted everyone scared stiff."
  219. Data "What does a panda ghost eat? Bam-BOO!"
  220. Data "What's a ghost's favorite dessert? I-Scream!"
  221. Data "Where do ghosts buy their food? At the ghost-ery store!"
  222. Data "How do you know when a ghost is sad? He starts boo hooing."
  223. Data "Why don't mummies take time off? They're afraid to unwind."
  224. Data "Why did the headless horseman go into business? He wanted to get ahead in life."
  225. Data "What kind of music do mummies like listening to on Halloween? Wrap music."
  226. Data "Why don't mummies have friends? Because they're too wrapped up in themselves."
  227. Data "Why did the vampire read the newspaper? He heard it had great circulation."
  228. Data "How do vampires get around on Halloween? On blood vessels."
  229. Data "What's it like to be kissed by a vampire? It's a pain in the neck."
  230. Data "What's it called when a vampire has trouble with his house? A grave problem."
  231. Data "How can you tell when a vampire has been in a bakery? All the jelly has been sucked out of the jelly doughnuts."
  232. Data "What do you get when you cross a vampire and a snowman? Frostbite."
  233. Data "Why do skeletons have low self-esteem? They have no body to love."
  234. Data "Know why skeletons are so calm? Because nothing gets under their skin."
  235. Data "What do you call a cleaning skeleton? The grim sweeper."
  236. Data "What do skeletons order at a restaurant? Spare ribs."
  237. Data "What do you call a witch's garage? A broom closet."
  238. Data "What kind of food would you find on a haunted beach? A sand-witch!"
  239. Data "What was the witch's favorite subject in school? Spelling."
  240. Data "What do you call two witches who live together? Broom-mates!"
  241. Data "What's a witch's favorite makeup? Ma-scare-a."
  242. Data "Who helps the little pumpkins cross the road safely? The crossing gourd."
  243. Data "What treat do eye doctors give out on Halloween? Candy corneas."
  244. Data "What type of plants do well on all Hallow's Eve? Bam-BOO!"
  245. Data "What do birds say on Halloween? Trick or tweet!"
  246. Data "Why don't skeletons ever go trick or treating? Because they have no-body to go with."
  247. Data "Where do ghosts buy their Halloween candy? At the ghost-ery store!"
  248. Data "What do owls say when they go trick or treating? 'Happy Owl-ween!'"
  249. Data "What do ghosts give out to trick or treaters? Booberries!"
  250. Data "Who did Frankenstein go trick or treating with? His ghoul friend."
  251. Data "What Halloween candy is never on time for the party? Choco-LATE!"
  252. Data "What do witches put on to go trick or treating? Mas-scare-a."
  253. Data "What does Bigfoot say when he asks for candy?  'Trick-or-feet!'"
  254. Data "Which type of pants do ghosts wear to trick or treat? Boo jeans."
  255. Data "What makes trick or treating with twin witches so challenging? You never know which witch is which!"
  256. Data "What happens when a vampire goes in the snow? Frost bite!"
  257. Data "What do you call two witches living together? Broommates"
  258. Data "What position does a ghost play in hockey? Ghoulie."
  259. Data "What do mummies listen to on Halloween? Wrap music."
  260. Data "How do you make a skeleton laugh? You tickle his funny bone!"
  261. Data "Which Halloween monster is good at math? Count Dracula!"
  262. Data "Why did the Cyclops give up teaching? He only had one pupil!"
  263. Data "Why didn't the skeleton go to see a scary movie? He didn't have the guts."
  264. Data "What did the boy ghost say to the girl ghost? 'You sure are boo-tiful!'"
  265. Data "Where does Dracula keep his money? In a blood bank."
  266. Data "Why are ghosts terrible liars? You can see right through them!"
  267. Data "Why don't mummies take vacations? They're afraid to unwind."
  268. Data "What is a vampire's favorite holiday, besides Halloween? Fangs-giving!"
  269. Data "Where do fashionable ghosts shop? Bootiques!"
  270. Data "What's a monster's favorite play? Romeo and Ghouliet!"
  271. Data "What room does a ghost not need? A living room."
  272. Data "What monster plays tricks on Halloween? Prank-enstein!"
  273. Data "What's a ghost's favorite dessert? I scream."
  274. Data "What does the skeleton chef say when he serves you a meal? 'Bone Appetit!'"
  275. Data "What is a vampire's favorite fruit? A neck-tarine!"
  276. Data "What do witches put on their bagels? Scream cheese."
  277. Data "What do ghosts eat for dinner? Spook-ghetti!"
  278. Data "What do skeletons order at restaurants? Spare ribs."
  279. Data "What does a panda ghost eat? Bam-BOO!"
  280. Data "What tops off a mummy's ice cream sundae? Whipped scream."
  281. Data "What's a ghost's favorite yogurt flavor? Boo-berry!"
  282. Data "What's a vampire's least favorite meal? A steak!"
  283. Data "Why was the candy corn booed off the stage? All of his jokes were too corny!"
  284. Data "EOD"
  285.  
  286. Sub Update ' preserve from ravages of graphics effects ;-))
  287.     Dim As Integer i, spaces
  288.     Dim w$, c$, a$, h$, pc$
  289.     Color Yellow, Back
  290.     Locate 17, (120 - Len(Answer$)) / 2: Print Coded$;
  291.     Color White, Back
  292.     Locate 18, (120 - Len(Answer$)) / 2
  293.     For i = 1 To Len(Answer$)
  294.         w$ = Mid$(Working$, i, 1): c$ = Mid$(Coded$, i, 1)
  295.         a$ = Mid$(Answer$, i, 1): h$ = Letters$(HighLited)
  296.         If w$ = "*" Then
  297.             pc$ = "*": If h$ = c$ Then Color White, Blue Else Color White, Back
  298.         Else
  299.             Color White, Back: If w$ = UCase$(a$) Then pc$ = a$ Else pc$ = w$
  300.         End If
  301.         Print pc$;
  302.     Next
  303.     spaces = 9
  304.     For i = 1 To 26 'blue background highlighter
  305.         If i = HighLited Then Color Yellow, Blue Else Color Yellow, Back
  306.         Locate 21, spaces: Print Letters$(i);
  307.         If i = HighLited Then Color Yellow, Blue Else Color White, Back
  308.         Locate 22, spaces: Print Guesses$(i);
  309.         spaces = spaces + 4
  310.     Next
  311.     If Mode = 1 Then
  312.         Color White, Back
  313.         cp 24, "  Guess Solve Letter or Menu # "
  314.         cp 25, String$(31, "W") ' for worm poison (the fore color)
  315.     ElseIf Mode = 0 Then
  316.         Color Yellow, Back
  317.         cp 24, "  Select Code Letter or Menu # "
  318.         cp 25, String$(31, "W") ' for worm poison (the fore color)
  319.     ElseIf Mode = 3 Then
  320.         Color White, Back
  321.         cp 24, "     Select Letter to Find     "
  322.         cp 25, String$(31, "W") ' for worm poison (the fore color)
  323.     End If
  324.  
  325. Sub DisplayInstructions ' only once let worms eat them up as game goes on
  326.     Color Orange, Back: Cls
  327.     cp 4, "*** Halloween Challenge - Crypt-O-Gram Puzzle ***"
  328.     Color Red
  329.     cp 6, "Solve puzzle by selecting a Code letter then selecting a Guess letter for it."
  330.     cp 7, "All selections are made by pressing spacebar when you see your letter or digit."
  331.     cp 8, "You will need to verify your selection by pressing spacebar again when see Y for Yes."
  332.     cp 9, "Use the escape key to quit immediately (an X box in top right is not accessible)."
  333.     Color BB
  334.     cp 11, "To get the answer and move onto next puzzle, select 1."
  335.     cp 12, "To decode current highlighted letter, select 2."
  336.     cp 13, "To solve a letter, select 3 and then select letter to find."
  337.     cp 14, "To clear a guess at highlighted Code letter, select 4."
  338.  
  339. Sub cp (row, text$) ' center text on text screen
  340.     'Locate row, 1: Print Space$(_Width) ' clear out old line in case the next is shorter
  341.     'Locate row, 1: Print Space$(Xmax / 8);  'text screen
  342.     ' clear old line was interferring with worm trails
  343.     Locate row, (Xmax / 8 - Len(text$)) / 2: Print text$;
  344.  
  345. Function choice$ (row, col, selection$) ' replace InKey$ with _KeyDown()
  346.     Dim As _Unsigned Long fg, bg
  347.     Dim As Integer saveRow, saveCol, i
  348.     Dim k$
  349.     fg~& = _DefaultColor: bg~& = _BackgroundColor
  350.     saveRow = CsrLin: saveCol = Pos(0)
  351.     If _KeyDown(27) Then System ' emergency exit
  352.     GoSub show:
  353.     k$ = InKey$
  354.     If _KeyDown(27) Then System ' emergency exit
  355.     If k$ = " " Then KeyTimer = Timer: Place = (Place + 1) Mod Len(selection$)
  356.     If Timer - KeyTimer >= 4 Then choice$ = Mid$(selection$, Place + 1, 1): Place = 0
  357.     Locate saveRow, saveCol: Exit Function
  358.  
  359.     show:
  360.     Locate row, col
  361.     For i = 1 To Len(selection$)
  362.         If i = Place + 1 Then Color bg~&, fg~& Else Color fg~&, bg~&
  363.         Locate row, col - 1 + i: Print Mid$(selection$, i, 1);
  364.     Next
  365.     '_Display
  366.     Color fg~&, bg~&
  367.     Return
  368.  
  369. Sub DrawWorms (DrawReset As Integer) ' one frame in main loop
  370.     Static x(1 To nWorms, 1 To 20), y(1 To nWorms, 1 To 20)
  371.     Dim M As _MEM
  372.     Dim As Integer i, j, good
  373.     Dim As Single x, y, xx, yy
  374.     _Source 0
  375.     If DrawReset Then
  376.         'M = _Mem(x())
  377.         '_MemFill M, M.OFFSET, M.SIZE, 0 As _BYTE 'reset the array, Thanks Steve
  378.         'M = _Mem(y())
  379.         '_MemFill M, M.OFFSET, M.SIZE, 0 As _BYTE 'reset the array, eh didn't work
  380.         For i = 1 To nWorms
  381.             NewWorm i
  382.             For j = 1 To 20
  383.                 x(i, j) = 0: y(i, j) = 0
  384.             Next
  385.         Next
  386.         DrawReset = 0
  387.     End If
  388.     For i = 1 To nWorms
  389.         _Dest WT
  390.         Fcirc Worms(i).X, Worms(i).Y, 6, &HFF000000
  391.         _Dest 0
  392.         If _KeyDown(27) Then Exit Sub
  393.         For j = 1 To Worms(i).Sz ' blackout old segments
  394.             If x(i, j) And y(i, j) Then Fcirc x(i, j), y(i, j), 8, &HFF000000
  395.         Next
  396.  
  397.         If Rnd < .15 Then 'move the worm  (gots to slow down the worms)
  398.             tryAgain:
  399.             If _KeyDown(27) Then Exit Sub
  400.             If Rnd < .3 Then Worms(i).DX = Worms(i).DX + .8 * Rnd - .4 Else Worms(i).DY = Worms(i).DY + .8 * Rnd - .4
  401.             If Worms(i).DX ^ 2 + Worms(i).DY ^ 2 > 2 Then
  402.                 Worms(i).DX = Worms(i).DX * .5: Worms(i).DY = Worms(i).DY * .5
  403.             End If
  404.             x = Worms(i).X + Worms(i).DX * 2.0: y = Worms(i).Y + Worms(i).DY * 2.0
  405.             good = -1
  406.             If x >= WormYard.X + 6 And x <= WormYard.X + WormYard.W - 6 Then
  407.                 If y >= WormYard.Y + 6 And y <= WormYard.Y + WormYard.H - 6 Then
  408.                     For yy = y - 6 To y + 6
  409.                         For xx = x - 6 To x + 6
  410.                             If Point(xx, yy) = White Or Point(xx, yy) = Yellow Then good = 0: Exit For
  411.                         Next
  412.                         If good = 0 Then Exit For
  413.                     Next
  414.                 Else
  415.                     good = 0
  416.                 End If
  417.             Else
  418.                 good = 0
  419.             End If
  420.             If good = 0 Then 'turn the worm
  421.                 If Rnd > .5 Then 'change dx
  422.                     If Worms(i).DX Then
  423.                         Worms(i).DX = -Worms(i).DX
  424.                     Else
  425.                         If Rnd > .5 Then Worms(i).DX = 1 Else Worms(i).DX = -1
  426.                     End If
  427.                 Else
  428.                     If Worms(i).DY Then
  429.                         Worms(i).DY = -Worms(i).DY
  430.                     Else
  431.                         If Rnd > .5 Then Worms(i).DY = 1 Else Worms(i).DY = -1
  432.                     End If
  433.                 End If
  434.                 GoTo tryAgain
  435.             End If
  436.  
  437.             For j = Worms(i).Sz To 2 Step -1
  438.                 x(i, j) = x(i, j - 1): y(i, j) = y(i, j - 1)
  439.                 If x(i, j) And y(i, j) Then DrawBall x(i, j), y(i, j), 6, Worms(i).C1
  440.             Next
  441.             x(i, 1) = x: y(i, 1) = y
  442.             DrawBall x(i, 1), y(i, 1), 6, Worms(i).C1
  443.             Worms(i).X = x: Worms(i).Y = y
  444.         Else
  445.             For j = Worms(i).Sz To 2 Step -1
  446.                 If x(i, j) And y(i, j) Then DrawBall x(i, j), y(i, j), 6, Worms(i).C1
  447.             Next
  448.             DrawBall x(i, 1), y(i, 1), 6, Worms(i).C1
  449.         End If
  450.     Next i 'worm index
  451.  
  452. Sub NewWormYard (x, y, w, h)
  453.     WormYard.X = x: WormYard.Y = y: WormYard.W = w: WormYard.H = h
  454.  
  455. Sub NewWorm (i)
  456.     Dim As Integer side, lev
  457.     'pick which side to enter, for dx, dy generally headed towards inner screen
  458.     side = Int(Rnd * 4)
  459.     Select Case side
  460.         Case 0 ' left side
  461.             Worms(i).X = WormYard.X + 6
  462.             Worms(i).Y = WormYard.Y + 6 + (WormYard.H - 12) * Rnd
  463.             Worms(i).DX = 1
  464.             Worms(i).DY = 0
  465.         Case 1 'right side
  466.             Worms(i).X = WormYard.X + WormYard.W - 6
  467.             Worms(i).Y = WormYard.Y + 6 + (WormYard.H - 12) * Rnd
  468.             Worms(i).DX = -1
  469.             Worms(i).DY = 0
  470.         Case 2 ' top
  471.             Worms(i).Y = WormYard.Y + 6
  472.             Worms(i).X = WormYard.X + 6 + (WormYard.W - 12) * Rnd
  473.             Worms(i).DX = 0
  474.             Worms(i).DY = 1
  475.         Case 3 'bottom
  476.             Worms(i).Y = WormYard.Y + WormYard.H - 6
  477.             Worms(i).X = WormYard.X + 6 + (WormYard.W - 12) * Rnd
  478.             Worms(i).DX = 0
  479.             Worms(i).DY = -1
  480.     End Select
  481.     Worms(i).Sz = Int(Rnd * 11) + 10
  482.     side = Int(Rnd * 4): lev = Int(Rnd * 10)
  483.     If side = 0 Then
  484.         Worms(i).C1 = _RGB32(255 - 20 * lev + 50, 180 - 15 * lev, 180 - 15 * lev)
  485.     ElseIf side = 1 Then
  486.         Worms(i).C1 = _RGB32(255 - 20 * lev, 180 - 15 * lev + 50, 180 - 15 * lev)
  487.     ElseIf side = 2 Then
  488.         Worms(i).C1 = _RGB32(255 - 20 * lev, 180 - 15 * lev, 180 - 15 * lev + 20)
  489.     ElseIf side = 3 Then
  490.         Worms(i).C1 = _RGB32(255 - 20 * lev, 180 - 15 * lev, 180 - 15 * lev)
  491.     End If
  492.  
  493. Sub newSpinner (i As Integer) 'set Spinners dimensions start angles, color?
  494.     Dim r As Integer
  495.     S(i).Sz = Rnd * .2 + .4
  496.     If Rnd < .5 Then r = -1 Else r = 1
  497.     S(i).DX = (S(i).Sz * Rnd * 2 + 2) * r * 1.25: S(i).DY = (S(i).Sz * Rnd * 2 + 2) * r * 1.25
  498.     r = Int(Rnd * 4)
  499.     Select Case r
  500.         Case 0: S(i).X = Rnd * (Xmax - 120) + 60: S(i).Y = 0: If S(i).DY < 0 Then S(i).DY = -S(i).DY
  501.         Case 1: S(i).X = Rnd * (Xmax - 120) + 60: S(i).Y = Ymax: If S(i).DY > 0 Then S(i).DY = -S(i).DY
  502.         Case 2: S(i).X = 0: S(i).Y = Rnd * (Ymax - 120) + 60: If S(i).DX < 0 Then S(i).DX = -S(i).DX
  503.         Case 3: S(i).X = Xmax: S(i).Y = Rnd * (Ymax - 120) + 60: If S(i).DX > 0 Then S(i).DX = -S(i).DX
  504.     End Select
  505.     r = Rnd * 90 + 30
  506.     S(i).C1 = _RGB32(r, Rnd * .5 * r, Rnd * .25 * r) 'red ghost spiders???
  507.  
  508. Sub drawSpinner (x As Integer, y As Integer, scale As Single, heading As Single, c As _Unsigned Long)
  509.     Dim x1, x2, x3, x4, y1, y2, y3, y4, r, a, a1, a2, lg, d, rd
  510.     Dim rred, bblue, ggreen
  511.     Static switch As Integer
  512.     switch = switch + 2
  513.     switch = switch Mod 16 + 1
  514.     rred = _Red32(c): ggreen = _Green32(c): bblue = _Blue32(c)
  515.     r = 10 * scale
  516.     x1 = x + r * Cos(heading): y1 = y + r * Sin(heading)
  517.     r = 2 * r 'lg lengths
  518.     For lg = 1 To 8
  519.         If lg < 5 Then
  520.             a = heading + .9 * lg * _Pi(1 / 5) + (lg = switch) * _Pi(1 / 10)
  521.         Else
  522.             a = heading - .9 * (lg - 4) * _Pi(1 / 5) - (lg = switch) * _Pi(1 / 10)
  523.         End If
  524.         x2 = x1 + r * Cos(a): y2 = y1 + r * Sin(a)
  525.         drawLink x1, y1, 3 * scale, x2, y2, 2 * scale, _RGB32(rred + 20, ggreen + 10, bblue + 5)
  526.         If lg = 1 Or lg = 2 Or lg = 7 Or lg = 8 Then d = -1 Else d = 1
  527.         a1 = a + d * _Pi(1 / 12)
  528.         x3 = x2 + r * 1.5 * Cos(a1): y3 = y2 + r * 1.5 * Sin(a1)
  529.         drawLink x2, y2, 2 * scale, x3, y3, scale, _RGB32(rred + 35, ggreen + 17, bblue + 8)
  530.         rd = Int(Rnd * 8) + 1
  531.         a2 = a1 + d * _Pi(1 / 8) * rd / 8
  532.         x4 = x3 + r * 1.5 * Cos(a2): y4 = y3 + r * 1.5 * Sin(a2)
  533.         drawLink x3, y3, scale, x4, y4, scale, _RGB32(rred + 50, ggreen + 25, bblue + 12)
  534.     Next
  535.     r = r * .5
  536.     Fcirc x1, y1, r, _RGB32(rred - 20, ggreen - 10, bblue - 5)
  537.     x2 = x1 + (r + 1) * Cos(heading - _Pi(1 / 12)): y2 = y1 + (r + 1) * Sin(heading - _Pi(1 / 12))
  538.     Fcirc x2, y2, r * .2, &HFF000000
  539.     x2 = x1 + (r + 1) * Cos(heading + _Pi(1 / 12)): y2 = y1 + (r + 1) * Sin(heading + _Pi(1 / 12))
  540.     Fcirc x2, y2, r * .2, &HFF000000
  541.     r = r * 2
  542.     x1 = x + r * .9 * Cos(heading + _Pi): y1 = y + r * .9 * Sin(heading + _Pi)
  543.     TiltedEllipseFill 0, x1, y1, r, .7 * r, heading + _Pi, _RGB32(rred, ggreen, bblue)
  544.  
  545. Sub drawLink (x1, y1, r1, x2, y2, r2, c As _Unsigned Long)
  546.     Dim a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  547.     a = _Atan2(y2 - y1, x2 - x1)
  548.     a1 = a + _Pi(1 / 2)
  549.     a2 = a - _Pi(1 / 2)
  550.     x3 = x1 + r1 * Cos(a1): y3 = y1 + r1 * Sin(a1)
  551.     x4 = x1 + r1 * Cos(a2): y4 = y1 + r1 * Sin(a2)
  552.     x5 = x2 + r2 * Cos(a1): y5 = y2 + r2 * Sin(a1)
  553.     x6 = x2 + r2 * Cos(a2): y6 = y2 + r2 * Sin(a2)
  554.     fquad x3, y3, x4, y4, x5, y5, x6, y6, c
  555.     Fcirc x1, y1, r1, c
  556.     Fcirc x2, y2, r2, c
  557.  
  558. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  559. Sub fquad (x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, x3 As Integer, y3 As Integer, x4 As Integer, y4 As Integer, c As _Unsigned Long)
  560.     ftri x1, y1, x2, y2, x4, y4, c
  561.     ftri x3, y3, x4, y4, x1, y1, c
  562.  
  563. Sub ftri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
  564.     Dim a&
  565.     a& = _NewImage(1, 1, 32)
  566.     _Dest a&
  567.     PSet (0, 0), K
  568.     _Dest 0
  569.     _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
  570.     _FreeImage a& '<<< this is important!
  571.  
  572. Sub TiltedEllipseFill (destHandle&, x0, y0, a, b, ang, c As _Unsigned Long)
  573.     Dim max As Integer, mx2 As Integer, i As Integer, j As Integer, k As Single, lasti As Single, lastj As Single
  574.     Dim prc As _Unsigned Long, tef As Long
  575.     prc = _RGB32(255, 255, 255, 255)
  576.     If a > b Then max = a + 1 Else max = b + 1
  577.     mx2 = max + max
  578.     tef = _NewImage(mx2, mx2)
  579.     _Dest tef
  580.     _Source tef 'point wont read without this!
  581.     For k = 0 To 6.2832 + .05 Step .1
  582.         i = max + a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
  583.         j = max + a * Cos(k) * Sin(ang) - b * Sin(k) * Cos(ang)
  584.         If k <> 0 Then
  585.             Line (lasti, lastj)-(i, j), prc
  586.         Else
  587.             PSet (i, j), prc
  588.         End If
  589.         lasti = i: lastj = j
  590.     Next
  591.     Dim xleft(mx2) As Integer, xright(mx2) As Integer, x As Integer, y As Integer
  592.     For y = 0 To mx2
  593.         x = 0
  594.         While Point(x, y) <> prc And x < mx2
  595.             x = x + 1
  596.         Wend
  597.         xleft(y) = x
  598.         While Point(x, y) = prc And x < mx2
  599.             x = x + 1
  600.         Wend
  601.         While Point(x, y) <> prc And x < mx2
  602.             x = x + 1
  603.         Wend
  604.         If x = mx2 Then xright(y) = xleft(y) Else xright(y) = x
  605.     Next
  606.     _Dest destHandle&
  607.     For y = 0 To mx2
  608.         If xleft(y) <> mx2 Then Line (xleft(y) + x0 - max, y + y0 - max)-(xright(y) + x0 - max, y + y0 - max), c, BF
  609.     Next
  610.     _FreeImage tef
  611.  
  612. Sub Fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  613.     Dim Radius As Long, RadiusError As Long
  614.     Dim X As Long, Y As Long
  615.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  616.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  617.     Line (CX - X, CY)-(CX + X, CY), C, BF
  618.     While X > Y
  619.         RadiusError = RadiusError + Y * 2 + 1
  620.         If RadiusError >= 0 Then
  621.             If X <> Y + 1 Then
  622.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  623.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  624.             End If
  625.             X = X - 1
  626.             RadiusError = RadiusError - X * 2
  627.         End If
  628.         Y = Y + 1
  629.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  630.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  631.     Wend
  632.  
  633. Sub DrawBall (x, y, r, c As _Unsigned Long)
  634.     Dim rred As Long, grn As Long, blu As Long, rr As Long, f
  635.     rred = _Red32(c): grn = _Green32(c): blu = _Blue32(c)
  636.     For rr = r To 0 Step -1
  637.         f = 1.25 - rr / r
  638.         Fcirc x, y, rr, _RGB32(rred * f, grn * f, blu * f)
  639.     Next
  640.  
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: johnno56 on October 09, 2021, 12:59:28 am
Break suggested? Advice taken. Let me know if you need anything else?
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 09, 2021, 08:20:26 am
Break suggested? Advice taken. Let me know if you need anything else?

Creepy Crypt Sound effects? (I like Pete's thunderstorm stuff, TheBob's pumpkin is great too but I have my own pumpkin I want to use.)

Oh hey, I need a ghost writer to get better jokes than what's in the Data section ;-))

Oh wait... we could do those (jokes other than ones in puzzle) in sound (oh maybe those jokes too that would be a nice trick or treat read the answer amongst the many told verbally while user is trying to concentrate on puzzle).
 
@johnno56 I prefer your sound files that are cross platform than using Windows only speech synthesis.

Maybe jokes not needed, just some haunting torment for the user while he attempts to decode a dead joke, moo ha ha. Make the user think he's died and gone to bad joke hell, AKA Pete's heaven.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: johnno56 on October 09, 2021, 09:02:19 am
Regardless of whether the synthesis is Windows-based or not, how can the 'results' be classified as 'non cross platform'? I can output the audio format to many types. I use 'ogg' because the compression is higher than 'wav' and 'mp3'...  I am confused... (not even a chuckle... lol)
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 09, 2021, 09:05:24 am
Windows speech synthesis, I think, can only be used in... wait for it.

Windows!

I mean it seems logical to me.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 09, 2021, 09:07:43 am
@johnno56 if you give me sound stuff that works for you, and I test it and it works for me too, then I know 2 OS's at least that they will work. 2 is good enough for me to say cross platform.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 10, 2021, 02:37:47 am
Well I try again, here is version 2021-10-10 of Crypto-O-Gram with 3 background sound and graphics effects. Had a last minute change of music files because the one I had was too big for forum post.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 11, 2021, 11:41:41 am
Ha! my bad timing to post above with all this new stuff with QB64 happening ;(

Then mpgcan stuff, wow!

Well I thought pretty good graphics and sound added, b+ at least, Moo ha ha.
Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 11, 2021, 12:18:10 pm
Some screen shots from what may be my last Graphics version for Halloween Challenge (I think I have some ideas for Screen 0 extra credit version).

Title: Re: Crypt-O-Gram Puzzle - Halloween Challenge
Post by: bplus on October 11, 2021, 12:37:47 pm
PS everything in this Crypt-0-gram Puzzle program is working fine in QB64 v2.0.

I did have to update all my Handy Functions that used the Function Name to build$ the string I was going to return with the Function call ;-(  actually wasn't hard to fix. Ironically the first program I tested QB64 v2.0 was Text Fetch and that was hard to figure out what was going on because the program was complex and I of course didn't remember what variable did what! Had me stumped for awhile but after figuring that I needed a build$ variable instead of Function name, all went sooth! This was before I watched Fellippe's video on $Debug but I don't think that would have helped with Function$ fixes.