CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
gui_mastermind.c-Dateireferenz
#include "camera_info.h"
#include "keyboard.h"
#include "lang.h"
#include "conf.h"
#include "gui.h"
#include "gui_draw.h"
#include "gui_lang.h"
#include "gui_batt.h"
#include "gui_mbox.h"
#include "modes.h"
#include "time.h"
#include "module_def.h"
#include "simple_game.c"
+ Include-Abhängigkeitsdiagramm für gui_mastermind.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define COLOR_LIGHT_GRAY   MAKE_COLOR(COLOR_GREY_LT,COLOR_GREY_LT)
 
#define BK_COLOR   MAKE_COLOR(COLOR_GREY,COLOR_GREY)
 
#define TEXT_COLOR   MAKE_COLOR(COLOR_GREY,COLOR_BLACK)
 

Funktionen

void gui_game_menu_kbd_process ()
 
int gui_mastermind_kbd_process ()
 
void gui_mastermind_draw ()
 
static void choice_box (int x, int y, twoColors cl)
 
static void clue_box (int pos, color col)
 
char WinQuary ()
 
static void info_line (char *msg)
 
char CanNext ()
 
void CreateColorCombo ()
 
int gui_mastermind_init ()
 
static void draw_box (color border)
 
static void end_game (int msg)
 
static void chg_box (int inc_box, int inc_val)
 
int basic_module_init ()
 

Variablen

gui_handler GUI_MODE_MASTERMIND
 
int cell_size = 20
 
int curr_x
 
int curr_y
 
int answer [4]
 
char colors [6]
 
int curr_color [4]
 
int GameGo
 
static char buf [128]
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define BK_COLOR   MAKE_COLOR(COLOR_GREY,COLOR_GREY)

Definiert in Zeile 25 der Datei gui_mastermind.c.

#define COLOR_LIGHT_GRAY   MAKE_COLOR(COLOR_GREY_LT,COLOR_GREY_LT)

Definiert in Zeile 24 der Datei gui_mastermind.c.

#define TEXT_COLOR   MAKE_COLOR(COLOR_GREY,COLOR_BLACK)

Definiert in Zeile 26 der Datei gui_mastermind.c.

Dokumentation der Funktionen

int basic_module_init ( )

Definiert in Zeile 277 der Datei gui_mastermind.c.

278 {
279  colors[0] = COLOR_RED;
280  colors[1] = COLOR_GREEN;
281  colors[2] = COLOR_BLUE;
282  colors[3] = COLOR_YELLOW;
283  colors[4] = COLOR_WHITE;
284  colors[5] = COLOR_BLACK;
285 
286  return gui_mastermind_init();
287 }
char CanNext ( )

Definiert in Zeile 96 der Datei gui_mastermind.c.

97 {
98  if (curr_color[0] == 99 || curr_color[1] == 99 || curr_color[2] == 99 || curr_color[3] == 99)
99  return 0;
100  else if (curr_color[0] == curr_color[1] || curr_color[0] == curr_color[2] || curr_color[0] == curr_color[3] ||
101  curr_color[1] == curr_color[2] || curr_color[1] == curr_color[3] ||
102  curr_color[2] == curr_color[3])
103  {
105  return 0;
106  }
107  return 1;
108 }
static void chg_box ( int  inc_box,
int  inc_val 
)
static

Definiert in Zeile 196 der Datei gui_mastermind.c.

197 {
199  curr_x = (curr_x + inc_box) & 3;
200  if (curr_color[curr_x] == 99) curr_color[curr_x] = 0;
201  curr_color[curr_x] = (curr_color[curr_x] + inc_val);
202  if (curr_color[curr_x] < 0) curr_color[curr_x] = 5;
203  else if (curr_color[curr_x] > 5) curr_color[curr_x] = 0;
205 }
static void choice_box ( int  x,
int  y,
twoColors  cl 
)
static

Definiert in Zeile 36 der Datei gui_mastermind.c.

static void clue_box ( int  pos,
color  col 
)
static

Definiert in Zeile 43 der Datei gui_mastermind.c.

44 {
45  int x = camera_screen.disp_left+4*cell_size+10+(pos+2)*(FONT_WIDTH+2);
48 }
void CreateColorCombo ( )

Definiert in Zeile 110 der Datei gui_mastermind.c.

111 {
112  char tmp = 0;
113  int i = 0;
114 
115  for (i = 0; i < 4; i++)
116  answer[i] = 99;
117  i = 0;
118  while (i < 4)
119  {
120  tmp = rand() % 6;
121  if (answer[0] != tmp && answer[1] != tmp && answer[2] != tmp && answer[3] != tmp)
122  {
123  answer[i] = tmp;
124  i++;
125  }
126  }
127 }
static void draw_box ( color  border)
static

