-------------------------------------------------------------------------------- PROGRAM BAGELS -------------------------------------------------------------------------------- LANGUAGES TO IMPLEMENT IN -------------------------------------------------------------------------------- # LANGUAGE IDE -- --------- ---------------------------------------------- 01 Ada GNAT Studio 02 BASIC GW-BASIC 03 C\C++ C-Free 04 C# Visual Studio 2019 05 COBOL OpenCobolIDE 06 Haskell Notepad++ -> Command Line (with help from cabal) 07 Java Eclipse 08 Lisp Racket 09 Lua ZeroBrane Studio 10 Pascal Turbo Pascal 11 Perl Notepad++ -> Command Line 12 PowerShell Notepad++ -> Windows PowerShell 13 Python Idle 14 VB .NET Visual Studio 2019 -------------------------------------------------------------------------------- GLOBAL VARIABLES -------------------------------------------------------------------------------- Running(BOOLEAN) for main outer loop GameOver(BOOLEAN) for inner loop Digits(ARRAY OF INTEGERS) holding the three digits. Score(INTEGER) holds the player's win count -------------------------------------------------------------------------------- GAME LOOP VARIABLES -------------------------------------------------------------------------------- Guess(INTEGER) player's guess Attempt(INTEGER) number of tries Guessed(BOOLEAN) did the number get guessed -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- METHODS/FUNCTIONS (GENERIC) -------------------------------------------------------------------------------- AskQuestion -------------------------------------------------------------------------------- ACCEPT : prompt(STRING) RETURN : STRING LOGIC : display the prompt and accept input. all input is uppercased, then return the input. do not allow empty string. if the string is empty display PLEASE ANSWER THE QUESTION. -------------------------------------------------------------------------------- GetIntInput -------------------------------------------------------------------------------- ACCEPT : prompt(STRING) RETURN : INTEGER LOGIC : display the prompt and accept input. verify that the response is an INTEGER using IsAnInt method and if it is not, display YOU DID NOT ENTER AN INTEGER. and ask again. otherwise return the response. -------------------------------------------------------------------------------- IsAnInt -------------------------------------------------------------------------------- ACCEPT : input(STRING) RETURN : BOOLEAN LOGIC : determine if the input is an INTEGER or not and return BOOLEAN -------------------------------------------------------------------------------- AskToPlayAgain -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : BOOLEAN LOGIC : ask the player DO YOU WANT TO PLAY AGAIN? and get a response, the response is compared against uppercased YES or Y and NO or N. if the response is anything else, display PLEASE ANSWER "YES" OR "NO". and ask again. if the response is YES or Y or NO or N then return a BOOLEAN value that represents that response. Use AskQuestion method. -------------------------------------------------------------------------------- AskToSeeTheRules -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : BOOLEAN LOGIC : ask DO YOU WANT TO SEE THE RULES? and accept a response. if the response is YES or Y then return TRUE otherwise return FALSE. Use AskQuestion method. -------------------------------------------------------------------------------- GenerateRandomNumber -------------------------------------------------------------------------------- ACCEPT : minimum(INTEGER) maximum(INTEGER) show(BOOLEAN) RETURN : INTEGER LOGIC : generate a random INTEGER between minimum and maximum, show determines if it displays the value generated or not, finally return the generated value. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- METHODS/FUNCTIONS (SPECIFIC TO GAME) -------------------------------------------------------------------------------- AskForGuess -------------------------------------------------------------------------------- ACCEPT : Attempt(INTEGER) RETURN : INTEGER LOGIC : display GUESS #[Attempt]? and accept input. check to see that the input is an INTEGER, larger than 99, less than 1000, and is non-negative. if it is negative tell the player PLEASE GUESS A NON-NEGATIVE NUMBER. if it is < 100 or > 999 tell the player PLEASE GUESS A NUMBER BETWEEN 100 AND 999. otherwise return the INTEGER response. -------------------------------------------------------------------------------- DisplayRules -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : display the rules as I WILL THINK OF A THREE-DIGIT NUMBER. YOU WILL TRY TO GUESS MY NUMBER AND I WILL GIVE YOU CLUES AS FOLLOWS: PICO - ONE DIGIT CORRECT BUT IN THE WRONG POSITION FERMI - ONE DIGIT CORRECT AND IN THE RIGHT POSITION BAGELS - NO DIGITS ARE CORRECT [BLANK LINE] YOU GET TWENTY TRIES BEFORE YOU LOSE. [BLANK LINE] -------------------------------------------------------------------------------- DisplayGameOver -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : using MakeIntFromArray display OH WELL, THAT'S TWENTY GUESSES. MY NUMBER WAS [NUMBER]. [BLANK LINE] -------------------------------------------------------------------------------- MakeIntFromArray -------------------------------------------------------------------------------- ACCEPT : arrayIn (INTEGERS) RETURN : retVal INTEGER LOGIC : turn the three digits from the array into an int and return. this is arrayIn(1) * 100 + arrayIn(2) * 10 + arrayIn(3) -------------------------------------------------------------------------------- MakeArrayFromInt -------------------------------------------------------------------------------- ACCEPT : valIn INTEGER RETURN : retArray (ARRAY OF INTEGERS) LOGIC : turn the number into an array of 3 digits as retArray(1) = valIn / 100 retArray(2) = (valIn - (retArray(1) * 100)) / 10 retArray(3) = (valIn - (retArray(1) * 100) - (retArray(2)) * 10) return the retArray -------------------------------------------------------------------------------- CreateTheNumber -------------------------------------------------------------------------------- ACCEPT : NONE RETURN : NONE LOGIC : randomly select the first digit between 1 and 9. randomly select the second and third digits between 0 and 9. none of the numbers can be the same. store the digits into the Digits array. -------------------------------------------------------------------------------- CheckGuess -------------------------------------------------------------------------------- ACCEPT : Guess INTEGER RETURN : BOOLEAN LOGIC : call MakeArrayFromInt and pass in Guess place in Temp(INTEGER) create an array vals(INTEGER) to hold the comparison results Then compare: Temp(1) vs Digits(1) if same then vals(1) = 1 Temp(2) vs Digits(2) if same then vals(2) = 1 Temp(3) vs Digits(3) if same then vals(3) = 1 if(vals(1-3) = 111) then return TRUE (the player guessed right) otherwise if vals(1) = 0 then compare Temp(1) vs Digits(2) if same then vals(1) = 2 Temp(1) vs Digits(3) if same then vals(1) = 2 if vals(2) = 0 then compare Temp(2) vs Digits(1) if same then vals(2) = 2 Temp(2) vs Digits(3) if same then vals(2) = 2 if vals(3) = 0 then compare Temp(3) vs Digits(1) if same then vals(3) = 2 Temp(3) vs Digits(2) if same then vals(3) = 2 if vals(1-3) = 0 then display BAGELS else if vals(1) = 1 display FERMI else if vals(1) = 2 display PICO if vals(2) = 1 display FERMI else if vals(2) = 2 display PICO if vals(3) = 1 display FERMI else if vals(3) = 2 display PICO return false -------------------------------------------------------------------------------- Main Logic -------------------------------------------------------------------------------- display *** BAGELS : [LANGUAGE] *** define guess as INTEGER set Running to TRUE if AskToSeeTheRules returns TRUE call DisplayRules initialize Score to 0 loop while Running initialize Attempt to 1 call CreateTheNumber display OK, I HAVE A NUMBER IN MIND. loop while GameOver is FALSE Guess = AskForGuess() Guessed = call CheckGuess(Guess) if Guessed = TRUE then display YOU GOT IT!!! increase Score by 1 GameOver = TRUE else increase Attempt by 1 if Attempt > 20 then DisplayGameOver() GameOver = TRUE do loop logic display *** GAME OVER *** Running = AskToPlayAgain() do loop logic display A [SCORE] POINT BAGLES BUFF! display HOPE YOU HAD FUN. BYE! --------------------------------------------------------------------------------