ularn_ask.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: ularn_ask.c
  4. *
  5. * DESCRIPTION:
  6. * This module provides functions for getting answers to common questions
  7. * in the game from teh player.
  8. *
  9. * =============================================================================
  10. * EXPORTED VARIABLES
  11. *
  12. * None
  13. *
  14. * =============================================================================
  15. * EXPORTED FUNCTIONS
  16. *
  17. * more - Asks press space to continue
  18. * clearpager - resets pagination calculations for paged text output
  19. * pager - Call to perform pagination ofter each line of text is output
  20. * getyn - ASks for a yess no answer
  21. * getpassword - Get the password for wizard
  22. * dirsub - Asks for a direction
  23. *
  24. * =============================================================================
  25. */
  26. #include "ularn_ask.h"
  27. #include "dungeon.h"
  28. #include "header.h"
  29. #include "player.h"
  30. #include "ularn_game.h"
  31. #include "ularn_win.h"
  32. /* =============================================================================
  33. * Local variables
  34. */
  35. /* the current line number for paginating text */
  36. static int srcount = 0;
  37. /* =============================================================================
  38. * Exported functions
  39. */
  40. /* =============================================================================
  41. * FUNCTION: more
  42. */
  43. void more(void) {
  44. Print("\n --- press ");
  45. Standout("space");
  46. Print(" to continue --- ");
  47. get_prompt_input("", " ", 0);
  48. }
  49. /* =============================================================================
  50. * FUNCTION: clearpager
  51. */
  52. void clearpager(void) { srcount = 0; }
  53. /* =============================================================================
  54. * FUNCTION: pager
  55. */
  56. void pager(void) {
  57. if (++srcount >= 22) {
  58. srcount = 0;
  59. more();
  60. ClearText();
  61. }
  62. }
  63. /* =============================================================================
  64. * FUNCTION: getyn
  65. */
  66. int getyn(void) {
  67. int i;
  68. i = get_prompt_input("", "yYnN\033 ", 1);
  69. if (isspace(i))
  70. i = ESC;
  71. return i;
  72. }
  73. /* =============================================================================
  74. * FUNCTION: getpassword
  75. */
  76. int getpassword(void) {
  77. char gpwbuf[9];
  78. Print("\nEnter Password: ");
  79. get_password_input(gpwbuf, 8);
  80. if (strcmp(gpwbuf, password) != 0) {
  81. Print("\nSorry.\n");
  82. return 0;
  83. } else
  84. return 1;
  85. }
  86. /* =============================================================================
  87. * FUNCTION: dirsub
  88. */
  89. int dirsub(int *x, int *y) {
  90. ActionType ans;
  91. int d;
  92. ActionType dir_order[9];
  93. /*
  94. * Direction keys. Order must match diroff
  95. */
  96. dir_order[0] = ACTION_MOVE_SOUTH;
  97. dir_order[1] = ACTION_MOVE_EAST;
  98. dir_order[2] = ACTION_MOVE_NORTH;
  99. dir_order[3] = ACTION_MOVE_WEST;
  100. dir_order[4] = ACTION_MOVE_NORTHEAST;
  101. dir_order[5] = ACTION_MOVE_NORTHWEST;
  102. dir_order[6] = ACTION_MOVE_SOUTHEAST;
  103. dir_order[7] = ACTION_MOVE_SOUTHWEST;
  104. dir_order[8] = 0;
  105. ans = get_dir_input("\nIn What Direction? ", 1);
  106. d = 0;
  107. while (dir_order[d] != ans)
  108. d++;
  109. d++;
  110. Print(dirname[d]);
  111. *x = playerx + diroffx[d];
  112. *y = playery + diroffy[d];
  113. return d;
  114. }