fix more signed integer issues.
[Project_algorithmic_C.git] / lib / ui.c
index c75e3b01ca69f981a1544455fc6aaf51494968b3..da79cb3f317f6f0776b81d58ac77df43a31f1ae6 100644 (file)
--- a/lib/ui.c
+++ b/lib/ui.c
@@ -3,7 +3,7 @@
  *
  *       Filename:  ui.c
  *
- *    Description:  Routines to handle the user interface 
+ *    Description:  Routines to handle the user interface
  *
  *        Version:  1.0
  *        Created:  24/04/2017 16:41:15
@@ -19,8 +19,8 @@
 #include <string.h>
 
 #include "ui.h"
-#include "othello.h"
 #include "debug.h"
+#include "list.h"
 
 /* in all print routine, y and x are the coordinates of the first character of the shape
  * which can be a space ' ' */
@@ -56,6 +56,12 @@ void print_board(int y, int x) {
     mvprintw(y+25, x, " -----+----+----+----+----+----+----+-----");
 }
 
+static void set_default_colors() {
+
+    init_pair(1, COLOR_WHITE, COLOR_BLACK);
+    attron(COLOR_PAIR(1));
+}
+
 static void print_o(int y, int x, unsigned int type) {
 
     if (type == black) {
@@ -69,11 +75,10 @@ static void print_o(int y, int x, unsigned int type) {
     mvprintw(y, x, "/\\");
     mvprintw(y+1, x, "\\/");
     /* reset to default */
-    init_pair(1, COLOR_WHITE, COLOR_BLACK);
-    attron(COLOR_PAIR(1));
+    set_default_colors();
 }
 
-/* will be used for pawn placement hints */
+/* used for pawn placement hints */
 static void print_x(int y, int x, unsigned int type) {
 
     if (type == hint_allowed) {
@@ -86,14 +91,13 @@ static void print_x(int y, int x, unsigned int type) {
     mvprintw(y, x, "\\/");
     mvprintw(y+1, x,"/\\");
     /* reset to default */
-    init_pair(1, COLOR_WHITE, COLOR_BLACK);
-    attron(COLOR_PAIR(1));
+    set_default_colors();
 }
 
 /* y = 1: y -> 0      x = 1: 1 -> 1
  * y > 1: y -> y + 3  x > 1: x -> x + 5 */
 static int remap_y(int y) {
-   
+
     if (y == 1) {
         return 2;
     } else if (y > 1 && y <= board_size) {
@@ -125,8 +129,16 @@ void print_pawns(int base_y, int base_x, unsigned int pawn_array[board_size][boa
     }
 }
 
-int map_col_letter_to_int(char c) {
-    
+void print_shots_list(int base_y, int base_x, struct shots_list_s* shots_list) {
+    struct shots_list_s* list_counter;
+
+    list_for_each_entry(list_counter, &shots_list->list, list) {
+        print_x(base_y + remap_y(list_counter->y), base_x + remap_x(list_counter->x), list_counter->type);
+    }
+}
+
+int map_col_letter_to_index(char c) {
+
     if (c == 'a' || c == 'A') {
         return 1;
     } else if (c == 'b' || c == 'B') {
@@ -148,8 +160,32 @@ int map_col_letter_to_int(char c) {
     }
 }
 
+/* return capital letters */
+char map_col_index_to_letter(int index) {
+
+    if (index == 1) {
+        return 'A';
+    } else if (index == 2) {
+        return 'B';
+    } else if (index == 3) {
+        return 'C';
+    } else if (index == 4) {
+        return 'D';
+    } else if (index == 5) {
+        return 'E';
+    } else if (index == 6) {
+        return 'F';
+    } else if (index == 7) {
+        return 'G';
+    } else if (index == 9) {
+        return 'H';
+    } else {
+        return -1;
+    }
+}
+
 int prompt_values(WINDOW* windows, int base_y, int base_x, const char* msg, int* y, char* x) {
     mvwprintw(windows, base_y, base_x, "%s\n", msg);
-    int retVal = mvwscanw(windows, base_y + 1, base_x + strlen(msg)/2, "%d%c", y, x);
-    return (retVal == 1) ? 0 : 1;
+    int retval = mvwscanw(windows, base_y + 1, base_x + strlen(msg)/2, "%d%c", y, x);
+    return (retval == 1) ? 0 : 1;
 }