Browse Source

first commit

Aaro Saila 2 years ago
commit
69ca98ffb5
4 changed files with 98 additions and 0 deletions
  1. 8 0
      global_macros.h
  2. 70 0
      main.c
  3. 12 0
      test_utils/test_utils.c
  4. 8 0
      test_utils/test_utils.h

+ 8 - 0
global_macros.h

@@ -0,0 +1,8 @@
+#ifndef GLOBAL_MACROS_H
+#define GLOBAL_MACROS_H
+
+#define BUF_SIZE 256
+#define BRD_SIZE_X 15
+#define BRD_SIZE_Y 30
+
+#endif // GLOBAL_MACROS_H

+ 70 - 0
main.c

@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <termios.h>
+#include <stdlib.h>
+#include "./global_macros.h"
+
+//TEMP
+#include "./test_utils/test_utils.h"
+
+int main() {
+  // Termios setup
+  struct termios attr;
+
+  tcgetattr(STDIN_FILENO, &attr);
+
+  const struct termios ATTR_ORIG = attr;
+
+  attr.c_lflag &= ~(ECHO | ICANON);
+  attr.c_cc[VMIN] = 0;
+  attr.c_cc[VTIME] = 0;
+
+  tcsetattr(STDIN_FILENO, 0,&attr);
+
+  // Game board setup
+  char board[BRD_SIZE_X][BRD_SIZE_Y];
+
+  for (int i = 0; i < BRD_SIZE_X; i++) {
+    for (int j = 0; j < BRD_SIZE_Y; j++) {
+      if (
+          (i > 0 && i < BRD_SIZE_X - 1)
+          && (j == 0 || j == BRD_SIZE_Y - 1)
+          ) {
+        board[i][j] = '|';
+      } else if (
+          (i == 0 || i == BRD_SIZE_X - 1)
+          && (j > 0 && j < BRD_SIZE_Y - 1)
+        ) {
+        board[i][j] = '-';
+      } else {
+        board[i][j] = ' ';   
+      }
+    }
+  }
+
+  board[0][0] = '+';
+  board[BRD_SIZE_X - 1][0] = '+';
+  board[0][BRD_SIZE_Y - 1] = '+';
+  board[BRD_SIZE_X - 1][BRD_SIZE_Y - 1] = '+';
+
+  printBoard(board);
+
+  /*
+  while (1) {
+    fflush(stdout);
+    char buf[BUF_SIZE] = {0};
+    read(STDIN_FILENO, buf, 2);
+
+    if (buf[0] == 0)
+      continue;
+
+    write(STDOUT_FILENO, buf, 2);
+    //printf("\n");
+  }
+  */
+
+  // Termios reset
+  tcsetattr(STDIN_FILENO, 0,&ATTR_ORIG);
+
+  return 0;
+}

+ 12 - 0
test_utils/test_utils.c

@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "test_utils.h"
+#include "../global_macros.h"
+
+void printBoard(char board[BRD_SIZE_X][BRD_SIZE_Y]) {
+  for (int i = 0; i < BRD_SIZE_X; i++) {
+    for (int j = 0; j < BRD_SIZE_Y; j++) {
+      printf("%c", board[i][j]);
+    }
+    printf("\n");
+  }
+}

+ 8 - 0
test_utils/test_utils.h

@@ -0,0 +1,8 @@
+#ifndef TEST_UTILS_H
+#define TEST_UTILS_H
+
+#include "../global_macros.h"
+
+void printBoard(char board[BRD_SIZE_X][BRD_SIZE_Y]);
+
+#endif // TEST_UTILS_H