init_field.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* $NetBSD: init_field.c,v 1.8 2003/08/07 09:37:36 agc Exp $ */
  2. /*
  3. * Copyright (c) 1980, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. #if 0
  33. static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: init_field.c,v 1.8 2003/08/07 09:37:36 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. # include "robots.h"
  39. static int telx = 0;
  40. static int tely = 0;
  41. /*
  42. * init_field:
  43. * Lay down the initial pattern whih is constant across all levels,
  44. * and initialize all the global variables.
  45. */
  46. void
  47. init_field()
  48. {
  49. int i;
  50. static bool first = TRUE;
  51. static const char *const desc[] = {
  52. "Directions:",
  53. "",
  54. "y k u",
  55. " \\|/",
  56. "h- -l",
  57. " /|\\",
  58. "b j n",
  59. "",
  60. "Commands:",
  61. "",
  62. "w: wait for end",
  63. "t: teleport",
  64. "q: quit",
  65. "^L: redraw screen",
  66. "",
  67. "Legend:",
  68. "",
  69. "+: robot",
  70. "*: junk heap",
  71. "@: you",
  72. "",
  73. "Score: 0",
  74. NULL
  75. };
  76. Dead = FALSE;
  77. Waiting = FALSE;
  78. Score = 0;
  79. erase();
  80. move(0, 0);
  81. addch('+');
  82. for (i = 1; i < Y_FIELDSIZE; i++) {
  83. move(i, 0);
  84. addch('|');
  85. }
  86. move(Y_FIELDSIZE, 0);
  87. addch('+');
  88. for (i = 1; i < X_FIELDSIZE; i++)
  89. addch('-');
  90. addch('+');
  91. if (first)
  92. refresh();
  93. move(0, 1);
  94. for (i = 1; i < X_FIELDSIZE; i++)
  95. addch('-');
  96. addch('+');
  97. for (i = 1; i < Y_FIELDSIZE; i++) {
  98. move(i, X_FIELDSIZE);
  99. addch('|');
  100. }
  101. if (first)
  102. refresh();
  103. for (i = 0; desc[i] != NULL; i++) {
  104. move(i, X_FIELDSIZE + 2);
  105. addstr(desc[i]);
  106. }
  107. telx = X_FIELDSIZE + 2;
  108. tely = i;
  109. if (first)
  110. refresh();
  111. first = FALSE;
  112. #ifdef FANCY
  113. if (Pattern_roll)
  114. Next_move = &Move_list[-1];
  115. #endif
  116. }
  117. void
  118. telmsg(on)
  119. int on;
  120. {
  121. move(tely, telx);
  122. addstr(on ? "Teleport!" : " ");
  123. }