1 /* $OpenBSD: play_level.c,v 1.10 2016/01/04 17:33:24 mestre Exp $ */
2 /* $NetBSD: play_level.c,v 1.3 1995/04/22 10:09:03 cgd Exp $ */
3
4 /*
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 #include "robots.h"
34
35 /*
36 * play_level:
37 * Let the player play the current level
38 */
39 void
play_level(void)40 play_level(void)
41 {
42 COORD *cp;
43
44 move(My_pos.y, My_pos.x);
45 addch(PLAYER);
46 refresh();
47 for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) {
48 if (cp->y < 0)
49 continue;
50 move(cp->y, cp->x);
51 addch(ROBOT);
52 }
53 refresh();
54 #ifdef DEBUG
55 standout();
56 move(Min.y, Min.x);
57 addch(inch());
58 move(Max.y, Max.x);
59 addch(inch());
60 standend();
61 #endif /* DEBUG */
62 flushinp();
63 while (!Dead && Num_robots > 0) {
64 move(My_pos.y, My_pos.x);
65 if (!jumping())
66 refresh();
67 get_move();
68 if (Field[My_pos.y][My_pos.x] != 0)
69 Dead = TRUE;
70 if (!Dead)
71 move_robots();
72 if (Was_bonus) {
73 move(Y_PROMPT, X_PROMPT);
74 clrtoeol();
75 move(Y_PROMPT + 1, X_PROMPT);
76 clrtoeol();
77 Was_bonus = FALSE;
78 }
79 }
80
81 /*
82 * if the player didn't die, add on the possible bonuses
83 */
84
85 if (!Dead) {
86 Was_bonus = FALSE;
87
88 if (Level == Start_level && Start_level > 1) {
89 move(Y_PROMPT, X_PROMPT);
90 printw("Advance bonus: %d", S_BONUS);
91 refresh();
92 add_score(S_BONUS);
93 Was_bonus = TRUE;
94 }
95
96 if (Wait_bonus != 0) {
97 if (!Was_bonus)
98 move(Y_PROMPT, X_PROMPT);
99 else
100 move(Y_PROMPT + 1, X_PROMPT);
101 printw("Wait bonus: %d", Wait_bonus);
102 refresh();
103 add_score(Wait_bonus);
104 Was_bonus = TRUE;
105 }
106 }
107 }
108