Add the basic code structure and build system
[Project_algorithmic_C.git] / lib / ui.c
diff --git a/lib/ui.c b/lib/ui.c
new file mode 100644 (file)
index 0000000..cee08f1
--- /dev/null
+++ b/lib/ui.c
@@ -0,0 +1,74 @@
+/*
+ * =====================================================================================
+ *
+ *       Filename:  ui.c
+ *
+ *    Description:  Routines to handle the user interface 
+ *
+ *        Version:  1.0
+ *        Created:  24/04/2017 16:41:15
+ *       Revision:  none
+ *       Compiler:  gcc
+ *
+ *         Author:  Jerome Benoit (fraggle), jerome.benoit@piment-noir.org
+ *   Organization:  Piment Noir
+ *
+ * =====================================================================================
+ */
+
+#include <ncurses.h>
+
+#include "ui.h"
+
+/* in all print routine, y and x are the coordinates of the first character of the shape
+ * which can be a space ' ' */
+
+/* FIXME: one can split this shape in building blocks and build it using them */
+void print_board(int y, int x) {
+
+    mvprintw(y, x, "    |    |");
+    mvprintw(y+1, x, "    |    |");
+    mvprintw(y+2, x, "----+----+----");
+    mvprintw(y+3, x, "    |    |");
+    mvprintw(y+4, x, "    |    |");
+    mvprintw(y+5, x, "----+----+----");
+    mvprintw(y+6, x, "    |    |");
+    mvprintw(y+7, x, "    |    |");
+}
+
+static void print_x(int y, int x) {
+
+    mvprintw(y, x, "\\/");
+    mvprintw(y+1, x,"/\\");
+}
+
+static void print_o(int y, int x) {
+
+    mvprintw(y, x, "/\\");
+    mvprintw(y+1, x, "\\/");
+}
+
+/* y: 1 -> +0  x: 1 -> +1
+ *    2 -> +3     2 -> +6
+ *    3 -> +6     3 -> +11 */
+static int remap_y(int y) {
+
+    if (y == 1) {
+        return 0;
+    } else if (y == 2) {
+        return 3;
+    } else {
+        return 6;
+    }
+}
+
+static int remap_x(int x) {
+
+    if (x == 1) {
+        return 1;
+    } else if (x == 2) {
+        return 6;
+    } else {
+        return 11;
+    }
+}