1 /* $Id: result.c,v 1.28 2005/07/04 06:26:22 oohara Exp $ */
2
3 /* VERSION */
4 #include <config.h>
5
6 #include <stdio.h>
7 /* strlen */
8 #include <string.h>
9 /* malloc */
10 #include <stdlib.h>
11
12 #include "stage.h"
13 #include "score.h"
14 #include "tenm_graphic.h"
15 #include "util.h"
16 #include "tenm_input.h"
17 #include "tenm_timer.h"
18 #include "esc-ok.h"
19 #include "background.h"
20 #include "pause.h"
21 #include "const.h"
22 #include "option.h"
23
24 #include "result.h"
25
26 /* return 1 if the program should quit, 0 if not */
27 int
show_result(void)28 show_result(void)
29 {
30 int i;
31 int x;
32 int y;
33 char temp[128];
34 const option *op = NULL;
35
36 op = get_option();
37 if (op == NULL)
38 {
39 fprintf(stderr, "game_loop: get_option failed\n");
40 return 1;
41 }
42
43 /* no need to detect focus loss */
44 tenm_set_focus_handler((void (*)(int)) NULL);
45 clear_pause();
46
47 tenm_timer_reset();
48
49 set_background(0);
50 clear_window_with_background();
51
52 if (draw_string(100, 40, "dangen result", 14) != 0)
53 fprintf(stderr, "show_result: draw_string (title) failed\n");
54
55 sprintf(temp, "version %.20s", VERSION);
56 if (draw_string(100, 60, temp, (int) strlen(temp)) != 0)
57 fprintf(stderr, "show_result: draw_string (version) failed\n");
58
59 if (cheating())
60 {
61 x = 253;
62 y = 100;
63 if (draw_string(100, y, "cheat option(s):", 16) != 0)
64 fprintf(stderr, "show_result: draw_string (cheat option) failed\n");
65 if (op->free_select != 0)
66 {
67 if (draw_string(x, y, "--free-select", 13) != 0)
68 fprintf(stderr, "show_result: draw_string (--free-select) failed\n");
69 x += 126;
70 }
71 if (op->slow != 0)
72 {
73 if (draw_string(x, y, "--slow", 6) != 0)
74 fprintf(stderr, "show_result: draw_string (--slow) failed\n");
75 x += 63;
76 }
77 }
78
79 sprintf(temp, "total score: %8d", get_score());
80 if (draw_string(100, 150, temp, (int) strlen(temp)) != 0)
81 fprintf(stderr, "show_result: draw_string (total score) failed\n");
82
83 for (i = 1; i <= 5; i++)
84 {
85 if (i > get_stage_number())
86 break;
87 if (get_stage_id(i) < 0)
88 break;
89 if (get_stage_name(i) == NULL)
90 break;
91
92 y = 180 + (i - 1) * 20;
93 sprintf(temp, "%-20.20s %8d", get_stage_name(i),
94 get_stage_score(i));
95 if (draw_string(100, y, temp, (int) strlen(temp)) != 0)
96 fprintf(stderr, "show_result: draw_string (stage %d) failed\n", i);
97
98 if (get_stage_cleared(i) != 0)
99 {
100 if (draw_string(82, y, "*", 1) != 0)
101 fprintf(stderr, "show_result: draw_string (stage %d clear mark) "
102 "failed\n", i);
103 }
104 }
105 if (get_stage_cleared(6) != 0)
106 {
107 y = 180 + (6 - 1) * 20;
108 sprintf(temp, "* ship bonus %8d", get_stage_score(6));
109 if (draw_string(82, y, temp, (int) strlen(temp)) != 0)
110 fprintf(stderr, "show_result: draw_string (ship bonus) "
111 "failed\n");
112 }
113
114
115 if (draw_string(WINDOW_WIDTH / 2 - 76, 440, "press ESC to quit", 17) != 0)
116 fprintf(stderr, "show_result: draw_string (ESC instruction) failed\n");
117
118 tenm_redraw_window();
119
120 while (1 == 1)
121 {
122 /* quit the program if a SDL_QUIT event happened
123 * (for example, if a SIGINT signal (sent by Ctrl+c) is received)
124 */
125 if (tenm_event_handle() != 0)
126 {
127 return 1;
128 }
129
130 /* back to the title if ESC is pressed */
131 if (tenm_get_key_status() & 32)
132 {
133 if (get_esc_ok())
134 {
135 set_esc_ok(0);
136 break;
137 }
138 }
139 else
140 {
141 set_esc_ok(1);
142 }
143
144 /* this wait is necessary to save CPU time */
145 tenm_wait_next_frame();
146 }
147
148 return 0;
149 }
150