Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.9 kB
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

#include "create.h"

void displayRobot(int robot) {
  switch (robot) {
  case 1:
    printf("\x1B[31m ⛟ ");
    break;
  case 2:
    printf("\x1B[32m ⛟ ");
    break;
  case 3:
    printf("\x1B[33m ⛟ ");
    break;
  case 4:
    printf("\x1B[34m ⛟ ");
    break;
  default:
    break;
  }
}

void displayColor(int id) {
  switch (id) {
  case 1:
    printf("\x1B[31m");
    break;
  case 2:
    printf("\x1B[32m");
    break;
  case 3:
    printf("\x1B[33m");
    break;
  case 4:
    printf("\x1B[34m");
    break;
  default:
    printf("\x1B[37m");
    break;
  }
}

void displayTarget(Box **grid, int x, int y, int target) {
  displayColor(grid[x][y].robot.id);
  switch (target) {
  case 1:
    printf(" ⑴ ");
    break;
  case 2:
    printf(" ⑵ ");
    break;
  case 3:
    printf(" ⑶ ");
    break;
  case 4:
    printf(" ⑷ ");
    break;
  case 5:
    printf(" ⑸ ");
    break;
  case 6:
    printf(" ⑹ ");
    break;
  case 7:
    printf(" ⑺ ");
    break;
  case 8:
    printf(" ⑻ ");
    break;
  case 9:
    printf(" ⑼ ");
    break;
  case 10:
    printf(" ⑽ ");
    break;
  case 11:
    printf(" ⑾ ");
    break;
  case 12:
    printf(" ⑿ ");
    break;
  case 13:
    printf(" ⒀ ");
    break;
  case 14:
    printf(" ⒁ ");
    break;
  case 15:
    printf(" ⒂ ");
    break;
  case 16:
    printf(" ⒃ ");
    break;
  case 17:
    printf(" ⒄ ");
    break;
  case 18:
    printf(" ⒅ ");
    break;
  default:
    break;
  }
}

void displayWall(Box **grid, int x, int y) {
  if (grid[x][y].wall.type == 1) {
    switch (grid[x][y].robot.id) {
    case 1:
      printf("\x1B[31m▁▁▁");
      break;
    case 2:
      printf("\x1B[32m▁▁▁");
      break;
    case 3:
      printf("\x1B[33m▁▁▁");
      break;
    case 4:
      printf("\x1B[34m▁▁▁");
      break;
    default:
      printf("\x1B[37m▁▁▁");
      break;
    }
  }
  if (grid[x][y].wall.type == 2) {
    switch (grid[x][y].robot.id) {
    case 1:
      printf("\x1B[31m ▏ ");
      break;
    case 2:
      printf("\x1B[32m ▏ ");
      break;
    case 3:
      printf("\x1B[33m ▏ ");
      break;
    case 4:
      printf("\x1B[34m ▏ ");
      break;
    default:
      printf("\x1B[37m ▏ ");
      break;
    }
  }
  if (grid[x][y].wall.type == 3) {
    switch (grid[x][y].robot.id) {
    case 1:
      printf("\x1B[31m ▕ ");
      break;
    case 2:
      printf("\x1B[32m ▕ ");
      break;
    case 3:
      printf("\x1B[33m ▕ ");
      break;
    case 4:
      printf("\x1B[34m ▕ ");
      break;
    default:
      printf("\x1B[37m ▕ ");
      break;
    }
  }
  if (grid[x][y].wall.type == 4) {
    switch (grid[x][y].robot.id) {
    case 1:
      printf("\x1B[31m▔▔▔");
      break;
    case 2:
      printf("\x1B[32m▔▔▔");
      break;
    case 3:
      printf("\x1B[33m▔▔▔");
      break;
    case 4:
      printf("\x1B[34m▔▔▔");
      break;
    default:
      printf("\x1B[37m▔▔▔");
      break;
    }
  }
}

void displayGrid(Box **grid, int size) {

  if (grid == NULL) {
    printf("Allocation failed");
    exit(11);
  }

  int targetCount = 1;
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      if (grid[i][j].wall.type != 0) {
        displayWall(grid, i, j);
      } else if (grid[i][j].wall.type == 2) {
        printf("\x1B[37m ▏ ");
      } else if (grid[i][j].wall.type == 3) {
        printf("\x1B[37m ▕ ");
      } else if (grid[i][j].wall.type == 4) {
        printf("\x1B[37m▔▔▔");
      } else if (grid[i][j].wall.type == 0 && grid[i][j].robot.id == 0 &&
                 grid[i][j].target == 0) {
        printf("\x1B[30m - ");
      } else if (grid[i][j].target != 0) {
        displayTarget(grid, i, j, targetCount);
        targetCount++;
      } else {
        displayRobot(grid[i][j].robot.id);
      }
    }
    printf("\n");
  }
}
Leave a Comment