Author Topic: CryptoGram finished!  (Read 5308 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
CryptoGram finished!
« on: September 07, 2021, 09:36:54 pm »
This is a code word game. You are given a phrase in code. You have to decode it. These types of puzzles are often found in a newspaper. I hope you like it.
Code: QB64: [Select]
  1. GOTO beginning
  2. crap:
  3. PRINT "Error, Line number"
  4. beginning:
  5. WIDTH 80, 50
  6. CONST TRUE = 1
  7. CONST FALSE = 0
  8. CONST numberOfLines = 15
  9. CONST Easy = 1
  10. CONST Normal = 2
  11. CONST arrowKeyMove$ = "L64O2C"
  12. CONST enterKeyHit$ = "L45O4C"
  13.  
  14. DIM SHARED leftArrow$: leftArrow$ = CHR$(0) + "K"
  15. DIM SHARED rightArrow$: rightArrow$ = CHR$(0) + "M"
  16. DIM SHARED upArrow$: upArrow$ = CHR$(0) + "H"
  17. DIM SHARED downArrow$: downArrow$ = CHR$(0) + "P"
  18. DIM SHARED translationMatrix$(1 TO 26, 1 TO 2): FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": NEXT cl
  19. DIM SHARED codedPhrase$: codedPhrase$ = ""
  20. DIM SHARED answerPhrase$: answerPhrase$ = ""
  21. DIM SHARED highlightedLetter: highlightedLetter = 0
  22. DIM SHARED workingLines$(1 TO numberOfLines)
  23. DIM SHARED initiallyCodedLines$(1 TO numberOfLines)
  24. DIM SHARED answerLines$(1 TO numberOfLines)
  25. DIM SHARED leftPositions(1 TO numberOfLines) AS INTEGER
  26. DIM SHARED maxLineNumber: maxLineNumber = 0
  27. DIM SHARED usersCode$(1 TO 26, 1 TO 2): FOR x = 1 TO 26: usersCode$(x, 1) = CHR$(x + 64): usersCode$(x, 2) = "-": NEXT x
  28. DIM SHARED mode: mode = Normal
  29. DIM SHARED loaded: loaded = FALSE
  30. DIM SHARED numberOfPhrases
  31. FOR cl = 1 TO numberOfLines
  32.     workingLines$(cl) = ""
  33.     initiallyCodedLines$(cl) = ""
  34.     answerLines$(cl) = ""
  35.     leftPositions(cl) = 0
  36. NEXT cl
  37.  
  38. CALL Menu
  39.  
  40. SUB Menu
  41.     opt = 1
  42.     mode = Normal
  43.     PrintAgain:
  44.     COLOR 14, 2: CLS: tabs = 25
  45.     a$ = "Main Menu": LOCATE 13, Center(a$): PRINT a$:
  46.     LOCATE 14, Center(a$) - 1: PRINT "-----------"
  47.     COLOR 14, 2: a$ = "Mode = Easy  Normal":
  48.     LOCATE 16, Center(a$): PRINT "Mode = ";
  49.     IF mode = Easy THEN
  50.         COLOR 14, 0
  51.     ELSEIF mode = Normal THEN
  52.         COLOR 14, 2
  53.     END IF
  54.     PRINT "Easy";: COLOR 14, 2: PRINT " ";
  55.     IF mode = Normal THEN
  56.         COLOR 14, 0
  57.     ELSEIF mode = Normal THEN
  58.         COLOR 14, 2
  59.     END IF
  60.     PRINT "Normal"
  61.  
  62.     LOCATE 19, tabs
  63.     COLOR 15, 2: PRINT "1.) ";
  64.     IF opt = 1 THEN
  65.         COLOR 14, 0:
  66.     ELSE
  67.         COLOR 14, 2
  68.     END IF
  69.     PRINT "Instructions"
  70.  
  71.     LOCATE 21, tabs
  72.     COLOR 15, 2: PRINT "2.) ";
  73.     IF opt = 2 THEN
  74.         COLOR 14, 0
  75.     ELSE
  76.         COLOR 14, 2
  77.     END IF
  78.     PRINT "New Game"
  79.  
  80.     LOCATE 23, tabs
  81.     COLOR 15, 2: PRINT "3.) ";
  82.     IF opt = 3 THEN
  83.         COLOR 14, 0
  84.     ELSE
  85.         COLOR 14, 2
  86.     END IF
  87.     PRINT "Load a Saved Game"
  88.  
  89.     LOCATE 25, tabs
  90.     COLOR 15, 2: PRINT "4.) ";
  91.     IF opt = 4 THEN
  92.         COLOR 14, 0
  93.     ELSE
  94.         COLOR 14, 2
  95.     END IF
  96.     PRINT "Add New Phrase to Data File"
  97.  
  98.     LOCATE 27, tabs
  99.     COLOR 15, 2: PRINT "5.) ";
  100.     IF opt = 5 THEN
  101.         COLOR 14, 0
  102.     ELSE
  103.         COLOR 14, 2
  104.     END IF
  105.     PRINT "End Game"
  106.     DO
  107.         choice$ = INKEY$
  108.         SELECT CASE choice$
  109.             CASE upArrow$
  110.                 opt = opt - 1
  111.                 IF opt = 0 THEN opt = 5
  112.                 PLAY arrowKeyMove$
  113.                 GOTO PrintAgain
  114.             CASE leftArrow$
  115.                 IF mode = Easy THEN
  116.                     mode = Normal
  117.                 ELSEIF mode = Normal THEN
  118.                     mode = Easy
  119.                 END IF
  120.                 PLAY arrowKeyMove$
  121.                 GOTO PrintAgain
  122.             CASE downArrow$
  123.                 opt = opt + 1
  124.                 IF opt = 6 THEN opt = 1
  125.                 PLAY arrowKeyMove$
  126.                 GOTO PrintAgain
  127.             CASE rightArrow$
  128.                 IF mode = Easy THEN
  129.                     mode = Normal
  130.                 ELSEIF mode = Normal THEN
  131.                     mode = Easy
  132.                 END IF
  133.                 PLAY arrowKeyMove$
  134.                 GOTO PrintAgain
  135.             CASE CHR$(13)
  136.                 PLAY enterKeyHit$
  137.                 IF opt = 1 THEN CALL Instructions
  138.                 IF opt = 2 THEN CALL Main
  139.                 IF opt = 3 THEN CALL LoadGame
  140.                 IF opt = 4 THEN CALL AddPhrase
  141.                 IF opt = 5 THEN END
  142.                 GOTO PrintAgain
  143.             CASE "1"
  144.                 PLAY enterKeyHit$
  145.                 CALL Instructions
  146.                 GOTO PrintAgain
  147.             CASE "2"
  148.                 PLAY enterKeyHit$
  149.                 loaded = FALSE
  150.                 CALL Main
  151.                 GOTO PrintAgain
  152.             CASE "3"
  153.                 PLAY enterKeyHit$
  154.                 loaded = TRUE
  155.                 CALL LoadGame
  156.                 GOTO PrintAgain
  157.             CASE "4"
  158.                 PLAY enterKeyHit$
  159.                 CALL AddPhrase
  160.                 GOTO PrintAgain
  161.             CASE "5"
  162.                 PLAY enterKeyHit$
  163.                 END
  164.         END SELECT
  165.     LOOP UNTIL choice$ = CHR$(13) OR choice$ = "5"
  166.  
  167. SUB Instructions
  168.     COLOR 10, 13: CLS
  169.     a$ = "A random phrase picked from " + CHR$(34) + "Phrases.txt" + CHR$(34) + " will be displayed in code."
  170.     LOCATE 12, Center(a$): PRINT a$
  171.     a$ = "The goal is to decode the phrase. The coded letters are in one color": LOCATE 14, Center(a$): PRINT a$
  172.     a$ = "and the letters you choose in another color. In easy mode, incorrect": LOCATE 16, Center(a$): PRINT a$
  173.     a$ = "letters are displayed in yet another color. Different types": LOCATE 18, Center(a$): PRINT a$
  174.     a$ = "of hints are available from the hint menu.": LOCATE 20, Center(a$): PRINT a$
  175.     a$ = "Use the arrow keys to select the letter you wish to change. Type": LOCATE 25, Center(a$): PRINT a$
  176.     a$ = "in the letter you wish to change it to. Push the [ESC] key": LOCATE 27, Center(a$): PRINT a$
  177.     a$ = "to reset the puzzle to the starting code.": LOCATE 29, Center(a$): PRINT a$
  178.  
  179.     a$ = "Hit any key to return to the Main Menu": LOCATE 45, Center(a$): COLOR 11, 13: PRINT a$: l$ = P$
  180.  
  181. SUB AddPhrase
  182.     COLOR 11, 13
  183.     CLS
  184.     a$ = "Type in the phrase you want to add. Do not hit": LOCATE 15, Center(a$): PRINT a$
  185.     a$ = " the [ENTER] key until you've entered the entire phrase. ": LOCATE 17, Center(a$): PRINT a$
  186.     a$ = "Don't worry if your entry passes the end of the screen": LOCATE 19, Center(a$): PRINT a$
  187.     a$ = "and continues on to the next line. In fact, longer": LOCATE 21, Center(a$): PRINT a$
  188.     a$ = "phrases are easier to decode.": LOCATE 23, Center(a$): PRINT a$
  189.  
  190.     LOCATE 28, 10: LINE INPUT "Type in your phrase: ", newPhrase$
  191.     maxIndex = FileStatus
  192.     DIM fileArray$(1 TO maxIndex + 1)
  193.     OPEN "Phrases.txt" FOR INPUT AS #1
  194.     FOR index = 1 TO maxIndex
  195.         LINE INPUT #1, fileArray$(index)
  196.     NEXT index
  197.     CLOSE #1
  198.  
  199.     fileArray$(maxIndex + 1) = newPhrase$
  200.     OPEN "Phrases.txt" FOR OUTPUT AS #1
  201.     FOR index = 1 TO maxIndex + 1
  202.         PRINT #1, fileArray$(index)
  203.     NEXT index
  204.     PRINT #1, "EOF"
  205.     CLOSE #1
  206.  
  207.  
  208. SUB LoadGame
  209.     maxLineNumber = 0
  210.     FOR index = 1 TO 26
  211.         translationMatrix$(index, 1) = "": translationMatrix$(index, 2) = ""
  212.         usersCode$(index, 1) = "": usersCode$(index, 2) = ""
  213.     NEXT index
  214.     codedPhrase$ = ""
  215.     answerPhrase$ = ""
  216.     highlightedLetter = 0
  217.     mode = 0
  218.     FOR index = 1 TO 15
  219.         workingLines$(index) = ""
  220.         initiallyCodedLines$(index) = ""
  221.         answerLines$(index) = ""
  222.         leftPositions(index) = 0
  223.     NEXT index
  224.  
  225.     OPEN "CryptoGram" FOR INPUT AS #1
  226.     LINE INPUT #1, mLN$: maxLineNumber = VAL(mLN$)
  227.     FOR index = 1 TO 26
  228.         LINE INPUT #1, translationMatrix$(index, 1)
  229.         LINE INPUT #1, translationMatrix$(index, 2)
  230.         LINE INPUT #1, usersCode$(index, 1)
  231.         LINE INPUT #1, usersCode$(index, 2)
  232.     NEXT index
  233.     LINE INPUT #1, codedPhrase$
  234.     LINE INPUT #1, answerPhrase$
  235.     LINE INPUT #1, hL$: PRINT hL$: g$ = P$: highlightedLetter = VAL(hL$)
  236.     LINE INPUT #1, m$: mode = VAL(m$)
  237.     FOR index = 1 TO maxLineNumber
  238.         LINE INPUT #1, workingLines$(index)
  239.         LINE INPUT #1, initiallyCodedLines$(index)
  240.         LINE INPUT #1, answerLines$(index)
  241.         LINE INPUT #1, lP$: leftPositions(index) = VAL(lP$)
  242.     NEXT index
  243.     CLOSE #1
  244.     loaded = TRUE: CALL Main
  245.  
  246. SUB SaveGame
  247.     OPEN "CryptoGram" FOR OUTPUT AS #1
  248.     PRINT #1, S$(maxLineNumber)
  249.     FOR index = 1 TO 26
  250.         PRINT #1, translationMatrix$(index, 1)
  251.         PRINT #1, translationMatrix$(index, 2)
  252.         PRINT #1, usersCode$(index, 1)
  253.         PRINT #1, usersCode$(index, 2)
  254.     NEXT index
  255.     PRINT #1, codedPhrase$
  256.     PRINT #1, answerPhrase$
  257.     PRINT #1, S$(highlightedLetter)
  258.     PRINT #1, S$(mode)
  259.     FOR index = 1 TO maxLineNumber
  260.         PRINT #1, workingLines$(index)
  261.         PRINT #1, initiallyCodedLines$(index)
  262.         PRINT #1, answerLines$(index)
  263.         PRINT #1, S$(leftPositions(index))
  264.     NEXT index
  265.     CLOSE #1
  266.     _DELAY (0.25)
  267.     PLAY arrowKeyMove$
  268.  
  269. SUB Main
  270.     IF loaded = FALSE THEN
  271.  
  272.         COLOR 15, 1
  273.         'first, pick a phrase
  274.         randomPhrase = INT(RND * FileStatus) + 1
  275.         OPEN "Phrases.txt" FOR INPUT AS #1
  276.         FOR x = 1 TO randomPhrase
  277.             LINE INPUT #1, answerPhrase$
  278.         NEXT x
  279.         CLOSE #1
  280.  
  281.         'second, create a code
  282.         usedAlphabet$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  283.         FOR allLetters = 1 TO 26
  284.             translationMatrix$(allLetters, 1) = CHR$(allLetters + 64)
  285.             newRndLet:
  286.             randomLetter = INT(RND * LEN(usedAlphabet$)) + 1
  287.             translationMatrix$(allLetters, 2) = MID$(usedAlphabet$, randomLetter, 1)
  288.             IF translationMatrix$(allLetters, 1) = translationMatrix$(allLetters, 2) THEN GOTO newRndLet
  289.             usedAlphabet$ = MID$(usedAlphabet$, 1, randomLetter - 1) + MID$(usedAlphabet$, randomLetter + 1, LEN(usedAlphabet$))
  290.         NEXT allLetters
  291.  
  292.         'third: put the phrase in code
  293.         FOR letter = 1 TO LEN(answerPhrase$)
  294.             answerLetter$ = MID$(answerPhrase$, letter, 1)
  295.             upAnsLet$ = UCASE$(answerLetter$)
  296.             answerLetterNumber = ASC(upAnsLet$) - 64
  297.             IF ASC(upAnsLet$) >= 65 AND ASC(upAnsLet$) <= 90 THEN
  298.                 upCodeLet$ = translationMatrix$(ASC(upAnsLet$) - 64, 2)
  299.                 IF ASC(answerLetter$) >= 65 AND ASC(answerLetter$) <= 90 THEN
  300.                     codedLetter$ = upCodeLet$
  301.                 ELSE
  302.                     codedLetter$ = LCASE$(upCodeLet$)
  303.                 END IF
  304.             ELSE
  305.                 codedLetter$ = answerLetter$
  306.             END IF
  307.             codedPhrase$ = codedPhrase$ + codedLetter$
  308.         NEXT letter
  309.  
  310.         'next on the list is to center the phrases
  311.         lineNumber = 0
  312.         shrinkingCode$ = codedPhrase$
  313.         shrinkingAnswer$ = answerPhrase$
  314.         DO
  315.             checking = 60
  316.             DO
  317.                 wheresSpace$ = MID$(shrinkingAnswer$, checking, 1)
  318.                 checking = checking - 1
  319.             LOOP UNTIL wheresSpace$ = CHR$(32)
  320.             lineNumber = lineNumber + 1
  321.             answerLines$(lineNumber) = MID$(shrinkingAnswer$, 1, checking)
  322.             workingLines$(lineNumber) = MID$(shrinkingCode$, 1, checking)
  323.             initiallyCodedLines$(lineNumber) = MID$(shrinkingCode$, 1, checking)
  324.             leftPositions(lineNumber) = Center(answerLines$(lineNumber))
  325.             shrinkingAnswer$ = MID$(shrinkingAnswer$, checking + 1, LEN(shrinkingAnswer$))
  326.             shrinkingCode$ = MID$(shrinkingCode$, checking + 1, LEN(shrinkingCode$))
  327.         LOOP UNTIL LEN(shrinkingAnswer$) <= 60
  328.         lineNumber = lineNumber + 1
  329.         answerLines$(lineNumber) = shrinkingAnswer$
  330.         leftPositions(lineNumber) = Center(answerLines$(lineNumber))
  331.         workingLines$(lineNumber) = shrinkingCode$
  332.         initiallyCodedLines$(lineNumber) = shrinkingCode$
  333.  
  334.         maxLineNumber = lineNumber
  335.  
  336.         highlightedLetter = 1
  337.     END IF
  338.     refresh = TRUE
  339.     DO
  340.         userInput$ = UCASE$(INKEY$)
  341.         SELECT CASE userInput$
  342.             CASE "1"
  343.                 PLAY enterKeyHit$
  344.                 refresh = TRUE
  345.                 CALL Hints
  346.             CASE "2"
  347.                 PLAY enterKeyHit$
  348.                 CALL SaveGame
  349.             CASE CHR$(27)
  350.                 PLAY enterKeyHit$ + enterKeyHit$ + arrowKeyMove$
  351.                 CALL RestartPuzzle
  352.                 refresh = TRUE
  353.             CASE "5"
  354.                 PLAY enterKeyHit$
  355.                 CALL Menu
  356.             CASE leftArrow$
  357.                 PLAY arrowKeyMove$
  358.                 IF highlightedLetter > 1 THEN
  359.                     highlightedLetter = highlightedLetter - 1
  360.                 ELSE
  361.                     highlightedLetter = 26
  362.                 END IF
  363.                 refresh = TRUE
  364.             CASE rightArrow$
  365.                 PLAY arrowKeyMove$
  366.                 IF highlightedLetter < 26 THEN
  367.                     highlightedLetter = highlightedLetter + 1
  368.                 ELSE
  369.                     highlightedLetter = 1
  370.                 END IF
  371.                 refresh = TRUE
  372.             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"
  373.                 PLAY enterKeyHit$
  374.                 usersCode$(highlightedLetter, 2) = userInput$
  375.                 CALL Switch(userInput$)
  376.                 refresh = TRUE
  377.         END SELECT
  378.  
  379.         IF refresh = TRUE THEN
  380.             refresh = FALSE
  381.             CALL ShowPuzzle
  382.         END IF
  383.     LOOP UNTIL userInput$ = "9" OR CorrectPhrase = TRUE
  384.     IF CorrectPhrase = TRUE THEN
  385.         COLOR 11, 0
  386.         LOCATE 25, Center("success")
  387.         PRINT "SUCCESS!!"
  388.         _DELAY (10)
  389.     END IF
  390.  
  391. SUB Hints
  392.     nope:
  393.     COLOR 14, 1
  394.     CLS
  395.     a$ = "You have an option of 3 types of hints to choose from.": LOCATE 10, Center(a$): PRINT a$
  396.     a$ = "Wheel of Fortune reveals the letters for R, S, T, L, N and E": LOCATE 11, Center(a$): PRINT a$
  397.     a$ = "Or you can choose to reveal a single letter.": LOCATE 12, Center(a$): PRINT a$
  398.     a$ = "Example phrase = Rmtleyr ewatbr": LOCATE 14, Center(a$): COLOR 10, 1: PRINT "Example phrase ";: COLOR 14, 1: PRINT "=";: COLOR 10, 1: PRINT " Rmtleyr ewatbr": COLOR 14, 1
  399.     a$ = "1.) Wheel of Fortune: Example phrase = Emtlele ewrtse": LOCATE 17, Center(a$): PRINT "1.) Wheel of Fortune: ";: COLOR 10, 1: PRINT "Example phrase = ";
  400.     COLOR 12, 1: PRINT "E";: COLOR 10, 1: PRINT "mtle";: COLOR 12, 1: PRINT "le";: COLOR 10, 1: PRINT " ew";: COLOR 12, 1: PRINT "r";: COLOR 10, 1: PRINT "t";: COLOR 12, 1: PRINT "se": COLOR 14, 1
  401.     a$ = "2.) Reveal a single random letter: Rmtleyr ewatbr": LOCATE 19, Center(a$): PRINT "2.) Reveal a single random letter: ";: COLOR 12, 1: PRINT "E";: COLOR 10, 1
  402.     PRINT "mtley";: COLOR 12, 1: PRINT "e";: COLOR 10, 1: PRINT " ewrts";: COLOR 12, 1: PRINT "e": COLOR 14, 1
  403.     a$ = "3.) Choose a single coded letter to decode:": LOCATE 21, Center(a$): PRINT a$
  404.     a$ = "    Pick any letter in example phrase": LOCATE 22, Center(a$): PRINT "    Pick any letter in ";: COLOR 10, 1: PRINT "R";
  405.     COLOR 12, 1: PRINT "m";: COLOR 10, 1: PRINT "tleyr ewatbr";: COLOR 14, 1
  406.     a$ = "      to be revealed in example phrase": LOCATE 23, Center(a$): PRINT "      to be revealed in ";: COLOR 10, 1: PRINT "E";: COLOR 12, 1: PRINT "x";: COLOR 10, 1: PRINT "ample phrase": COLOR 14, 1
  407.     a$ = "4.) Reveal a letter you think is in the answer phrase:": LOCATE 25, Center(a$): PRINT a$
  408.     a$ = "Choosing " + CHR$(34) + "K" + CHR$(34) + " wouldn't reveal anything. Choosing " + CHR$(34) + "L" + CHR$(34): LOCATE 26, Center(a$): PRINT a$
  409.     a$ = " Reveals the " + CHR$(34) + "L" + CHR$(34) + " -- example phrase": LOCATE 27, Center(a$): PRINT "reveals the " + CHR$(34) + "L" + CHR$(34) + " -- ";
  410.     COLOR 10, 1: PRINT "Examp";: COLOR 12, 1: PRINT "l";: COLOR 10, 1: PRINT "e phrase": COLOR 14, 1
  411.     a$ = "5.) Switch to easy mode": LOCATE 29, Center(a$): PRINT a$
  412.     a$ = "6.) Display every coded letter and the letter": LOCATE 31, Center(a$): PRINT a$
  413.     a$ = "       it should be for 2 seconds": LOCATE 32, Center(a$): PRINT a$
  414.  
  415.  
  416.  
  417.     a$ = "7.) Cancel": LOCATE 35, Center(a$): PRINT a$
  418.     PLAY arrowKeyMove$
  419.     r$ = P$
  420.     PLAY enterKeyHit$
  421.     SELECT CASE r$
  422.         CASE "1"
  423.             r$ = translationMatrix$(18, 2): re = ASC(r$) - 64: highlightedLetter = re: CALL Switch("R"): usersCode$(re, 2) = "R"
  424.             ss$ = translationMatrix$(19, 2): se = ASC(ss$) - 64: highlightedLetter = se: CALL Switch("S"): usersCode$(se, 2) = "S"
  425.             t$ = translationMatrix$(20, 2): te = ASC(t$) - 64: highlightedLetter = te: CALL Switch("T"): usersCode$(te, 2) = "T"
  426.             l$ = translationMatrix$(12, 2): le = ASC(l$) - 64: highlightedLetter = le: CALL Switch("L"): usersCode$(le, 2) = "L"
  427.             n$ = translationMatrix$(14, 2): ne = ASC(n$) - 64: highlightedLetter = ne: CALL Switch("N"): usersCode$(ne, 2) = "N"
  428.             e$ = translationMatrix$(5, 2): ee = ASC(e$) - 64: highlightedLetter = ee: CALL Switch("E"): usersCode$(ee, 2) = "E"
  429.         CASE "2"
  430.             gotThis:
  431.             tryAgain:
  432.             there = FALSE
  433.             someRandom$ = CHR$((INT(RND * 26)) + 65)
  434.             FOR x = 1 TO maxLineNumber
  435.                 FOR y = 1 TO LEN(answerLines$(x))
  436.                     IF UCASE$(MID$(answerLines$(x), y, 1)) = someRandom$ THEN there = TRUE
  437.                 NEXT y
  438.             NEXT x
  439.             IF there = FALSE THEN GOTO tryAgain
  440.             itShouldBeCodedAs$ = translationMatrix$(ASC(someRandom$) - 64, 2)
  441.             usersAttempt$ = usersCode$(ASC(itShouldBeCodedAs$) - 64, 2)
  442.             IF usersAttempt$ = someRandom$ THEN GOTO tryAgain
  443.             highlightedLetter = ASC(itShouldBeCodedAs$) - 64
  444.             Switch (someRandom$)
  445.             usersCode$(highlightedLetter, 2) = someRandom$
  446.         CASE "3"
  447.             PRINT: PRINT
  448.             a$ = "What code letter do you want to know the answer letter for?    ": LOCATE , Center(a$): PRINT a$;
  449.             invlInp:
  450.             someCodedLetter$ = UCASE$(P$)
  451.             ascSomeCodedLetter = ASC(someCodedLetter$) - 64
  452.             correctLetter$ = ""
  453.             FOR index = 1 TO 26
  454.                 IF translationMatrix$(index, 2) = someCodedLetter$ THEN correctLetter$ = translationMatrix$(index, 1)
  455.             NEXT index
  456.             highlightedLetter = ascSomeCodedLetter
  457.             CALL Switch(correctLetter$)
  458.         CASE "4"
  459.             a$ = "What answer letter do you want the code for?    ": LOCATE , Center(a$): PRINT a$;
  460.             invlInpt:
  461.             d$ = UCASE$(P$)
  462.             da = ASC(d$) - 64
  463.  
  464.             ans$ = translationMatrix$(da, 2)
  465.             highlightedLetter = da
  466.             CALL Switch(ans$)
  467.         CASE "5"
  468.             mode = Easy
  469.         CASE "6"
  470.             COLOR 15, 1
  471.             CLS
  472.             FOR index = 1 TO 26
  473.                 LOCATE 22, ((80 - 52) / 2) + (index * 2)
  474.                 PRINT translationMatrix$(index, 1)
  475.                 LOCATE 24, ((80 - 52) / 2) + (index * 2)
  476.                 PRINT translationMatrix$(index, 2)
  477.             NEXT index
  478.             _DELAY (2)
  479.         CASE "7"
  480.             'just go away
  481.         CASE ELSE
  482.             GOTO nope
  483.     END SELECT
  484.     highlightedLetter = 1
  485.  
  486. FUNCTION CorrectPhrase
  487.     ag = TRUE
  488.     FOR x = 1 TO maxLineNumber
  489.         IF workingLines$(x) <> answerLines$(x) THEN ag = FALSE
  490.     NEXT x
  491.     CorrectPhrase = ag
  492.  
  493. SUB Switch (withThis$)
  494.     DIM newLines$(1 TO maxLineNumber): FOR i = 1 TO maxLineNumber: newLines$(i) = "": NEXT i
  495.     FOR l = 1 TO maxLineNumber
  496.         FOR c = 1 TO LEN(workingLines$(l))
  497.             letter$ = CHR$(highlightedLetter + 64)
  498.             initialLetter$ = MID$(initiallyCodedLines$(l), c, 1)
  499.             wcl$ = MID$(workingLines$(l), c, 1)
  500.             IF ASC(initialLetter$) >= 65 AND ASC(initialLetter$) <= 90 THEN
  501.                 withThis$ = UCASE$(withThis$)
  502.             ELSEIF ASC(initialLetter$) >= 97 AND ASC(initialLetter$) <= 122 THEN
  503.                 withThis$ = LCASE$(withThis$)
  504.             ELSE
  505.             END IF
  506.             IF letter$ = UCASE$(initialLetter$) THEN
  507.                 newLines$(l) = newLines$(l) + withThis$
  508.             ELSE
  509.                 newLines$(l) = newLines$(l) + wcl$
  510.             END IF
  511.         NEXT c 'haracter
  512.     NEXT l 'ine
  513.     FOR index = 1 TO maxLineNumber
  514.         workingLines$(index) = newLines$(index)
  515.     NEXT index
  516.  
  517. SUB RestartPuzzle
  518.     FOR c = 1 TO maxLineNumber
  519.         workingLines$(c) = initiallyCodedLines$(c)
  520.     NEXT c
  521.     FOR xx = 1 TO 26
  522.         usersCode$(xx, 2) = "-"
  523.     NEXT xx
  524.  
  525. SUB ShowPuzzle
  526.     COLOR 10, 1: CLS
  527.  
  528.     FOR eachLine = 1 TO maxLineNumber
  529.         LOCATE 13 + eachLine, leftPositions(eachLine)
  530.         FOR eachLetter = 1 TO LEN(workingLines$(eachLine))
  531.             f$ = MID$(workingLines$(eachLine), eachLetter, 1)
  532.             icl$ = MID$(initiallyCodedLines$(eachLine), eachLetter, 1)
  533.             correct$ = MID$(answerLines$(eachLine), eachLetter, 1)
  534.             ac = ASC(UCASE$(icl$)) - 64
  535.             IF f$ <> icl$ THEN
  536.                 COLOR 12, 1
  537.             END IF
  538.             IF f$ = correct$ AND mode = Easy THEN
  539.                 COLOR 15, 1
  540.             END IF
  541.             IF highlightedLetter = ac THEN
  542.                 COLOR 10, 0
  543.             END IF
  544.             IF f$ = icl$ AND highlightedLetter <> ac AND f$ <> correct$ THEN COLOR 10, 1
  545.  
  546.             PRINT f$;
  547.             COLOR 10, 1
  548.         NEXT eachLetter
  549.     NEXT eachLine
  550.     spaces = 2
  551.     FOR x = 1 TO 26
  552.         IF x = highlightedLetter THEN
  553.             COLOR 10, 0
  554.         ELSE
  555.             COLOR 10, 1
  556.         END IF
  557.         LOCATE 35, spaces
  558.         PRINT usersCode$(x, 1)
  559.         LOCATE 37, spaces
  560.         PRINT usersCode$(x, 2)
  561.         spaces = spaces + 3
  562.     NEXT x
  563.     a$ = "Push 1 to access the hint menu"
  564.     LOCATE 43, Center(a$): COLOR 14, 1: PRINT a$
  565.     a$ = "Push 2 to save the game and quit": COLOR 14, 1: LOCATE 45, Center(a$): PRINT a$
  566.     a$ = "Push [ESC] to reset": LOCATE 47, Center(a$): COLOR 14, 1: PRINT a$
  567.     a$ = "Push 5 to quit": LOCATE 49, Center(a$): COLOR 14, 1: PRINT a$
  568.  
  569. FUNCTION FileStatus
  570.     IF _FILEEXISTS("Phrases.txt") = 0 THEN
  571.         OPEN "Phrases.txt" FOR OUTPUT AS #1
  572.         PRINT #1, "Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our yesterdays have lighted fools The way to dusty death. Out, out, brief candle! Life's but a walking shadow, a poor player, That struts and frets his hour upon the stage, And then is heard no more. It is a tale Told by an idiot, full of sound and fury, Signifying nothing."
  573.         PRINT #1, "To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream"
  574.         PRINT #1, "If someone is able to show me that what I think or do is not right, I will happily change. For I seek the truth, by which no oe ever was truly harmed. Harmed is the person who continues in his self-deception and ignorance."
  575.         PRINT #1, "Funny lines: Before you marry a person, you should first make them use a computer with slow internet to see who they really are. -- Someone asked me, if I were stranded on a desert island what book would I bring... " + CHR$(34) + "How to Build a Boat." + CHR$(34)
  576.         PRINT #1, "Funny lines: I finally realized that people are prisoners of their own phones... that's why it's called a " + CHR$(34) + "cell" + CHR$(34) + " phone. -- Be decisive. Right or wrong, make a decision. The road is paved with flat squirrels who couldn't make a decision."
  577.         PRINT #1, "Funny lines: If at first you don't succeed, then skydiving definitely isn't for you. -- My cell phone is acting up. I keep pressing the Home button but every time I look around, I'm still at work."
  578.         PRINT #1, "Pangrams: Pack my box with five dozen liquor jugs. -- The quick brown fox jumps over the lazy dog. -- My girl wove six dozen plaid jackets before she quit."
  579.         PRINT #1, "EOF"
  580.         CLOSE #1
  581.         numberOfPhrases = 7
  582.     ELSE
  583.         OPEN "Phrases.txt" FOR INPUT AS #1
  584.         numberOfPhrases = 0
  585.         DO
  586.             numberOfPhrases = numberOfPhrases + 1
  587.             LINE INPUT #1, lineCounting$
  588.         LOOP UNTIL INSTR(lineCounting$, "EOF") <> 0
  589.         numberOfPhrases = numberOfPhrases - 1
  590.         CLOSE #1
  591.     END IF
  592.     FileStatus = numberOfPhrases
  593.  
  594. FUNCTION Center (text$)
  595.     Center = INT((80 - LEN(text$)) / 2)
  596.  
  597. FUNCTION S$ (number)
  598.     S$ = LTRIM$(STR$(number))
  599.  
  600.     pause$ = INPUT$(1)
  601.     IF pause$ = CHR$(27) THEN END
  602.     P$ = pause$
  603.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: CryptoGram finished!
« Reply #1 on: September 07, 2021, 09:59:47 pm »
I used to do these things years ago, using that archaic system, pencil and paper (in this case puzzle magazines)... So much fun... Oh. Hang on... That involves a lot of thinking... It's all coming back to me now... I would finish a few of them then walk away due to 'brain strain'... That was the only part of these puzzles I did not like... I am SO glad you have an 'easy' setting...

Excellent job. Well done! Looking forward to your next project... Nudge. Nudge.  No pressure, right? lol
Logic is the beginning of wisdom.

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: CryptoGram finished!
« Reply #2 on: September 08, 2021, 01:19:34 pm »
Well, almost finished. I thought I had fixed the hints of option 3 and 4 but apparently not. I'll post the correct SELECT CASE for the block in the Hint SUB soon.

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: CryptoGram finished!
« Reply #3 on: September 08, 2021, 04:46:04 pm »
I was planning on simply posting the correct SELECT CASE block in the Hints SUB. However, I noticed other errors in the code. Specifically if you started a game, went back to the main menu and started another game, the second game phrase was added to the first with a different codes for each. Since I fixed that too I thought the best thing to do would just be to repost the whole code. Hopefully there aren't any more errors that I missed.
Code: QB64: [Select]
  1. GOTO beginning
  2. crap:
  3. PRINT "Error, Line number"
  4. beginning:
  5. WIDTH 80, 50
  6. CONST TRUE = 1
  7. CONST FALSE = 0
  8. CONST numberOfLines = 15
  9. CONST Easy = 1
  10. CONST Normal = 2
  11. CONST arrowKeyMove$ = "L64O2C"
  12. CONST enterKeyHit$ = "L45O4C"
  13.  
  14. DIM SHARED leftArrow$: leftArrow$ = CHR$(0) + "K"
  15. DIM SHARED rightArrow$: rightArrow$ = CHR$(0) + "M"
  16. DIM SHARED upArrow$: upArrow$ = CHR$(0) + "H"
  17. DIM SHARED downArrow$: downArrow$ = CHR$(0) + "P"
  18. DIM SHARED translationMatrix$(1 TO 26, 1 TO 2): FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": NEXT cl
  19. DIM SHARED codedPhrase$: codedPhrase$ = ""
  20. DIM SHARED answerPhrase$: answerPhrase$ = ""
  21. DIM SHARED highlightedLetter: highlightedLetter = 0
  22. DIM SHARED workingLines$(1 TO numberOfLines)
  23. DIM SHARED initiallyCodedLines$(1 TO numberOfLines)
  24. DIM SHARED answerLines$(1 TO numberOfLines)
  25. DIM SHARED leftPositions(1 TO numberOfLines) AS INTEGER
  26. DIM SHARED maxLineNumber: maxLineNumber = 0
  27. DIM SHARED usersCode$(1 TO 26, 1 TO 2): FOR x = 1 TO 26: usersCode$(x, 1) = CHR$(x + 64): usersCode$(x, 2) = "-": NEXT x
  28. DIM SHARED mode: mode = Normal
  29. DIM SHARED loaded: loaded = FALSE
  30. DIM SHARED numberOfPhrases
  31. FOR cl = 1 TO numberOfLines
  32.     workingLines$(cl) = ""
  33.     initiallyCodedLines$(cl) = ""
  34.     answerLines$(cl) = ""
  35.     leftPositions(cl) = 0
  36. NEXT cl
  37. CALL Menu
  38.  
  39. SUB Menu
  40.     opt = 1
  41.     mode = Normal
  42.     PrintAgain:
  43.     COLOR 14, 2: CLS: tabs = 25
  44.     a$ = "Main Menu": LOCATE 13, Center(a$): PRINT a$:
  45.     LOCATE 14, Center(a$) - 1: PRINT "-----------"
  46.     COLOR 14, 2: a$ = "Mode = Easy  Normal":
  47.     LOCATE 16, Center(a$): PRINT "Mode = ";
  48.     IF mode = Easy THEN
  49.         COLOR 14, 0
  50.     ELSEIF mode = Normal THEN
  51.         COLOR 14, 2
  52.     END IF
  53.     PRINT "Easy";: COLOR 14, 2: PRINT " ";
  54.     IF mode = Normal THEN
  55.         COLOR 14, 0
  56.     ELSEIF mode = Normal THEN
  57.         COLOR 14, 2
  58.     END IF
  59.     PRINT "Normal"
  60.  
  61.     LOCATE 19, tabs
  62.     COLOR 15, 2: PRINT "1.) ";
  63.     IF opt = 1 THEN
  64.         COLOR 14, 0:
  65.     ELSE
  66.         COLOR 14, 2
  67.     END IF
  68.     PRINT "Instructions"
  69.  
  70.     LOCATE 21, tabs
  71.     COLOR 15, 2: PRINT "2.) ";
  72.     IF opt = 2 THEN
  73.         COLOR 14, 0
  74.     ELSE
  75.         COLOR 14, 2
  76.     END IF
  77.     PRINT "New Game"
  78.  
  79.     LOCATE 23, tabs
  80.     COLOR 15, 2: PRINT "3.) ";
  81.     IF opt = 3 THEN
  82.         COLOR 14, 0
  83.     ELSE
  84.         COLOR 14, 2
  85.     END IF
  86.     PRINT "Load a Saved Game"
  87.  
  88.     LOCATE 25, tabs
  89.     COLOR 15, 2: PRINT "4.) ";
  90.     IF opt = 4 THEN
  91.         COLOR 14, 0
  92.     ELSE
  93.         COLOR 14, 2
  94.     END IF
  95.     PRINT "Add New Phrase to Data File"
  96.  
  97.     LOCATE 27, tabs
  98.     COLOR 15, 2: PRINT "5.) ";
  99.     IF opt = 5 THEN
  100.         COLOR 14, 0
  101.     ELSE
  102.         COLOR 14, 2
  103.     END IF
  104.     PRINT "End Game"
  105.     DO
  106.         choice$ = INKEY$
  107.         SELECT CASE choice$
  108.             CASE upArrow$
  109.                 opt = opt - 1
  110.                 IF opt = 0 THEN opt = 5
  111.                 PLAY arrowKeyMove$
  112.                 GOTO PrintAgain
  113.             CASE leftArrow$
  114.                 IF mode = Easy THEN
  115.                     mode = Normal
  116.                 ELSEIF mode = Normal THEN
  117.                     mode = Easy
  118.                 END IF
  119.                 PLAY arrowKeyMove$
  120.                 GOTO PrintAgain
  121.             CASE downArrow$
  122.                 opt = opt + 1
  123.                 IF opt = 6 THEN opt = 1
  124.                 PLAY arrowKeyMove$
  125.                 GOTO PrintAgain
  126.             CASE rightArrow$
  127.                 IF mode = Easy THEN
  128.                     mode = Normal
  129.                 ELSEIF mode = Normal THEN
  130.                     mode = Easy
  131.                 END IF
  132.                 PLAY arrowKeyMove$
  133.                 GOTO PrintAgain
  134.             CASE CHR$(13)
  135.                 PLAY enterKeyHit$
  136.                 IF opt = 1 THEN CALL Instructions
  137.                 IF opt = 2 THEN CALL Main
  138.                 IF opt = 3 THEN CALL LoadGame
  139.                 IF opt = 4 THEN CALL AddPhrase
  140.                 IF opt = 5 THEN END
  141.                 GOTO PrintAgain
  142.             CASE "1"
  143.                 PLAY enterKeyHit$
  144.                 CALL Instructions
  145.                 GOTO PrintAgain
  146.             CASE "2"
  147.                 PLAY enterKeyHit$
  148.                 loaded = FALSE
  149.                 CALL Main
  150.                 GOTO PrintAgain
  151.             CASE "3"
  152.                 PLAY enterKeyHit$
  153.                 loaded = TRUE
  154.                 CALL LoadGame
  155.                 GOTO PrintAgain
  156.             CASE "4"
  157.                 PLAY enterKeyHit$
  158.                 CALL AddPhrase
  159.                 GOTO PrintAgain
  160.             CASE "5"
  161.                 PLAY enterKeyHit$
  162.                 END
  163.         END SELECT
  164.     LOOP UNTIL choice$ = CHR$(13) OR choice$ = "5"
  165.  
  166. SUB Instructions
  167.     COLOR 10, 13: CLS
  168.     a$ = "A random phrase picked from " + CHR$(34) + "Phrases.txt" + CHR$(34) + " will be displayed in code."
  169.     LOCATE 12, Center(a$): PRINT a$
  170.     a$ = "The goal is to decode the phrase. The coded letters are in one color": LOCATE 14, Center(a$): PRINT a$
  171.     a$ = "and the letters you choose in another color. In easy mode, incorrect": LOCATE 16, Center(a$): PRINT a$
  172.     a$ = "letters are displayed in yet another color. Different types": LOCATE 18, Center(a$): PRINT a$
  173.     a$ = "of hints are available from the hint menu.": LOCATE 20, Center(a$): PRINT a$
  174.     a$ = "Use the arrow keys to select the letter you wish to change. Type": LOCATE 25, Center(a$): PRINT a$
  175.     a$ = "in the letter you wish to change it to. Push the [ESC] key": LOCATE 27, Center(a$): PRINT a$
  176.     a$ = "to reset the puzzle to the starting code.": LOCATE 29, Center(a$): PRINT a$
  177.  
  178.     a$ = "Hit any key to return to the Main Menu": LOCATE 45, Center(a$): COLOR 11, 13: PRINT a$: l$ = P$
  179.  
  180. SUB AddPhrase
  181.     COLOR 11, 13
  182.     CLS
  183.     a$ = "Type in the phrase you want to add. Do not hit": LOCATE 15, Center(a$): PRINT a$
  184.     a$ = " the [ENTER] key until you've entered the entire phrase. ": LOCATE 17, Center(a$): PRINT a$
  185.     a$ = "Don't worry if your entry passes the end of the screen": LOCATE 19, Center(a$): PRINT a$
  186.     a$ = "and continues on to the next line. In fact, longer": LOCATE 21, Center(a$): PRINT a$
  187.     a$ = "phrases are easier to decode.": LOCATE 23, Center(a$): PRINT a$
  188.  
  189.     LOCATE 28, 10: LINE INPUT "Type in your phrase: ", newPhrase$
  190.     maxIndex = FileStatus
  191.     DIM fileArray$(1 TO maxIndex + 1)
  192.     OPEN "Phrases.txt" FOR INPUT AS #1
  193.     FOR index = 1 TO maxIndex
  194.         LINE INPUT #1, fileArray$(index)
  195.     NEXT index
  196.     CLOSE #1
  197.  
  198.     fileArray$(maxIndex + 1) = newPhrase$
  199.     OPEN "Phrases.txt" FOR OUTPUT AS #1
  200.     FOR index = 1 TO maxIndex + 1
  201.         PRINT #1, fileArray$(index)
  202.     NEXT index
  203.     PRINT #1, "EOF"
  204.     CLOSE #1
  205.  
  206.  
  207. SUB LoadGame
  208.     maxLineNumber = 0
  209.     FOR index = 1 TO 26
  210.         translationMatrix$(index, 1) = "": translationMatrix$(index, 2) = ""
  211.         usersCode$(index, 1) = "": usersCode$(index, 2) = ""
  212.     NEXT index
  213.     codedPhrase$ = ""
  214.     answerPhrase$ = ""
  215.     highlightedLetter = 0
  216.     mode = 0
  217.     FOR index = 1 TO 15
  218.         workingLines$(index) = ""
  219.         initiallyCodedLines$(index) = ""
  220.         answerLines$(index) = ""
  221.         leftPositions(index) = 0
  222.     NEXT index
  223.  
  224.     OPEN "CryptoGram" FOR INPUT AS #1
  225.     LINE INPUT #1, mLN$: maxLineNumber = VAL(mLN$)
  226.     FOR index = 1 TO 26
  227.         LINE INPUT #1, translationMatrix$(index, 1)
  228.         LINE INPUT #1, translationMatrix$(index, 2)
  229.         LINE INPUT #1, usersCode$(index, 1)
  230.         LINE INPUT #1, usersCode$(index, 2)
  231.     NEXT index
  232.     LINE INPUT #1, codedPhrase$
  233.     LINE INPUT #1, answerPhrase$
  234.     LINE INPUT #1, hL$
  235.     LINE INPUT #1, m$: mode = VAL(m$)
  236.     FOR index = 1 TO maxLineNumber
  237.         LINE INPUT #1, workingLines$(index)
  238.         LINE INPUT #1, initiallyCodedLines$(index)
  239.         LINE INPUT #1, answerLines$(index)
  240.         LINE INPUT #1, lP$: leftPositions(index) = VAL(lP$)
  241.     NEXT index
  242.     CLOSE #1
  243.     loaded = TRUE: CALL Main
  244.  
  245. SUB SaveGame
  246.     OPEN "CryptoGram" FOR OUTPUT AS #1
  247.     PRINT #1, S$(maxLineNumber)
  248.     FOR index = 1 TO 26
  249.         PRINT #1, translationMatrix$(index, 1)
  250.         PRINT #1, translationMatrix$(index, 2)
  251.         PRINT #1, usersCode$(index, 1)
  252.         PRINT #1, usersCode$(index, 2)
  253.     NEXT index
  254.     PRINT #1, codedPhrase$
  255.     PRINT #1, answerPhrase$
  256.     PRINT #1, S$(highlightedLetter)
  257.     PRINT #1, S$(mode)
  258.     FOR index = 1 TO maxLineNumber
  259.         PRINT #1, workingLines$(index)
  260.         PRINT #1, initiallyCodedLines$(index)
  261.         PRINT #1, answerLines$(index)
  262.         PRINT #1, S$(leftPositions(index))
  263.     NEXT index
  264.     CLOSE #1
  265.     _DELAY (0.25)
  266.     PLAY arrowKeyMove$
  267.  
  268. SUB Main
  269.     IF loaded = FALSE THEN
  270.         FOR cl = 1 TO 26
  271.             translationMatrix$(cl, 1) = ""
  272.             translationMatrix$(cl, 2) = ""
  273.             usersCode$(cl, 1) = CHR$(cl + 64)
  274.             usersCode$(cl, 2) = "-"
  275.         NEXT cl
  276.         codedPhrase$ = ""
  277.         answerPhrase$ = ""
  278.         highlightedLetter = 1
  279.         FOR index = 1 TO numberOfLines
  280.             workingLines$(index) = ""
  281.             initiallyCodedLines$(index) = ""
  282.             answerLines$(index) = ""
  283.             leftPositions(index) = 0
  284.             maxLineNumber = 0
  285.         NEXT index
  286.  
  287.         COLOR 15, 1
  288.         'first, pick a phrase
  289.         randomPhrase = INT(RND * FileStatus) + 1
  290.         OPEN "Phrases.txt" FOR INPUT AS #1
  291.         FOR x = 1 TO randomPhrase
  292.             LINE INPUT #1, answerPhrase$
  293.         NEXT x
  294.         CLOSE #1
  295.  
  296.         'second, create a code
  297.         usedAlphabet$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  298.         FOR allLetters = 1 TO 26
  299.             translationMatrix$(allLetters, 1) = CHR$(allLetters + 64)
  300.             newRndLet:
  301.             randomLetter = INT(RND * LEN(usedAlphabet$)) + 1
  302.             translationMatrix$(allLetters, 2) = MID$(usedAlphabet$, randomLetter, 1)
  303.             IF translationMatrix$(allLetters, 1) = translationMatrix$(allLetters, 2) THEN GOTO newRndLet
  304.             usedAlphabet$ = MID$(usedAlphabet$, 1, randomLetter - 1) + MID$(usedAlphabet$, randomLetter + 1, LEN(usedAlphabet$))
  305.         NEXT allLetters
  306.  
  307.         'third: put the phrase in code
  308.         FOR letter = 1 TO LEN(answerPhrase$)
  309.             answerLetter$ = MID$(answerPhrase$, letter, 1)
  310.             upAnsLet$ = UCASE$(answerLetter$)
  311.             answerLetterNumber = ASC(upAnsLet$) - 64
  312.             IF ASC(upAnsLet$) >= 65 AND ASC(upAnsLet$) <= 90 THEN
  313.                 upCodeLet$ = translationMatrix$(ASC(upAnsLet$) - 64, 2)
  314.                 IF ASC(answerLetter$) >= 65 AND ASC(answerLetter$) <= 90 THEN
  315.                     codedLetter$ = upCodeLet$
  316.                 ELSE
  317.                     codedLetter$ = LCASE$(upCodeLet$)
  318.                 END IF
  319.             ELSE
  320.                 codedLetter$ = answerLetter$
  321.             END IF
  322.             codedPhrase$ = codedPhrase$ + codedLetter$
  323.         NEXT letter
  324.  
  325.         'next on the list is to center the phrases
  326.         lineNumber = 0
  327.         shrinkingCode$ = codedPhrase$
  328.         shrinkingAnswer$ = answerPhrase$
  329.         DO
  330.             checking = 60
  331.             DO
  332.                 wheresSpace$ = MID$(shrinkingAnswer$, checking, 1)
  333.                 checking = checking - 1
  334.             LOOP UNTIL wheresSpace$ = CHR$(32)
  335.             lineNumber = lineNumber + 1
  336.             answerLines$(lineNumber) = MID$(shrinkingAnswer$, 1, checking)
  337.             workingLines$(lineNumber) = MID$(shrinkingCode$, 1, checking)
  338.             initiallyCodedLines$(lineNumber) = MID$(shrinkingCode$, 1, checking)
  339.             leftPositions(lineNumber) = Center(answerLines$(lineNumber))
  340.             shrinkingAnswer$ = MID$(shrinkingAnswer$, checking + 1, LEN(shrinkingAnswer$))
  341.             shrinkingCode$ = MID$(shrinkingCode$, checking + 1, LEN(shrinkingCode$))
  342.         LOOP UNTIL LEN(shrinkingAnswer$) <= 60
  343.         lineNumber = lineNumber + 1
  344.         answerLines$(lineNumber) = shrinkingAnswer$
  345.         leftPositions(lineNumber) = Center(answerLines$(lineNumber))
  346.         workingLines$(lineNumber) = shrinkingCode$
  347.         initiallyCodedLines$(lineNumber) = shrinkingCode$
  348.  
  349.         maxLineNumber = lineNumber
  350.         highlightedLetter = 1
  351.     END IF
  352.     loaded = FALSE
  353.     refresh = TRUE
  354.     DO
  355.         userInput$ = UCASE$(INKEY$)
  356.         SELECT CASE userInput$
  357.             CASE "1"
  358.                 PLAY enterKeyHit$
  359.                 refresh = TRUE
  360.                 CALL Hints
  361.             CASE "2"
  362.                 PLAY enterKeyHit$
  363.                 CALL SaveGame
  364.                 CALL Menu
  365.             CASE CHR$(27)
  366.                 PLAY enterKeyHit$ + enterKeyHit$ + arrowKeyMove$
  367.                 CALL RestartPuzzle
  368.                 refresh = TRUE
  369.             CASE "5"
  370.                 CALL Menu
  371.                 PLAY enterKeyHit$
  372.                 highlightedLetter = 1
  373.                 FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": usersCode$(cl, 1) = "": usersCode$(cl, 2) = "": NEXT cl
  374.                 FOR cl = 1 TO numberOfLines
  375.                     workingLines$(cl) = ""
  376.                     initiallyCodedLines$(cl) = ""
  377.                     answerLines$(cl) = ""
  378.                     leftPositions(cl) = 0
  379.                 NEXT cl
  380.                 FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": usersCode$(cl, 1) = "": usersCode$(cl, 2) = "": NEXT cl
  381.                 mode = Normal
  382.  
  383.             CASE leftArrow$
  384.                 PLAY arrowKeyMove$
  385.                 IF highlightedLetter > 1 THEN
  386.                     highlightedLetter = highlightedLetter - 1
  387.                 ELSE
  388.                     highlightedLetter = 26
  389.                 END IF
  390.                 refresh = TRUE
  391.             CASE rightArrow$
  392.                 PLAY arrowKeyMove$
  393.                 IF highlightedLetter < 26 THEN
  394.                     highlightedLetter = highlightedLetter + 1
  395.                 ELSE
  396.                     highlightedLetter = 1
  397.                 END IF
  398.                 refresh = TRUE
  399.             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"
  400.                 PLAY enterKeyHit$
  401.                 usersCode$(highlightedLetter, 2) = userInput$
  402.                 CALL Switch(userInput$)
  403.                 refresh = TRUE
  404.         END SELECT
  405.  
  406.         IF refresh = TRUE THEN
  407.             refresh = FALSE
  408.             CALL ShowPuzzle
  409.         END IF
  410.     LOOP UNTIL userInput$ = "9" OR CorrectPhrase = TRUE
  411.     IF CorrectPhrase = TRUE THEN
  412.         COLOR 11, 0
  413.         LOCATE 25, Center("success")
  414.         PRINT "SUCCESS!!"
  415.         _DELAY (10)
  416.     END IF
  417.  
  418. SUB Hints
  419.     nope:
  420.     COLOR 14, 1
  421.     CLS
  422.     a$ = "You have an option of 3 types of hints to choose from.": LOCATE 10, Center(a$): PRINT a$
  423.     a$ = "Wheel of Fortune reveals the letters for R, S, T, L, N and E": LOCATE 11, Center(a$): PRINT a$
  424.     a$ = "Or you can choose to reveal a single letter.": LOCATE 12, Center(a$): PRINT a$
  425.     a$ = "Example phrase = Rmtleyr ewatbr": LOCATE 14, Center(a$): COLOR 10, 1: PRINT "Example phrase ";: COLOR 14, 1: PRINT "=";: COLOR 10, 1: PRINT " Rmtleyr ewatbr": COLOR 14, 1
  426.     a$ = "1.) Wheel of Fortune: Example phrase = Emtlele ewrtse": LOCATE 17, Center(a$): PRINT "1.) Wheel of Fortune: ";: COLOR 10, 1: PRINT "Example phrase = ";
  427.     COLOR 12, 1: PRINT "E";: COLOR 10, 1: PRINT "mtle";: COLOR 12, 1: PRINT "le";: COLOR 10, 1: PRINT " ew";: COLOR 12, 1: PRINT "r";: COLOR 10, 1: PRINT "t";: COLOR 12, 1: PRINT "se": COLOR 14, 1
  428.     a$ = "2.) Reveal a single random letter: Rmtleyr ewatbr": LOCATE 19, Center(a$): PRINT "2.) Reveal a single random letter: ";: COLOR 12, 1: PRINT "E";: COLOR 10, 1
  429.     PRINT "mtley";: COLOR 12, 1: PRINT "e";: COLOR 10, 1: PRINT " ewrts";: COLOR 12, 1: PRINT "e": COLOR 14, 1
  430.     a$ = "3.) Choose a single coded letter to decode:": LOCATE 21, Center(a$): PRINT a$
  431.     a$ = "    Pick any letter in example phrase": LOCATE 22, Center(a$): PRINT "    Pick any letter in ";: COLOR 10, 1: PRINT "R";
  432.     COLOR 12, 1: PRINT "m";: COLOR 10, 1: PRINT "tleyr ewatbr";: COLOR 14, 1
  433.     a$ = "      to be revealed in example phrase": LOCATE 23, Center(a$): PRINT "      to be revealed in ";: COLOR 10, 1: PRINT "E";: COLOR 12, 1: PRINT "x";: COLOR 10, 1: PRINT "ample phrase": COLOR 14, 1
  434.     a$ = "4.) Reveal a letter you think is in the answer phrase:": LOCATE 25, Center(a$): PRINT a$
  435.     a$ = "Choosing " + CHR$(34) + "K" + CHR$(34) + " wouldn't reveal anything. Choosing " + CHR$(34) + "L" + CHR$(34): LOCATE 26, Center(a$): PRINT a$
  436.     a$ = " Reveals the " + CHR$(34) + "L" + CHR$(34) + " -- example phrase": LOCATE 27, Center(a$): PRINT "reveals the " + CHR$(34) + "L" + CHR$(34) + " -- ";
  437.     COLOR 10, 1: PRINT "Examp";: COLOR 12, 1: PRINT "l";: COLOR 10, 1: PRINT "e phrase": COLOR 14, 1
  438.     a$ = "5.) Switch to easy mode": LOCATE 29, Center(a$): PRINT a$
  439.     a$ = "6.) Display every coded letter and the letter": LOCATE 31, Center(a$): PRINT a$
  440.     a$ = "       it should be for 2 seconds": LOCATE 32, Center(a$): PRINT a$
  441.  
  442.  
  443.  
  444.     a$ = "7.) Cancel": LOCATE 35, Center(a$): PRINT a$
  445.     PLAY arrowKeyMove$
  446.     r$ = P$
  447.     PLAY enterKeyHit$
  448.     SELECT CASE r$
  449.         CASE "1"
  450.             r$ = translationMatrix$(18, 2): re = ASC(r$) - 64: highlightedLetter = re: CALL Switch("R"): usersCode$(re, 2) = "R"
  451.             ss$ = translationMatrix$(19, 2): se = ASC(ss$) - 64: highlightedLetter = se: CALL Switch("S"): usersCode$(se, 2) = "S"
  452.             t$ = translationMatrix$(20, 2): te = ASC(t$) - 64: highlightedLetter = te: CALL Switch("T"): usersCode$(te, 2) = "T"
  453.             l$ = translationMatrix$(12, 2): le = ASC(l$) - 64: highlightedLetter = le: CALL Switch("L"): usersCode$(le, 2) = "L"
  454.             n$ = translationMatrix$(14, 2): ne = ASC(n$) - 64: highlightedLetter = ne: CALL Switch("N"): usersCode$(ne, 2) = "N"
  455.             e$ = translationMatrix$(5, 2): ee = ASC(e$) - 64: highlightedLetter = ee: CALL Switch("E"): usersCode$(ee, 2) = "E"
  456.         CASE "2"
  457.             gotThis:
  458.             tryAgain:
  459.             there = FALSE
  460.             someRandom$ = CHR$((INT(RND * 26)) + 65)
  461.             FOR x = 1 TO maxLineNumber
  462.                 FOR y = 1 TO LEN(answerLines$(x))
  463.                     IF UCASE$(MID$(answerLines$(x), y, 1)) = someRandom$ THEN there = TRUE
  464.                 NEXT y
  465.             NEXT x
  466.             IF there = FALSE THEN GOTO tryAgain
  467.             itShouldBeCodedAs$ = translationMatrix$(ASC(someRandom$) - 64, 2)
  468.             usersAttempt$ = usersCode$(ASC(itShouldBeCodedAs$) - 64, 2)
  469.             IF usersAttempt$ = someRandom$ THEN GOTO tryAgain
  470.             highlightedLetter = ASC(itShouldBeCodedAs$) - 64
  471.             Switch (someRandom$)
  472.             usersCode$(highlightedLetter, 2) = someRandom$
  473.         CASE "3"
  474.             PRINT: PRINT
  475.             a$ = "What code letter do you want to know the answer letter for?    ": LOCATE 37, Center(a$): PRINT a$;
  476.             aCodedLetter$ = P$: aCodedLetter$ = UCASE$(aCodedLetter$)
  477.             theCorrectLetter$ = ""
  478.             FOR index = 1 TO 26
  479.                 IF translationMatrix$(index, 2) = aCodedLetter$ THEN theCorrectLetter$ = translationMatrix$(index, 1)
  480.             NEXT index
  481.             highlightedLetter = ASC(aCodedLetter$) - 64
  482.             usersCode$(ASC(aCodedLetter$) - 64, 2) = theCorrectLetter$
  483.             CALL Switch(theCorrectLetter$)
  484.         CASE "4"
  485.             a$ = "What answer letter do you want the code for?    ": LOCATE 37, Center(a$): PRINT a$;: theCorrectLetter$ = P$: theCorrectLetter$ = UCASE$(theCorrectLetter$)
  486.             FOR index = 1 TO 26
  487.                 LOCATE 40, index: PRINT translationMatrix$(index, 1)
  488.                 LOCATE 41, index: PRINT translationMatrix$(index, 2)
  489.             NEXT index
  490.             f$ = P$
  491.             clPosition = ASC(theCorrectLetter$) - 64
  492.             letterCode$ = translationMatrix$(clPosition, 2)
  493.             highlightedLetter = ASC(letterCode$) - 64
  494.             CALL Switch(UCASE$(theCorrectLetter$))
  495.             usersCode$(highlightedLetter, 2) = UCASE$(theCorrectLetter$)
  496.         CASE "5"
  497.             mode = Easy
  498.         CASE "6"
  499.             COLOR 15, 1
  500.             CLS
  501.             FOR index = 1 TO 26
  502.                 LOCATE 22, ((80 - 52) / 2) + (index * 2)
  503.                 PRINT translationMatrix$(index, 1)
  504.                 LOCATE 24, ((80 - 52) / 2) + (index * 2)
  505.                 PRINT translationMatrix$(index, 2)
  506.             NEXT index
  507.             _DELAY (2)
  508.         CASE "7"
  509.             'just go away
  510.         CASE ELSE
  511.             GOTO nope
  512.     END SELECT
  513.     highlightedLetter = 1
  514.  
  515. FUNCTION CorrectPhrase
  516.     ag = TRUE
  517.     FOR x = 1 TO maxLineNumber
  518.         IF workingLines$(x) <> answerLines$(x) THEN ag = FALSE
  519.     NEXT x
  520.     CorrectPhrase = ag
  521.  
  522. SUB Switch (withThis$)
  523.     DIM newLines$(1 TO maxLineNumber): FOR i = 1 TO maxLineNumber: newLines$(i) = "": NEXT i
  524.     FOR l = 1 TO maxLineNumber
  525.         FOR c = 1 TO LEN(workingLines$(l))
  526.             letter$ = CHR$(highlightedLetter + 64)
  527.             initialLetter$ = MID$(initiallyCodedLines$(l), c, 1)
  528.             wcl$ = MID$(workingLines$(l), c, 1)
  529.             IF ASC(initialLetter$) >= 65 AND ASC(initialLetter$) <= 90 THEN
  530.                 withThis$ = UCASE$(withThis$)
  531.             ELSEIF ASC(initialLetter$) >= 97 AND ASC(initialLetter$) <= 122 THEN
  532.                 withThis$ = LCASE$(withThis$)
  533.             ELSE
  534.             END IF
  535.             IF letter$ = UCASE$(initialLetter$) THEN
  536.                 newLines$(l) = newLines$(l) + withThis$
  537.             ELSE
  538.                 newLines$(l) = newLines$(l) + wcl$
  539.             END IF
  540.         NEXT c 'haracter
  541.     NEXT l 'ine
  542.     FOR index = 1 TO maxLineNumber
  543.         workingLines$(index) = newLines$(index)
  544.     NEXT index
  545.  
  546. SUB RestartPuzzle
  547.     FOR c = 1 TO maxLineNumber
  548.         workingLines$(c) = initiallyCodedLines$(c)
  549.     NEXT c
  550.     FOR xx = 1 TO 26
  551.         usersCode$(xx, 2) = "-"
  552.     NEXT xx
  553.  
  554. SUB ShowPuzzle
  555.     COLOR 10, 1: CLS
  556.  
  557.     FOR eachLine = 1 TO maxLineNumber
  558.         LOCATE 13 + eachLine, leftPositions(eachLine)
  559.         FOR eachLetter = 1 TO LEN(workingLines$(eachLine))
  560.             f$ = MID$(workingLines$(eachLine), eachLetter, 1)
  561.             icl$ = MID$(initiallyCodedLines$(eachLine), eachLetter, 1)
  562.             correct$ = MID$(answerLines$(eachLine), eachLetter, 1)
  563.             ac = ASC(UCASE$(icl$)) - 64
  564.             IF f$ <> icl$ THEN
  565.                 COLOR 12, 1
  566.             END IF
  567.             IF f$ = correct$ AND mode = Easy THEN
  568.                 COLOR 15, 1
  569.             END IF
  570.             IF highlightedLetter = ac THEN
  571.                 COLOR 10, 0
  572.             END IF
  573.             IF f$ = icl$ AND highlightedLetter <> ac AND f$ <> correct$ THEN COLOR 10, 1
  574.  
  575.             PRINT f$;
  576.             COLOR 10, 1
  577.         NEXT eachLetter
  578.     NEXT eachLine
  579.     spaces = 2
  580.     FOR x = 1 TO 26
  581.         IF x = highlightedLetter THEN
  582.             COLOR 10, 0
  583.         ELSE
  584.             COLOR 10, 1
  585.         END IF
  586.         LOCATE 35, spaces
  587.         PRINT usersCode$(x, 1)
  588.         LOCATE 37, spaces
  589.         PRINT usersCode$(x, 2)
  590.         spaces = spaces + 3
  591.     NEXT x
  592.     a$ = "Push 1 to access the hint menu"
  593.     LOCATE 43, Center(a$): COLOR 14, 1: PRINT a$
  594.     a$ = "Push 2 to save the game and quit": COLOR 14, 1: LOCATE 45, Center(a$): PRINT a$
  595.     a$ = "Push [ESC] to reset": LOCATE 47, Center(a$): COLOR 14, 1: PRINT a$
  596.     a$ = "Push 5 to quit": LOCATE 49, Center(a$): COLOR 14, 1: PRINT a$
  597.  
  598. FUNCTION FileStatus
  599.     IF _FILEEXISTS("Phrases.txt") = 0 THEN
  600.         OPEN "Phrases.txt" FOR OUTPUT AS #1
  601.         PRINT #1, "Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our yesterdays have lighted fools The way to dusty death. Out, out, brief candle! Life's but a walking shadow, a poor player, That struts and frets his hour upon the stage, And then is heard no more. It is a tale Told by an idiot, full of sound and fury, Signifying nothing."
  602.         PRINT #1, "To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream"
  603.         PRINT #1, "If someone is able to show me that what I think or do is not right, I will happily change. For I seek the truth, by which no oe ever was truly harmed. Harmed is the person who continues in his self-deception and ignorance."
  604.         PRINT #1, "Funny lines: Before you marry a person, you should first make them use a computer with slow internet to see who they really are. -- Someone asked me, if I were stranded on a desert island what book would I bring... " + CHR$(34) + "How to Build a Boat." + CHR$(34)
  605.         PRINT #1, "Funny lines: I finally realized that people are prisoners of their own phones... that's why it's called a " + CHR$(34) + "cell" + CHR$(34) + " phone. -- Be decisive. Right or wrong, make a decision. The road is paved with flat squirrels who couldn't make a decision."
  606.         PRINT #1, "Funny lines: If at first you don't succeed, then skydiving definitely isn't for you. -- My cell phone is acting up. I keep pressing the Home button but every time I look around, I'm still at work."
  607.         PRINT #1, "Pangrams: Pack my box with five dozen liquor jugs. -- The quick brown fox jumps over the lazy dog. -- My girl wove six dozen plaid jackets before she quit."
  608.         PRINT #1, "EOF"
  609.         CLOSE #1
  610.         numberOfPhrases = 7
  611.     ELSE
  612.         OPEN "Phrases.txt" FOR INPUT AS #1
  613.         numberOfPhrases = 0
  614.         DO
  615.             numberOfPhrases = numberOfPhrases + 1
  616.             LINE INPUT #1, lineCounting$
  617.         LOOP UNTIL INSTR(lineCounting$, "EOF") <> 0
  618.         numberOfPhrases = numberOfPhrases - 1
  619.         CLOSE #1
  620.     END IF
  621.     FileStatus = numberOfPhrases
  622.  
  623. FUNCTION Center (text$)
  624.     Center = INT((80 - LEN(text$)) / 2)
  625.  
  626. FUNCTION S$ (number)
  627.     S$ = LTRIM$(STR$(number))
  628.  
  629.     pause$ = INPUT$(1)
  630.     IF pause$ = CHR$(27) THEN END
  631.     P$ = pause$
  632.  

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: CryptoGram finished!
« Reply #4 on: September 09, 2021, 12:12:27 am »
It still doesn't load correctly when you finish a puzzle and begin another one without exiting. Alas. So, if you run it and want to do another quote, just exit and then restart.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CryptoGram finished!
« Reply #5 on: November 03, 2021, 03:38:21 pm »
I was planning on simply posting the correct SELECT CASE block in the Hints SUB. However, I noticed other errors in the code. Specifically if you started a game, went back to the main menu and started another game, the second game phrase was added to the first with a different codes for each. Since I fixed that too I thought the best thing to do would just be to repost the whole code. Hopefully there aren't any more errors that I missed.
Code: QB64: [Select]
  1. GOTO beginning
  2. crap:
  3. PRINT "Error, Line number"
  4. beginning:
  5. WIDTH 80, 50
  6. CONST TRUE = 1
  7. CONST FALSE = 0
  8. CONST numberOfLines = 15
  9. CONST Easy = 1
  10. CONST Normal = 2
  11. CONST arrowKeyMove$ = "L64O2C"
  12. CONST enterKeyHit$ = "L45O4C"
  13.  
  14. DIM SHARED leftArrow$: leftArrow$ = CHR$(0) + "K"
  15. DIM SHARED rightArrow$: rightArrow$ = CHR$(0) + "M"
  16. DIM SHARED upArrow$: upArrow$ = CHR$(0) + "H"
  17. DIM SHARED downArrow$: downArrow$ = CHR$(0) + "P"
  18. DIM SHARED translationMatrix$(1 TO 26, 1 TO 2): FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": NEXT cl
  19. DIM SHARED codedPhrase$: codedPhrase$ = ""
  20. DIM SHARED answerPhrase$: answerPhrase$ = ""
  21. DIM SHARED highlightedLetter: highlightedLetter = 0
  22. DIM SHARED workingLines$(1 TO numberOfLines)
  23. DIM SHARED initiallyCodedLines$(1 TO numberOfLines)
  24. DIM SHARED answerLines$(1 TO numberOfLines)
  25. DIM SHARED leftPositions(1 TO numberOfLines) AS INTEGER
  26. DIM SHARED maxLineNumber: maxLineNumber = 0
  27. DIM SHARED usersCode$(1 TO 26, 1 TO 2): FOR x = 1 TO 26: usersCode$(x, 1) = CHR$(x + 64): usersCode$(x, 2) = "-": NEXT x
  28. DIM SHARED mode: mode = Normal
  29. DIM SHARED loaded: loaded = FALSE
  30. DIM SHARED numberOfPhrases
  31. FOR cl = 1 TO numberOfLines
  32.     workingLines$(cl) = ""
  33.     initiallyCodedLines$(cl) = ""
  34.     answerLines$(cl) = ""
  35.     leftPositions(cl) = 0
  36. NEXT cl
  37. CALL Menu
  38.  
  39. SUB Menu
  40.     opt = 1
  41.     mode = Normal
  42.     PrintAgain:
  43.     COLOR 14, 2: CLS: tabs = 25
  44.     a$ = "Main Menu": LOCATE 13, Center(a$): PRINT a$:
  45.     LOCATE 14, Center(a$) - 1: PRINT "-----------"
  46.     COLOR 14, 2: a$ = "Mode = Easy  Normal":
  47.     LOCATE 16, Center(a$): PRINT "Mode = ";
  48.     IF mode = Easy THEN
  49.         COLOR 14, 0
  50.     ELSEIF mode = Normal THEN
  51.         COLOR 14, 2
  52.     END IF
  53.     PRINT "Easy";: COLOR 14, 2: PRINT " ";
  54.     IF mode = Normal THEN
  55.         COLOR 14, 0
  56.     ELSEIF mode = Normal THEN
  57.         COLOR 14, 2
  58.     END IF
  59.     PRINT "Normal"
  60.  
  61.     LOCATE 19, tabs
  62.     COLOR 15, 2: PRINT "1.) ";
  63.     IF opt = 1 THEN
  64.         COLOR 14, 0:
  65.     ELSE
  66.         COLOR 14, 2
  67.     END IF
  68.     PRINT "Instructions"
  69.  
  70.     LOCATE 21, tabs
  71.     COLOR 15, 2: PRINT "2.) ";
  72.     IF opt = 2 THEN
  73.         COLOR 14, 0
  74.     ELSE
  75.         COLOR 14, 2
  76.     END IF
  77.     PRINT "New Game"
  78.  
  79.     LOCATE 23, tabs
  80.     COLOR 15, 2: PRINT "3.) ";
  81.     IF opt = 3 THEN
  82.         COLOR 14, 0
  83.     ELSE
  84.         COLOR 14, 2
  85.     END IF
  86.     PRINT "Load a Saved Game"
  87.  
  88.     LOCATE 25, tabs
  89.     COLOR 15, 2: PRINT "4.) ";
  90.     IF opt = 4 THEN
  91.         COLOR 14, 0
  92.     ELSE
  93.         COLOR 14, 2
  94.     END IF
  95.     PRINT "Add New Phrase to Data File"
  96.  
  97.     LOCATE 27, tabs
  98.     COLOR 15, 2: PRINT "5.) ";
  99.     IF opt = 5 THEN
  100.         COLOR 14, 0
  101.     ELSE
  102.         COLOR 14, 2
  103.     END IF
  104.     PRINT "End Game"
  105.     DO
  106.         choice$ = INKEY$
  107.         SELECT CASE choice$
  108.             CASE upArrow$
  109.                 opt = opt - 1
  110.                 IF opt = 0 THEN opt = 5
  111.                 PLAY arrowKeyMove$
  112.                 GOTO PrintAgain
  113.             CASE leftArrow$
  114.                 IF mode = Easy THEN
  115.                     mode = Normal
  116.                 ELSEIF mode = Normal THEN
  117.                     mode = Easy
  118.                 END IF
  119.                 PLAY arrowKeyMove$
  120.                 GOTO PrintAgain
  121.             CASE downArrow$
  122.                 opt = opt + 1
  123.                 IF opt = 6 THEN opt = 1
  124.                 PLAY arrowKeyMove$
  125.                 GOTO PrintAgain
  126.             CASE rightArrow$
  127.                 IF mode = Easy THEN
  128.                     mode = Normal
  129.                 ELSEIF mode = Normal THEN
  130.                     mode = Easy
  131.                 END IF
  132.                 PLAY arrowKeyMove$
  133.                 GOTO PrintAgain
  134.             CASE CHR$(13)
  135.                 PLAY enterKeyHit$
  136.                 IF opt = 1 THEN CALL Instructions
  137.                 IF opt = 2 THEN CALL Main
  138.                 IF opt = 3 THEN CALL LoadGame
  139.                 IF opt = 4 THEN CALL AddPhrase
  140.                 IF opt = 5 THEN END
  141.                 GOTO PrintAgain
  142.             CASE "1"
  143.                 PLAY enterKeyHit$
  144.                 CALL Instructions
  145.                 GOTO PrintAgain
  146.             CASE "2"
  147.                 PLAY enterKeyHit$
  148.                 loaded = FALSE
  149.                 CALL Main
  150.                 GOTO PrintAgain
  151.             CASE "3"
  152.                 PLAY enterKeyHit$
  153.                 loaded = TRUE
  154.                 CALL LoadGame
  155.                 GOTO PrintAgain
  156.             CASE "4"
  157.                 PLAY enterKeyHit$
  158.                 CALL AddPhrase
  159.                 GOTO PrintAgain
  160.             CASE "5"
  161.                 PLAY enterKeyHit$
  162.                 END
  163.         END SELECT
  164.     LOOP UNTIL choice$ = CHR$(13) OR choice$ = "5"
  165.  
  166. SUB Instructions
  167.     COLOR 10, 13: CLS
  168.     a$ = "A random phrase picked from " + CHR$(34) + "Phrases.txt" + CHR$(34) + " will be displayed in code."
  169.     LOCATE 12, Center(a$): PRINT a$
  170.     a$ = "The goal is to decode the phrase. The coded letters are in one color": LOCATE 14, Center(a$): PRINT a$
  171.     a$ = "and the letters you choose in another color. In easy mode, incorrect": LOCATE 16, Center(a$): PRINT a$
  172.     a$ = "letters are displayed in yet another color. Different types": LOCATE 18, Center(a$): PRINT a$
  173.     a$ = "of hints are available from the hint menu.": LOCATE 20, Center(a$): PRINT a$
  174.     a$ = "Use the arrow keys to select the letter you wish to change. Type": LOCATE 25, Center(a$): PRINT a$
  175.     a$ = "in the letter you wish to change it to. Push the [ESC] key": LOCATE 27, Center(a$): PRINT a$
  176.     a$ = "to reset the puzzle to the starting code.": LOCATE 29, Center(a$): PRINT a$
  177.  
  178.     a$ = "Hit any key to return to the Main Menu": LOCATE 45, Center(a$): COLOR 11, 13: PRINT a$: l$ = P$
  179.  
  180. SUB AddPhrase
  181.     COLOR 11, 13
  182.     CLS
  183.     a$ = "Type in the phrase you want to add. Do not hit": LOCATE 15, Center(a$): PRINT a$
  184.     a$ = " the [ENTER] key until you've entered the entire phrase. ": LOCATE 17, Center(a$): PRINT a$
  185.     a$ = "Don't worry if your entry passes the end of the screen": LOCATE 19, Center(a$): PRINT a$
  186.     a$ = "and continues on to the next line. In fact, longer": LOCATE 21, Center(a$): PRINT a$
  187.     a$ = "phrases are easier to decode.": LOCATE 23, Center(a$): PRINT a$
  188.  
  189.     LOCATE 28, 10: LINE INPUT "Type in your phrase: ", newPhrase$
  190.     maxIndex = FileStatus
  191.     DIM fileArray$(1 TO maxIndex + 1)
  192.     OPEN "Phrases.txt" FOR INPUT AS #1
  193.     FOR index = 1 TO maxIndex
  194.         LINE INPUT #1, fileArray$(index)
  195.     NEXT index
  196.     CLOSE #1
  197.  
  198.     fileArray$(maxIndex + 1) = newPhrase$
  199.     OPEN "Phrases.txt" FOR OUTPUT AS #1
  200.     FOR index = 1 TO maxIndex + 1
  201.         PRINT #1, fileArray$(index)
  202.     NEXT index
  203.     PRINT #1, "EOF"
  204.     CLOSE #1
  205.  
  206.  
  207. SUB LoadGame
  208.     maxLineNumber = 0
  209.     FOR index = 1 TO 26
  210.         translationMatrix$(index, 1) = "": translationMatrix$(index, 2) = ""
  211.         usersCode$(index, 1) = "": usersCode$(index, 2) = ""
  212.     NEXT index
  213.     codedPhrase$ = ""
  214.     answerPhrase$ = ""
  215.     highlightedLetter = 0
  216.     mode = 0
  217.     FOR index = 1 TO 15
  218.         workingLines$(index) = ""
  219.         initiallyCodedLines$(index) = ""
  220.         answerLines$(index) = ""
  221.         leftPositions(index) = 0
  222.     NEXT index
  223.  
  224.     OPEN "CryptoGram" FOR INPUT AS #1
  225.     LINE INPUT #1, mLN$: maxLineNumber = VAL(mLN$)
  226.     FOR index = 1 TO 26
  227.         LINE INPUT #1, translationMatrix$(index, 1)
  228.         LINE INPUT #1, translationMatrix$(index, 2)
  229.         LINE INPUT #1, usersCode$(index, 1)
  230.         LINE INPUT #1, usersCode$(index, 2)
  231.     NEXT index
  232.     LINE INPUT #1, codedPhrase$
  233.     LINE INPUT #1, answerPhrase$
  234.     LINE INPUT #1, hL$
  235.     LINE INPUT #1, m$: mode = VAL(m$)
  236.     FOR index = 1 TO maxLineNumber
  237.         LINE INPUT #1, workingLines$(index)
  238.         LINE INPUT #1, initiallyCodedLines$(index)
  239.         LINE INPUT #1, answerLines$(index)
  240.         LINE INPUT #1, lP$: leftPositions(index) = VAL(lP$)
  241.     NEXT index
  242.     CLOSE #1
  243.     loaded = TRUE: CALL Main
  244.  
  245. SUB SaveGame
  246.     OPEN "CryptoGram" FOR OUTPUT AS #1
  247.     PRINT #1, S$(maxLineNumber)
  248.     FOR index = 1 TO 26
  249.         PRINT #1, translationMatrix$(index, 1)
  250.         PRINT #1, translationMatrix$(index, 2)
  251.         PRINT #1, usersCode$(index, 1)
  252.         PRINT #1, usersCode$(index, 2)
  253.     NEXT index
  254.     PRINT #1, codedPhrase$
  255.     PRINT #1, answerPhrase$
  256.     PRINT #1, S$(highlightedLetter)
  257.     PRINT #1, S$(mode)
  258.     FOR index = 1 TO maxLineNumber
  259.         PRINT #1, workingLines$(index)
  260.         PRINT #1, initiallyCodedLines$(index)
  261.         PRINT #1, answerLines$(index)
  262.         PRINT #1, S$(leftPositions(index))
  263.     NEXT index
  264.     CLOSE #1
  265.     _DELAY (0.25)
  266.     PLAY arrowKeyMove$
  267.  
  268. SUB Main
  269.     IF loaded = FALSE THEN
  270.         FOR cl = 1 TO 26
  271.             translationMatrix$(cl, 1) = ""
  272.             translationMatrix$(cl, 2) = ""
  273.             usersCode$(cl, 1) = CHR$(cl + 64)
  274.             usersCode$(cl, 2) = "-"
  275.         NEXT cl
  276.         codedPhrase$ = ""
  277.         answerPhrase$ = ""
  278.         highlightedLetter = 1
  279.         FOR index = 1 TO numberOfLines
  280.             workingLines$(index) = ""
  281.             initiallyCodedLines$(index) = ""
  282.             answerLines$(index) = ""
  283.             leftPositions(index) = 0
  284.             maxLineNumber = 0
  285.         NEXT index
  286.  
  287.         COLOR 15, 1
  288.         'first, pick a phrase
  289.         randomPhrase = INT(RND * FileStatus) + 1
  290.         OPEN "Phrases.txt" FOR INPUT AS #1
  291.         FOR x = 1 TO randomPhrase
  292.             LINE INPUT #1, answerPhrase$
  293.         NEXT x
  294.         CLOSE #1
  295.  
  296.         'second, create a code
  297.         usedAlphabet$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  298.         FOR allLetters = 1 TO 26
  299.             translationMatrix$(allLetters, 1) = CHR$(allLetters + 64)
  300.             newRndLet:
  301.             randomLetter = INT(RND * LEN(usedAlphabet$)) + 1
  302.             translationMatrix$(allLetters, 2) = MID$(usedAlphabet$, randomLetter, 1)
  303.             IF translationMatrix$(allLetters, 1) = translationMatrix$(allLetters, 2) THEN GOTO newRndLet
  304.             usedAlphabet$ = MID$(usedAlphabet$, 1, randomLetter - 1) + MID$(usedAlphabet$, randomLetter + 1, LEN(usedAlphabet$))
  305.         NEXT allLetters
  306.  
  307.         'third: put the phrase in code
  308.         FOR letter = 1 TO LEN(answerPhrase$)
  309.             answerLetter$ = MID$(answerPhrase$, letter, 1)
  310.             upAnsLet$ = UCASE$(answerLetter$)
  311.             answerLetterNumber = ASC(upAnsLet$) - 64
  312.             IF ASC(upAnsLet$) >= 65 AND ASC(upAnsLet$) <= 90 THEN
  313.                 upCodeLet$ = translationMatrix$(ASC(upAnsLet$) - 64, 2)
  314.                 IF ASC(answerLetter$) >= 65 AND ASC(answerLetter$) <= 90 THEN
  315.                     codedLetter$ = upCodeLet$
  316.                 ELSE
  317.                     codedLetter$ = LCASE$(upCodeLet$)
  318.                 END IF
  319.             ELSE
  320.                 codedLetter$ = answerLetter$
  321.             END IF
  322.             codedPhrase$ = codedPhrase$ + codedLetter$
  323.         NEXT letter
  324.  
  325.         'next on the list is to center the phrases
  326.         lineNumber = 0
  327.         shrinkingCode$ = codedPhrase$
  328.         shrinkingAnswer$ = answerPhrase$
  329.         DO
  330.             checking = 60
  331.             DO
  332.                 wheresSpace$ = MID$(shrinkingAnswer$, checking, 1)
  333.                 checking = checking - 1
  334.             LOOP UNTIL wheresSpace$ = CHR$(32)
  335.             lineNumber = lineNumber + 1
  336.             answerLines$(lineNumber) = MID$(shrinkingAnswer$, 1, checking)
  337.             workingLines$(lineNumber) = MID$(shrinkingCode$, 1, checking)
  338.             initiallyCodedLines$(lineNumber) = MID$(shrinkingCode$, 1, checking)
  339.             leftPositions(lineNumber) = Center(answerLines$(lineNumber))
  340.             shrinkingAnswer$ = MID$(shrinkingAnswer$, checking + 1, LEN(shrinkingAnswer$))
  341.             shrinkingCode$ = MID$(shrinkingCode$, checking + 1, LEN(shrinkingCode$))
  342.         LOOP UNTIL LEN(shrinkingAnswer$) <= 60
  343.         lineNumber = lineNumber + 1
  344.         answerLines$(lineNumber) = shrinkingAnswer$
  345.         leftPositions(lineNumber) = Center(answerLines$(lineNumber))
  346.         workingLines$(lineNumber) = shrinkingCode$
  347.         initiallyCodedLines$(lineNumber) = shrinkingCode$
  348.  
  349.         maxLineNumber = lineNumber
  350.         highlightedLetter = 1
  351.     END IF
  352.     loaded = FALSE
  353.     refresh = TRUE
  354.     DO
  355.         userInput$ = UCASE$(INKEY$)
  356.         SELECT CASE userInput$
  357.             CASE "1"
  358.                 PLAY enterKeyHit$
  359.                 refresh = TRUE
  360.                 CALL Hints
  361.             CASE "2"
  362.                 PLAY enterKeyHit$
  363.                 CALL SaveGame
  364.                 CALL Menu
  365.             CASE CHR$(27)
  366.                 PLAY enterKeyHit$ + enterKeyHit$ + arrowKeyMove$
  367.                 CALL RestartPuzzle
  368.                 refresh = TRUE
  369.             CASE "5"
  370.                 CALL Menu
  371.                 PLAY enterKeyHit$
  372.                 highlightedLetter = 1
  373.                 FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": usersCode$(cl, 1) = "": usersCode$(cl, 2) = "": NEXT cl
  374.                 FOR cl = 1 TO numberOfLines
  375.                     workingLines$(cl) = ""
  376.                     initiallyCodedLines$(cl) = ""
  377.                     answerLines$(cl) = ""
  378.                     leftPositions(cl) = 0
  379.                 NEXT cl
  380.                 FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": usersCode$(cl, 1) = "": usersCode$(cl, 2) = "": NEXT cl
  381.                 mode = Normal
  382.  
  383.             CASE leftArrow$
  384.                 PLAY arrowKeyMove$
  385.                 IF highlightedLetter > 1 THEN
  386.                     highlightedLetter = highlightedLetter - 1
  387.                 ELSE
  388.                     highlightedLetter = 26
  389.                 END IF
  390.                 refresh = TRUE
  391.             CASE rightArrow$
  392.                 PLAY arrowKeyMove$
  393.                 IF highlightedLetter < 26 THEN
  394.                     highlightedLetter = highlightedLetter + 1
  395.                 ELSE
  396.                     highlightedLetter = 1
  397.                 END IF
  398.                 refresh = TRUE
  399.             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"
  400.                 PLAY enterKeyHit$
  401.                 usersCode$(highlightedLetter, 2) = userInput$
  402.                 CALL Switch(userInput$)
  403.                 refresh = TRUE
  404.         END SELECT
  405.  
  406.         IF refresh = TRUE THEN
  407.             refresh = FALSE
  408.             CALL ShowPuzzle
  409.         END IF
  410.     LOOP UNTIL userInput$ = "9" OR CorrectPhrase = TRUE
  411.     IF CorrectPhrase = TRUE THEN
  412.         COLOR 11, 0
  413.         LOCATE 25, Center("success")
  414.         PRINT "SUCCESS!!"
  415.         _DELAY (10)
  416.     END IF
  417.  
  418. SUB Hints
  419.     nope:
  420.     COLOR 14, 1
  421.     CLS
  422.     a$ = "You have an option of 3 types of hints to choose from.": LOCATE 10, Center(a$): PRINT a$
  423.     a$ = "Wheel of Fortune reveals the letters for R, S, T, L, N and E": LOCATE 11, Center(a$): PRINT a$
  424.     a$ = "Or you can choose to reveal a single letter.": LOCATE 12, Center(a$): PRINT a$
  425.     a$ = "Example phrase = Rmtleyr ewatbr": LOCATE 14, Center(a$): COLOR 10, 1: PRINT "Example phrase ";: COLOR 14, 1: PRINT "=";: COLOR 10, 1: PRINT " Rmtleyr ewatbr": COLOR 14, 1
  426.     a$ = "1.) Wheel of Fortune: Example phrase = Emtlele ewrtse": LOCATE 17, Center(a$): PRINT "1.) Wheel of Fortune: ";: COLOR 10, 1: PRINT "Example phrase = ";
  427.     COLOR 12, 1: PRINT "E";: COLOR 10, 1: PRINT "mtle";: COLOR 12, 1: PRINT "le";: COLOR 10, 1: PRINT " ew";: COLOR 12, 1: PRINT "r";: COLOR 10, 1: PRINT "t";: COLOR 12, 1: PRINT "se": COLOR 14, 1
  428.     a$ = "2.) Reveal a single random letter: Rmtleyr ewatbr": LOCATE 19, Center(a$): PRINT "2.) Reveal a single random letter: ";: COLOR 12, 1: PRINT "E";: COLOR 10, 1
  429.     PRINT "mtley";: COLOR 12, 1: PRINT "e";: COLOR 10, 1: PRINT " ewrts";: COLOR 12, 1: PRINT "e": COLOR 14, 1
  430.     a$ = "3.) Choose a single coded letter to decode:": LOCATE 21, Center(a$): PRINT a$
  431.     a$ = "    Pick any letter in example phrase": LOCATE 22, Center(a$): PRINT "    Pick any letter in ";: COLOR 10, 1: PRINT "R";
  432.     COLOR 12, 1: PRINT "m";: COLOR 10, 1: PRINT "tleyr ewatbr";: COLOR 14, 1
  433.     a$ = "      to be revealed in example phrase": LOCATE 23, Center(a$): PRINT "      to be revealed in ";: COLOR 10, 1: PRINT "E";: COLOR 12, 1: PRINT "x";: COLOR 10, 1: PRINT "ample phrase": COLOR 14, 1
  434.     a$ = "4.) Reveal a letter you think is in the answer phrase:": LOCATE 25, Center(a$): PRINT a$
  435.     a$ = "Choosing " + CHR$(34) + "K" + CHR$(34) + " wouldn't reveal anything. Choosing " + CHR$(34) + "L" + CHR$(34): LOCATE 26, Center(a$): PRINT a$
  436.     a$ = " Reveals the " + CHR$(34) + "L" + CHR$(34) + " -- example phrase": LOCATE 27, Center(a$): PRINT "reveals the " + CHR$(34) + "L" + CHR$(34) + " -- ";
  437.     COLOR 10, 1: PRINT "Examp";: COLOR 12, 1: PRINT "l";: COLOR 10, 1: PRINT "e phrase": COLOR 14, 1
  438.     a$ = "5.) Switch to easy mode": LOCATE 29, Center(a$): PRINT a$
  439.     a$ = "6.) Display every coded letter and the letter": LOCATE 31, Center(a$): PRINT a$
  440.     a$ = "       it should be for 2 seconds": LOCATE 32, Center(a$): PRINT a$
  441.  
  442.  
  443.  
  444.     a$ = "7.) Cancel": LOCATE 35, Center(a$): PRINT a$
  445.     PLAY arrowKeyMove$
  446.     r$ = P$
  447.     PLAY enterKeyHit$
  448.     SELECT CASE r$
  449.         CASE "1"
  450.             r$ = translationMatrix$(18, 2): re = ASC(r$) - 64: highlightedLetter = re: CALL Switch("R"): usersCode$(re, 2) = "R"
  451.             ss$ = translationMatrix$(19, 2): se = ASC(ss$) - 64: highlightedLetter = se: CALL Switch("S"): usersCode$(se, 2) = "S"
  452.             t$ = translationMatrix$(20, 2): te = ASC(t$) - 64: highlightedLetter = te: CALL Switch("T"): usersCode$(te, 2) = "T"
  453.             l$ = translationMatrix$(12, 2): le = ASC(l$) - 64: highlightedLetter = le: CALL Switch("L"): usersCode$(le, 2) = "L"
  454.             n$ = translationMatrix$(14, 2): ne = ASC(n$) - 64: highlightedLetter = ne: CALL Switch("N"): usersCode$(ne, 2) = "N"
  455.             e$ = translationMatrix$(5, 2): ee = ASC(e$) - 64: highlightedLetter = ee: CALL Switch("E"): usersCode$(ee, 2) = "E"
  456.         CASE "2"
  457.             gotThis:
  458.             tryAgain:
  459.             there = FALSE
  460.             someRandom$ = CHR$((INT(RND * 26)) + 65)
  461.             FOR x = 1 TO maxLineNumber
  462.                 FOR y = 1 TO LEN(answerLines$(x))
  463.                     IF UCASE$(MID$(answerLines$(x), y, 1)) = someRandom$ THEN there = TRUE
  464.                 NEXT y
  465.             NEXT x
  466.             IF there = FALSE THEN GOTO tryAgain
  467.             itShouldBeCodedAs$ = translationMatrix$(ASC(someRandom$) - 64, 2)
  468.             usersAttempt$ = usersCode$(ASC(itShouldBeCodedAs$) - 64, 2)
  469.             IF usersAttempt$ = someRandom$ THEN GOTO tryAgain
  470.             highlightedLetter = ASC(itShouldBeCodedAs$) - 64
  471.             Switch (someRandom$)
  472.             usersCode$(highlightedLetter, 2) = someRandom$
  473.         CASE "3"
  474.             PRINT: PRINT
  475.             a$ = "What code letter do you want to know the answer letter for?    ": LOCATE 37, Center(a$): PRINT a$;
  476.             aCodedLetter$ = P$: aCodedLetter$ = UCASE$(aCodedLetter$)
  477.             theCorrectLetter$ = ""
  478.             FOR index = 1 TO 26
  479.                 IF translationMatrix$(index, 2) = aCodedLetter$ THEN theCorrectLetter$ = translationMatrix$(index, 1)
  480.             NEXT index
  481.             highlightedLetter = ASC(aCodedLetter$) - 64
  482.             usersCode$(ASC(aCodedLetter$) - 64, 2) = theCorrectLetter$
  483.             CALL Switch(theCorrectLetter$)
  484.         CASE "4"
  485.             a$ = "What answer letter do you want the code for?    ": LOCATE 37, Center(a$): PRINT a$;: theCorrectLetter$ = P$: theCorrectLetter$ = UCASE$(theCorrectLetter$)
  486.             FOR index = 1 TO 26
  487.                 LOCATE 40, index: PRINT translationMatrix$(index, 1)
  488.                 LOCATE 41, index: PRINT translationMatrix$(index, 2)
  489.             NEXT index
  490.             f$ = P$
  491.             clPosition = ASC(theCorrectLetter$) - 64
  492.             letterCode$ = translationMatrix$(clPosition, 2)
  493.             highlightedLetter = ASC(letterCode$) - 64
  494.             CALL Switch(UCASE$(theCorrectLetter$))
  495.             usersCode$(highlightedLetter, 2) = UCASE$(theCorrectLetter$)
  496.         CASE "5"
  497.             mode = Easy
  498.         CASE "6"
  499.             COLOR 15, 1
  500.             CLS
  501.             FOR index = 1 TO 26
  502.                 LOCATE 22, ((80 - 52) / 2) + (index * 2)
  503.                 PRINT translationMatrix$(index, 1)
  504.                 LOCATE 24, ((80 - 52) / 2) + (index * 2)
  505.                 PRINT translationMatrix$(index, 2)
  506.             NEXT index
  507.             _DELAY (2)
  508.         CASE "7"
  509.             'just go away
  510.         CASE ELSE
  511.             GOTO nope
  512.     END SELECT
  513.     highlightedLetter = 1
  514.  
  515. FUNCTION CorrectPhrase
  516.     ag = TRUE
  517.     FOR x = 1 TO maxLineNumber
  518.         IF workingLines$(x) <> answerLines$(x) THEN ag = FALSE
  519.     NEXT x
  520.     CorrectPhrase = ag
  521.  
  522. SUB Switch (withThis$)
  523.     DIM newLines$(1 TO maxLineNumber): FOR i = 1 TO maxLineNumber: newLines$(i) = "": NEXT i
  524.     FOR l = 1 TO maxLineNumber
  525.         FOR c = 1 TO LEN(workingLines$(l))
  526.             letter$ = CHR$(highlightedLetter + 64)
  527.             initialLetter$ = MID$(initiallyCodedLines$(l), c, 1)
  528.             wcl$ = MID$(workingLines$(l), c, 1)
  529.             IF ASC(initialLetter$) >= 65 AND ASC(initialLetter$) <= 90 THEN
  530.                 withThis$ = UCASE$(withThis$)
  531.             ELSEIF ASC(initialLetter$) >= 97 AND ASC(initialLetter$) <= 122 THEN
  532.                 withThis$ = LCASE$(withThis$)
  533.             ELSE
  534.             END IF
  535.             IF letter$ = UCASE$(initialLetter$) THEN
  536.                 newLines$(l) = newLines$(l) + withThis$
  537.             ELSE
  538.                 newLines$(l) = newLines$(l) + wcl$
  539.             END IF
  540.         NEXT c 'haracter
  541.     NEXT l 'ine
  542.     FOR index = 1 TO maxLineNumber
  543.         workingLines$(index) = newLines$(index)
  544.     NEXT index
  545.  
  546. SUB RestartPuzzle
  547.     FOR c = 1 TO maxLineNumber
  548.         workingLines$(c) = initiallyCodedLines$(c)
  549.     NEXT c
  550.     FOR xx = 1 TO 26
  551.         usersCode$(xx, 2) = "-"
  552.     NEXT xx
  553.  
  554. SUB ShowPuzzle
  555.     COLOR 10, 1: CLS
  556.  
  557.     FOR eachLine = 1 TO maxLineNumber
  558.         LOCATE 13 + eachLine, leftPositions(eachLine)
  559.         FOR eachLetter = 1 TO LEN(workingLines$(eachLine))
  560.             f$ = MID$(workingLines$(eachLine), eachLetter, 1)
  561.             icl$ = MID$(initiallyCodedLines$(eachLine), eachLetter, 1)
  562.             correct$ = MID$(answerLines$(eachLine), eachLetter, 1)
  563.             ac = ASC(UCASE$(icl$)) - 64
  564.             IF f$ <> icl$ THEN
  565.                 COLOR 12, 1
  566.             END IF
  567.             IF f$ = correct$ AND mode = Easy THEN
  568.                 COLOR 15, 1
  569.             END IF
  570.             IF highlightedLetter = ac THEN
  571.                 COLOR 10, 0
  572.             END IF
  573.             IF f$ = icl$ AND highlightedLetter <> ac AND f$ <> correct$ THEN COLOR 10, 1
  574.  
  575.             PRINT f$;
  576.             COLOR 10, 1
  577.         NEXT eachLetter
  578.     NEXT eachLine
  579.     spaces = 2
  580.     FOR x = 1 TO 26
  581.         IF x = highlightedLetter THEN
  582.             COLOR 10, 0
  583.         ELSE
  584.             COLOR 10, 1
  585.         END IF
  586.         LOCATE 35, spaces
  587.         PRINT usersCode$(x, 1)
  588.         LOCATE 37, spaces
  589.         PRINT usersCode$(x, 2)
  590.         spaces = spaces + 3
  591.     NEXT x
  592.     a$ = "Push 1 to access the hint menu"
  593.     LOCATE 43, Center(a$): COLOR 14, 1: PRINT a$
  594.     a$ = "Push 2 to save the game and quit": COLOR 14, 1: LOCATE 45, Center(a$): PRINT a$
  595.     a$ = "Push [ESC] to reset": LOCATE 47, Center(a$): COLOR 14, 1: PRINT a$
  596.     a$ = "Push 5 to quit": LOCATE 49, Center(a$): COLOR 14, 1: PRINT a$
  597.  
  598. FUNCTION FileStatus
  599.     IF _FILEEXISTS("Phrases.txt") = 0 THEN
  600.         OPEN "Phrases.txt" FOR OUTPUT AS #1
  601.         PRINT #1, "Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our yesterdays have lighted fools The way to dusty death. Out, out, brief candle! Life's but a walking shadow, a poor player, That struts and frets his hour upon the stage, And then is heard no more. It is a tale Told by an idiot, full of sound and fury, Signifying nothing."
  602.         PRINT #1, "To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream"
  603.         PRINT #1, "If someone is able to show me that what I think or do is not right, I will happily change. For I seek the truth, by which no oe ever was truly harmed. Harmed is the person who continues in his self-deception and ignorance."
  604.         PRINT #1, "Funny lines: Before you marry a person, you should first make them use a computer with slow internet to see who they really are. -- Someone asked me, if I were stranded on a desert island what book would I bring... " + CHR$(34) + "How to Build a Boat." + CHR$(34)
  605.         PRINT #1, "Funny lines: I finally realized that people are prisoners of their own phones... that's why it's called a " + CHR$(34) + "cell" + CHR$(34) + " phone. -- Be decisive. Right or wrong, make a decision. The road is paved with flat squirrels who couldn't make a decision."
  606.         PRINT #1, "Funny lines: If at first you don't succeed, then skydiving definitely isn't for you. -- My cell phone is acting up. I keep pressing the Home button but every time I look around, I'm still at work."
  607.         PRINT #1, "Pangrams: Pack my box with five dozen liquor jugs. -- The quick brown fox jumps over the lazy dog. -- My girl wove six dozen plaid jackets before she quit."
  608.         PRINT #1, "EOF"
  609.         CLOSE #1
  610.         numberOfPhrases = 7
  611.     ELSE
  612.         OPEN "Phrases.txt" FOR INPUT AS #1
  613.         numberOfPhrases = 0
  614.         DO
  615.             numberOfPhrases = numberOfPhrases + 1
  616.             LINE INPUT #1, lineCounting$
  617.         LOOP UNTIL INSTR(lineCounting$, "EOF") <> 0
  618.         numberOfPhrases = numberOfPhrases - 1
  619.         CLOSE #1
  620.     END IF
  621.     FileStatus = numberOfPhrases
  622.  
  623. FUNCTION Center (text$)
  624.     Center = INT((80 - LEN(text$)) / 2)
  625.  
  626. FUNCTION S$ (number)
  627.     S$ = LTRIM$(STR$(number))
  628.  
  629.     pause$ = INPUT$(1)
  630.     IF pause$ = CHR$(27) THEN END
  631.     P$ = pause$
  632.  

Actually on line 314 you use Mid$ incorrectly for the 2nd Mid$ on the right of the = sign.
It does not produce error because QB64 is forgiving when you ask for more bytes = characters or letters, past the start position than are available in string, it just gives you all the letters it can.
Update: Lines 350 and 351 suffer the same problem and are "forgiven" by QB64 the same way, other Basics can be more picky! In all 3 cases you could use the 2 parameter version of Mid$ ie Mid$(s$, startPosition)

You do use Mid$() correctly everywhere you need a single letter Mid$(s$, startPosition, 1(letter))
And you use Mid$() correctly when the start position = 1 then the number of letters = the end position!

 
Mid$.PNG
« Last Edit: November 03, 2021, 03:54:18 pm by bplus »

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: CryptoGram finished!
« Reply #6 on: November 04, 2021, 05:44:57 pm »
I'm in the habit of giving MID$ three variables. If I hadn't been aware that MID$ would not give an error instead of the the empty string for letters beyond the end, I would've had to change my habitual use of three terms. And then there's the fact that if QB didn't return an empty string for every requested character beyond the length of the string, I would've had to code it differently, wouldn't I have?