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