TP 13 exo2: Add the code structure and some basic displaying routines for the tic...
[TD_C.git] / TP_13 / exo2 / lib / display.c
diff --git a/TP_13/exo2/lib/display.c b/TP_13/exo2/lib/display.c
new file mode 100644 (file)
index 0000000..22deb96
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * =====================================================================================
+ *
+ *       Filename:  display.c
+ *
+ *    Description:  Routines to handle the display 
+ *
+ *        Version:  1.0
+ *        Created:  15/03/2017 20:06:11
+ *       Revision:  none
+ *       Compiler:  gcc
+ *
+ *         Author:  Jerome Benoit (fraggle), jerome.benoit@piment-noir.org
+ *   Organization:  Piment Noir
+ *
+ * =====================================================================================
+ */
+
+#include <ncurses.h>
+
+/* in all print routine, y and x are the coordinates of the first character of the shape
+ * which can be a space ' ' */
+
+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, "    |    |");
+}
+
+/* there's only nine valid (y, x) 2-uplets for this two shapes 
+ * that are : - base_y, base_x +1
+ *            - base_y, base_x + 6
+ *            - base_y, base_x + 11 
+ *            - base_y + 3, base_x + 1 
+ *            - base_y + 6, base_x + 1 
+ *            - base_y + 3, base_x + 6 
+ *            - base_y + 3, base_x + 11 
+ *            - base_y + 6, base_x + 6 
+ *            - base_y + 6, base_x + 11 
+ * The added y value can be {0, 3, 6} 
+ * The added x value can be {1, 6, 11} */
+
+void print_x(int y, int x) {
+    mvprintw(y, x, "\\/");
+    mvprintw(y+1, x,"/\\");
+}
+
+void print_o(int y, int x) {
+    mvprintw(y, x, "/\\");
+    mvprintw(y+1, x, "\\/");
+}