Properly implement the validation of a shot and reverse or flip the
[Project_algorithmic_C.git] / lib / ui.c
index ae14d1df861be54fe1d6160ecef48c86d660d3f2..80a188b79c0a56a00b1bcd79bba580b9fe8cd6e5 100644 (file)
--- a/lib/ui.c
+++ b/lib/ui.c
@@ -120,8 +120,8 @@ static int remap_x(int x) {
 
 void print_pawns(int base_y, int base_x, unsigned int pawn_array[board_size][board_size]) {
 
-    for (unsigned int i = 1; i <= board_size; i++) {
-        for (unsigned int j = 1; j <= board_size; j++) {
+    for (int i = 1; i <= board_size; i++) {
+        for (int j = 1; j <= board_size; j++) {
             if (!is_box_type(i, j, pawn_array, empty)) {
                 print_o(base_y + remap_y(i), base_x + remap_x(j), get_box_value(i, j, pawn_array));
             }
@@ -129,7 +129,7 @@ void print_pawns(int base_y, int base_x, unsigned int pawn_array[board_size][boa
     }
 }
 
-int map_col_letter_to_int(char c) {
+int map_col_letter_to_index(char c) {
     
     if (c == 'a' || c == 'A') {
         return 1;
@@ -152,8 +152,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;
 }