void getRandomWord(char *output, size_t length);
int nextBlank(const char *string);
-
+enum Hotboxes { BoxSolve, BoxNew, BoxQuit, BoxShuffle, BoxEnter, BoxClear };
+const char *BoxNames[] = {
+ "solve", "new", "quit", "shuffle", "enter", "clear"
+};
+Box hotbox[6] = {
+ /* BoxSolve */ { 612, 0, 66, 30 },
+ /* BoxNew */ { 686, 0, 46, 30 },
+ /* BoxQuit */ { 742, 0, 58, 30 },
+ /* BoxShuffle */ { 618, 206, 66, 16 },
+ /* BoxEnter */ { 690, 254, 40, 35 },
+ /* BoxClear */ { 690, 304, 40, 40 }
+};
/* module level variables for game control */
char shuffle[8] = SPACE_FILLED_CHARS;
}
}
-
+static int IsInside(Box box, int x, int y)
+{
+ return ((x > box.x) && x < (box.x + box.width)
+ && (y > box.y) && (y < box.y + box.height));
+}
/***********************************************************
current=current->next;
}
- if (x > CLEARBOXSTARTX && x < CLEARBOXLENGTH+CLEARBOXSTARTX && y > CLEARBOXSTARTY && y < CLEARBOXSTARTY+CLEARBOXHEIGHT){
+ if (IsInside(hotbox[BoxClear], x, y)) {
/* clear has been pressed */
clearGuess = 1;
}
/* check the other hotspots */
- if (x > ENTERBOXSTARTX && x < ENTERBOXLENGTH+ENTERBOXSTARTX && y > ENTERBOXSTARTY && y < ENTERBOXSTARTY+ENTERBOXHEIGHT){
+ if (IsInside(hotbox[BoxEnter], x, y)) {
/* enter has been pressed */
checkGuess(answer, head);
}
-
- if (x > SOLVEBOXSTARTX && x < SOLVEBOXLENGTH+SOLVEBOXSTARTX && y > SOLVEBOXSTARTY && y < SOLVEBOXSTARTY+SOLVEBOXHEIGHT){
+ if (IsInside(hotbox[BoxSolve], x, y)) {
/* solve has been pressed */
solvePuzzle = 1;
}
- if (x > SHUFFLEBOXSTARTX && x < SHUFFLEBOXLENGTH+SHUFFLEBOXSTARTX && y > SHUFFLEBOXSTARTY && y < SHUFFLEBOXSTARTY+SHUFFLEBOXHEIGHT){
+ if (IsInside(hotbox[BoxShuffle], x, y)) {
/* shuffle has been pressed */
shuffleRemaining = 1;
Mix_PlayChannel(-1, getSound("shuffle"),0);
}
}
- if (x > NEWBOXSTARTX && x < NEWBOXLENGTH+NEWBOXSTARTX && y > NEWBOXSTARTY && y < NEWBOXSTARTY+NEWBOXHEIGHT){
+ if (IsInside(hotbox[BoxNew], x, y)) {
/* new has been pressed */
startNewGame = 1;
}
- if (x > QUITBOXSTARTX && x < QUITBOXLENGTH+QUITBOXSTARTX && y > QUITBOXSTARTY && y < QUITBOXSTARTY+QUITBOXHEIGHT){
+ if (IsInside(hotbox[BoxQuit], x, y)) {
/* new has been pressed */
quitGame = 1;
}
static int
is_valid_locale(const char *path)
{
- FILE *fp = NULL;
- char buffer[260];
- strcpy(buffer, path);
- if (buffer[strlen(buffer)-1] != '/')
- strcat(buffer, "/");
- strcat(buffer, "wordlist.txt");
- if ((fp = fopen(buffer, "r")) != NULL)
- fclose(fp);
- Debug("testing %s: %s", buffer, (fp == NULL)?"failed":"present");
- return (fp != NULL);
+ FILE *fp = NULL;
+ char buffer[260];
+ strcpy(buffer, path);
+ if (buffer[strlen(buffer)-1] != '/')
+ strcat(buffer, "/");
+ strcat(buffer, "wordlist.txt");
+ if ((fp = fopen(buffer, "r")) != NULL)
+ fclose(fp);
+ Debug("testing %s: %s", buffer, (fp == NULL)?"failed":"present");
+ return (fp != NULL);
+}
+
+/*
+ * parse a config line eg: solve = 555 30 76 20
+ */
+static int
+configBox(Box *pbox, const char *line)
+{
+ int x, y, w, h;
+ const char *p = strchr(line, '=');
+ if (p && sscanf(p+1, "%d %d %d %d", &x, &y, &w, &h) == 4) {
+ pbox->x = x;
+ pbox->y = y;
+ pbox->width = w;
+ pbox->height = h;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * read any locale-specific configuration information from an ini
+ * ini file. This can reconfigure the positions of the boxes to account
+ * for different word sizes or alternative background layouts
+ */
+static void
+loadConfig(const char *path)
+{
+ FILE *fp = NULL;
+ char line[80], *p;
+ if ((fp = fopen(path, "r")) != NULL) {
+ Debug("loading configuration from %s", path);
+ while (!feof(fp)) {
+ if ((p = fgets(line, sizeof(line), fp)) != NULL) {
+ int i;
+ while (*p && isspace(*p))
+ ++p;
+ if (*p == 0 || *p == ';')
+ continue;
+
+ for (i = 0; i < sizeof(BoxNames)/sizeof(BoxNames[0]); ++i) {
+ if (strncmp(BoxNames[i], p, strlen(BoxNames[i])) == 0) {
+ configBox(&hotbox[i], p);
+ break;
+ }
+ }
+ }
+ }
+ fclose(fp);
+ }
}
/*
smallLetterBank = SDL_LoadBMP(strcat(txt,"images/smallLetterBank.bmp"));
strcpy(txt, language);
numberBank = SDL_LoadBMP(strcat(txt,"images/numberBank.bmp"));
+ /* load locale specific configuration */
+ strcpy(txt, language);
+ loadConfig(strcat(txt, "config.ini"));
newGame(&head, dlbHead, screen, &letters);
/*SDL_Quit(); */
return 0;
}
+
+/*
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * tab-width: 4
+ * End:
+ */
// ASCII OFFSET to convert a number to it's character equivalent
#define NUM_TO_CHAR 48
+typedef struct Box {
+ int x;
+ int y;
+ int width;
+ int height;
+} Box;
+
// pixel locations of boxes
#define SHUFFLEBOX 110
#define ANSWERBOX 245
#define SHUFFLE 2
#define CONTROLS 3
-// enter button size and position
-#define ENTERBOXSTARTX 690
-#define ENTERBOXLENGTH 40
-#define ENTERBOXSTARTY 254
-#define ENTERBOXHEIGHT 35
-
-// clear button size and position
-#define CLEARBOXSTARTX 690
-#define CLEARBOXLENGTH 40
-#define CLEARBOXSTARTY 304
-#define CLEARBOXHEIGHT 40
-
-// shuffle button size and position
-#define SHUFFLEBOXSTARTX 618
-#define SHUFFLEBOXLENGTH 66
-#define SHUFFLEBOXSTARTY 206
-#define SHUFFLEBOXHEIGHT 16
-
-// solve button size and position
-#define SOLVEBOXSTARTX 612
-#define SOLVEBOXLENGTH 66
-#define SOLVEBOXSTARTY 0
-#define SOLVEBOXHEIGHT 30
-
-// new button size and position
-#define NEWBOXSTARTX 686
-#define NEWBOXLENGTH 46
-#define NEWBOXSTARTY 0
-#define NEWBOXHEIGHT 30
-
-// quit button size and position
-#define QUITBOXSTARTX 742
-#define QUITBOXLENGTH 58
-#define QUITBOXSTARTY 0
-#define QUITBOXHEIGHT 30
-
// define the clock position and character width
#define CLOCK_X 690
#define CLOCK_Y 35