#include <stdlib.h>
#include <string.h>
-#include "board.h"
#include "debug.h"
-typedef struct {
- int xsize;
- int ysize;
- float factor;
- int length;
- int premium;
- char *TW;
- char *DW;
- char *TL;
- char *DL;
- char *CS;
-} board_t;
-
-board_t _board =
-{
- 15, /* xsize */
- 15, /* ysize */
- 1, /* factor */
- 7, /* length */
- 50, /* premium */
- "A1\0A8\0A15\0H1\0H15\0O1\0O8\0O15\0", /* TW */
- "B2\0B14\0C3\0C13\0D4\0D12\0E5\0E11\0K5\0K11\0L4\0L12\0M3\0M13\0N2\0N14\0", /* DW */
- "B6\0B10\0F2\0F6\0F10\0F14\0J2\0J6\0J10\0J14\0N6\0N10\0", /* TL */
- "A4\0A12\0C7\0C9\0D1\0D8\0D15\0G3\0G7\0G9\0G13\0H4\0H12\0I3\0I7\0I9\0I13\0L1\0L8\0L15\0M7\0M9\0O4\0O12\0", /* DL */
- "H8\0" /* CS */
-};
-board_t *board = &_board;
+#include "board.h"
int contains (char *list, char *str)
{
attrset (COLOR_PAIR(color));
}
-play_t *initplay (void)
+play_t *initplay (int xsize, int ysize)
{
play_t *play = (play_t *) malloc (sizeof (play_t));
- play->tab = (char *) malloc (board->xsize * board->ysize);
- memset (play->tab, ' ', board->xsize * board->ysize);
- play->xsize = board->xsize;
- play->ysize = board->ysize;
+ play->tab = (char *) malloc (xsize * ysize);
+ memset (play->tab, ' ', xsize * ysize);
+ play->xsize = xsize;
+ play->ysize = ysize;
return play;
}
set_color (white);
}
-void showboard (play_t *play, int xoffset, int yoffset, int full)
+void showboard (play_t *play, board_t *board, int xoffset, int yoffset, int full)
{
int x, y;
for (x = -1; x <= board->xsize; x++) {
#ifndef __BOARD_H__
#define __BOARD_H__
+#include "constant.h"
+
typedef struct {
int xsize;
int ysize;
char *tab;
} play_t;
-char *initboard (void);
+char *initboard (int xsize, int ysize);
play_t *initplay ();
void showletter (char letter, int x, int y);
-void showboard (play_t *play, int xoffset, int yoffset, int full);
+void showboard (play_t *play, board_t *board, int xoffset, int yoffset, int full);
#endif /* __BOARD_H__ */
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+
+#include "board.h"
+
+#include "constant.h"
+
+static board_t _board_15x15_7 =
+{
+ 15, /* xsize */
+ 15, /* ysize */
+ 1, /* factor */
+ 7, /* length */
+ 50, /* premium */
+ "A1\0A8\0A15\0H1\0H15\0O1\0O8\0O15\0", /* TW */
+ "B2\0B14\0C3\0C13\0D4\0D12\0E5\0E11\0K5\0K11\0L4\0L12\0M3\0M13\0N2\0N14\0", /* DW */
+ "B6\0B10\0F2\0F6\0F10\0F14\0J2\0J6\0J10\0J14\0N6\0N10\0", /* TL */
+ "A4\0A12\0C7\0C9\0D1\0D8\0D15\0G3\0G7\0G9\0G13\0H4\0H12\0I3\0I7\0I9\0I13\0L1\0L8\0L15\0M7\0M9\0O4\0O12\0", /* DL */
+ "H8\0" /* CS */
+};
+
+static char _tiles_fr[106] = {
+ ' ', ' ',
+ 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E',
+ 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
+ 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I',
+ 'N', 'N', 'N', 'N', 'N', 'N',
+ 'O', 'O', 'O', 'O', 'O', 'O',
+ 'R', 'R', 'R', 'R', 'R', 'R',
+ 'S', 'S', 'S', 'S', 'S', 'S',
+ 'T', 'T', 'T', 'T', 'T', 'T',
+ 'U', 'U', 'U', 'U', 'U', 'U',
+ 'L', 'L', 'L', 'L', 'L',
+ 'D', 'D', 'D',
+ 'M', 'M', 'M',
+ 'G', 'G',
+ 'B', 'B',
+ 'C', 'C',
+ 'P', 'P',
+ 'F', 'F',
+ 'H', 'H',
+ 'V', 'V',
+ 'J',
+ 'Q',
+ 'K',
+ 'W',
+ 'X',
+ 'Y',
+ 'Z'
+};
+
+static lettervalue_t _lettervalues_fr[27] = {
+ {' ', 0},
+ {'E', 1},
+ {'A', 1},
+ {'I', 1},
+ {'N', 1},
+ {'O', 1},
+ {'R', 1},
+ {'S', 1},
+ {'T', 1},
+ {'U', 1},
+ {'L', 1},
+ {'D', 2},
+ {'M', 2},
+ {'G', 2},
+ {'B', 3},
+ {'C', 3},
+ {'P', 3},
+ {'F', 4},
+ {'H', 4},
+ {'V', 4},
+ {'J', 8},
+ {'Q', 8},
+ {'K', 10},
+ {'W', 10},
+ {'X', 10},
+ {'Y', 10},
+ {'Z', 10}
+};
+
+static bag_t _bag = {0};
+
+board_t *getboard (char *name)
+{
+ board_t *pt = NULL;
+
+ if (strcmp (name, "15x15-7") == 0) {
+ pt = &_board_15x15_7;
+ }
+
+ return pt;
+}
+
+bag_t *getbag (char *lang)
+{
+ bag_t *pt = NULL;
+
+ if (strcmp (lang, "fr") == 0) {
+ pt = &_bag;
+ pt->nbtiles = sizeof (_tiles_fr);
+ pt->tiles = _tiles_fr;
+ pt->nbletters = 27;
+ pt->lettervalues = _lettervalues_fr;
+ }
+
+ return pt;
+}
+
+/* vim: set ts=4 sw=4 et: */
--- /dev/null
+#ifndef __CONSTANT_H__
+#define __CONSTANT_H__
+
+#include "board.h"
+
+typedef struct {
+ int xsize;
+ int ysize;
+ float factor;
+ int length;
+ int premium;
+ char *TW;
+ char *DW;
+ char *TL;
+ char *DL;
+ char *CS;
+} board_t;
+
+typedef struct {
+ char letter;
+ int value;
+} lettervalue_t;
+
+typedef struct {
+ int nbletters;
+ int nbtiles;
+ char *tiles;
+ lettervalue_t *lettervalues;
+} bag_t;
+
+board_t *getboard (char *name);
+
+bag_t *getbag (char *lang);
+
+#endif /* __CONSTANT_H__ */
+
+/* vim: set ts=4 sw=4 et: */
/* depend: */
/* cflags: */
-/* linker: board.o debug.o -lcurses */
-/* winlnk: board.o debug.o -lpdcurses */
+/* linker: board.o constant.o debug.o -lcurses */
+/* winlnk: board.o constant.o debug.o -lpdcurses */
+/* winxxlnk: board.o constant.o debug.o -lncurses */
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include "board.h"
+#include "constant.h"
#include "debug.h"
#define KEY_ESC 0x1b
}
}
+ board_t *board = getboard ("15x15-7");
+ play_t *play = initplay (board->xsize, board->ysize);
+ VERBOSE (DEBUG, printf ("play: 0x%p\nboard: 0x%p\n", play, board));
+
initscr();
//seed = time((time_t *)0);
//srand(seed);
help_window (50, 1, 30);
- play_t *play = initplay ();
-
int mode = 0;
int xoffset = 3;
int yoffset = 3;
- showboard (play, xoffset, yoffset, mode);
+ showboard (play, board, xoffset, yoffset, mode);
int x = (play->xsize + 1)/ 2 - 1;
int y = (play->ysize + 1)/ 2 - 1;
case ERR:
default:
}
- showboard (play, xoffset, yoffset, mode);
+ showboard (play, board, xoffset, yoffset, mode);
}
endwin ();