Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Programming Challenge #4
- *
- * written by Alexander Frank
- * created on 02.13.18
- *
- * Game that compares a users guess number to a randomly generated number.
- *
- */
- program pc4;
- // includes
- #include ("stdlib.hhf");
- // static declarations
- static
- count: uns8 := 0;
- usersGuess: uns32;
- erraticNumber: uns32;
- // procedure forward declarations
- procedure getUns32; @forward;
- procedure erraticNumberGenerator; @forward;
- procedure getAndCompare; @forward;
- // procedure definitions
- // getUns32
- procedure getUns32;
- begin getUns32;
- forever
- try
- forever
- stdout.put(nl, nl, " Enter a number [0-100]: ");
- stdin.flushInput();
- stdin.getu32();
- if (eax > 0 && eax <= 100) then
- mov(eax, usersGuess);
- break;
- endif;
- endfor;
- unprotected break;
- anyexception
- stdout.put(nl, " Invalid entry. Try again.", nl, nl);
- endtry;
- endfor;
- end getUns32;
- // erraticNumberGenerator
- procedure erraticNumberGenerator;
- begin erraticNumberGenerator;
- rand.randomize();
- rand.urange(0, 100);
- mov(eax, erraticNumber);
- end erraticNumberGenerator;
- // compare
- procedure getAndCompare;
- begin getAndCompare;
- forever
- getUns32();
- mov(count, cl);
- inc(cl);
- mov(cl, count);
- stdout.put(" ~ The count is at ", (type uns8 count), "/10", nl);
- mov(usersGuess, eax);
- if (eax != erraticNumber) then
- if (eax < erraticNumber) then
- stdout.put(" ~ HINT: Too low!", nl);
- else
- stdout.put(" ~ HINT: Too high!", nl);
- endif;
- stdout.put(" ~ ",(type uns32 usersGuess), " was not the random number! Try again!", nl, nl);
- if (count >= 10) then
- stdout.put(nl, " Wow, you just LOST!", nl, nl);
- stdout.put(nl, " The RANDOM NUMBER is: ", (type uns32 erraticNumber) , nl, nl);
- mov(0, count);
- break;
- endif;
- else
- stdout.put(nl, " YOU GUESSED THE RANDOM NUMBER ", (type uns32 erraticNumber), " !!!!!!!!", nl);
- stdout.put(nl, nl, nl " !!!!!!!!!!!!!!YOU WIN!!!!!!!!!!!!!!", nl, nl, nl, nl, nl, nl, nl, nl);
- mov(0,count);
- break;
- endif;
- endfor;
- end getAndCompare;
- // main
- begin pc4;
- stdout.put(nl, " GUESSING GAME");
- forever
- erraticNumberGenerator();
- getAndCompare();
- stdout.put(nl, "Play again? [y\n] : ");
- stdin.flushInput();
- stdin.getc();
- breakif(al == 'n');
- endfor;
- end pc4;
Add Comment
Please, Sign In to add comment