Definiert in Zeile 182 der Datei gui_mastermind.c.

183 {
184  if (curr_color[curr_x] == 99) curr_color[curr_x] = 0;
186 }
static void end_game ( int  msg)
static

Definiert in Zeile 188 der Datei gui_mastermind.c.

189 {
190  int i;
191  info_line(lang_str(msg));
192  for (i=0; i<4;i++)
194 }
void gui_game_menu_kbd_process ( )

Definiert in Zeile 7 der Datei simple_game.c.

8 {
9  running = 0;
11 }
void gui_mastermind_draw ( )

Definiert in Zeile 266 der Datei gui_mastermind.c.

int gui_mastermind_init ( )

Definiert in Zeile 129 der Datei gui_mastermind.c.

130 {
131  int i, j;
132 
133  if (camera_screen.height * 3 > camera_screen.width * 2)
134  {
135  // worst case scenario (640x480)
136  cell_size = 8 * (camera_screen.height - FONT_HEIGHT * 2) / (9 * 9);
137  }
138  else
139  {
140  cell_size = (camera_screen.height - FONT_HEIGHT * 2) / 10;
141  }
142 
143  curr_x = 0;
144  curr_y = 7;
145 
147 
148  for (i = 0; i < 4; i++)
149  for (j = 0; j < 8; j++)
151 
155 
156  for (i = 0; i < 6; i++)
157  draw_rectangle(camera_screen.disp_right - (24 - i * 4) * FONT_WIDTH, 2 * FONT_HEIGHT + FONT_HEIGHT / 2, camera_screen.disp_right - (24 - i * 4) * FONT_WIDTH + FONT_HEIGHT, 3 * FONT_HEIGHT + FONT_HEIGHT / 2, MAKE_COLOR(colors[i], colors[i]),
159 
162 
166 
168 
172 
173  for (i = 0; i < 4; i++)
174  curr_color[i] = 99;
175 
177  return 1;
178 }
int gui_mastermind_kbd_process ( )

Definiert in Zeile 207 der Datei gui_mastermind.c.

208 {
209  int i = 0;
210  rand();
211  long key = kbd_get_autoclicked_key();
212  if (key)
213  {
214  if (GameGo == 1)
215  {
216  info_line(" ");
217  switch (key)
218  {
219  case KEY_SET:
220  if (CanNext())
221  {
222  if (WinQuary() == 1)
223  {
225  }
226  else if (WinQuary() == 2)
227  {
229  }
230  else
231  {
233  for (i = 0; i < 4; i++)
234  curr_color[i] = 99;
235  curr_y--;
236  curr_x = 0;
238  }
239  }
240  break;
241  case KEY_LEFT:
242  chg_box(-1, 0);
243  break;
244  case KEY_RIGHT:
245  chg_box(1, 0);
246  break;
247  case KEY_UP:
248  chg_box(0, 1);
249  break;
250  case KEY_DOWN:
251  chg_box(0, -1);
252  break;
253  }
254  }
255  else if (key == KEY_SET)
256  {
260  GameGo = 1;
261  }
262  }
263  return 0;
264 }
static void info_line ( char *  msg)
static
char WinQuary ( )

Definiert in Zeile 50 der Datei gui_mastermind.c.

51 {
52  char pos = 0;
53  int i, j;
54 
55  for (i = 0; i < 4; i++)
56  {
57  if (answer[i] == curr_color[i])
58  {
59  clue_box(pos, COLOR_BLACK);
60  pos++;
61  }
62  }
63 
64  if (pos == 4)
65  {
66  GameGo = 0;
67  return 1;
68  }
69 
70  for (i = 0; i < 4; i++)
71  {
72  for (j = 0; j < 4; j++)
73  {
74  if ((answer[i] == curr_color[j]) && (i != j))
75  {
76  clue_box(pos, COLOR_WHITE);
77  pos++;
78  }
79  }
80  }
81 
82  if (curr_y == 0)
83  {
84  GameGo = 0;
85  return 2;
86  }
87 
88  return 0;
89 }

Variablen-Dokumentation

int answer[4]

Definiert in Zeile 30 der Datei gui_mastermind.c.

char buf[128]
static

Definiert in Zeile 34 der Datei gui_mastermind.c.

int cell_size = 20

Definiert in Zeile 22 der Datei gui_mastermind.c.

char colors[6]

Definiert in Zeile 31 der Datei gui_mastermind.c.

int curr_color[4]

Definiert in Zeile 32 der Datei gui_mastermind.c.

int curr_x

Definiert in Zeile 28 der Datei gui_mastermind.c.

int curr_y

Definiert in Zeile 29 der Datei gui_mastermind.c.

int GameGo

Definiert in Zeile 33 der Datei gui_mastermind.c.