Guest User

Untitled

a guest
Feb 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. /*
  2. * Programming Challenge #4
  3. *
  4. * written by Alexander Frank
  5. * created on 02.13.18
  6. *
  7. * Game that compares a users guess number to a randomly generated number.
  8. *
  9. */
  10. program pc4;
  11.  
  12. // includes
  13. #include ("stdlib.hhf");
  14.  
  15. // static declarations
  16. static
  17. count: uns8 := 0;
  18. usersGuess: uns32;
  19. erraticNumber: uns32;
  20.  
  21. // procedure forward declarations
  22. procedure getUns32; @forward;
  23. procedure erraticNumberGenerator; @forward;
  24. procedure getAndCompare; @forward;
  25.  
  26. // procedure definitions
  27. // getUns32
  28. procedure getUns32;
  29. begin getUns32;
  30. forever
  31. try
  32. forever
  33.  
  34. stdout.put(nl, nl, " Enter a number [0-100]: ");
  35. stdin.flushInput();
  36. stdin.getu32();
  37. if (eax > 0 && eax <= 100) then
  38. mov(eax, usersGuess);
  39. break;
  40. endif;
  41.  
  42. endfor;
  43. unprotected break;
  44. anyexception
  45. stdout.put(nl, " Invalid entry. Try again.", nl, nl);
  46. endtry;
  47. endfor;
  48. end getUns32;
  49.  
  50. // erraticNumberGenerator
  51. procedure erraticNumberGenerator;
  52. begin erraticNumberGenerator;
  53. rand.randomize();
  54. rand.urange(0, 100);
  55. mov(eax, erraticNumber);
  56. end erraticNumberGenerator;
  57.  
  58. // compare
  59. procedure getAndCompare;
  60. begin getAndCompare;
  61. forever
  62. getUns32();
  63. mov(count, cl);
  64. inc(cl);
  65. mov(cl, count);
  66. stdout.put(" ~ The count is at ", (type uns8 count), "/10", nl);
  67. mov(usersGuess, eax);
  68. if (eax != erraticNumber) then
  69. if (eax < erraticNumber) then
  70. stdout.put(" ~ HINT: Too low!", nl);
  71. else
  72. stdout.put(" ~ HINT: Too high!", nl);
  73. endif;
  74.  
  75. stdout.put(" ~ ",(type uns32 usersGuess), " was not the random number! Try again!", nl, nl);
  76.  
  77. if (count >= 10) then
  78. stdout.put(nl, " Wow, you just LOST!", nl, nl);
  79. stdout.put(nl, " The RANDOM NUMBER is: ", (type uns32 erraticNumber) , nl, nl);
  80.  
  81. mov(0, count);
  82. break;
  83. endif;
  84. else
  85. stdout.put(nl, " YOU GUESSED THE RANDOM NUMBER ", (type uns32 erraticNumber), " !!!!!!!!", nl);
  86. stdout.put(nl, nl, nl " !!!!!!!!!!!!!!YOU WIN!!!!!!!!!!!!!!", nl, nl, nl, nl, nl, nl, nl, nl);
  87. mov(0,count);
  88. break;
  89. endif;
  90. endfor;
  91. end getAndCompare;
  92.  
  93. // main
  94. begin pc4;
  95. stdout.put(nl, " GUESSING GAME");
  96.  
  97. forever
  98. erraticNumberGenerator();
  99. getAndCompare();
  100. stdout.put(nl, "Play again? [y\n] : ");
  101. stdin.flushInput();
  102. stdin.getc();
  103. breakif(al == 'n');
  104. endfor;
  105. end pc4;
Add Comment
Please, Sign In to add comment