Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** EPITECH PROJECT, 2020
- ** navy
- ** File description:
- ** map
- */
- #include "../include/navy.h"
- #include "../include/util.h"
- void print_map(char *map)
- {
- int x = 0;
- my_putstr(" |");
- for (char i = 'A'; i <= 'H'; ++i) {
- my_putchar(i, 1);
- my_putchar(' ' - (22 * (i == 'H')), 1);
- }
- for (int i = 1; i <= 17; ++i)
- my_putchar('-' - (2 * (i == 2)), 1);
- my_putchar('\n', 1);
- for (int i = 1; i <= 8; ++i) {
- my_putchar(48 + i, 1);
- my_putchar('|', 1);
- for (int j = 1; j <= 8; ++j) {
- my_putchar(map[x], 1);
- my_putchar(' ' - (22 * (j == 8)), 1);
- ++x;
- }
- }
- }
- void print_maps(map_t *maps)
- {
- my_putstr("my positions:\n");
- print_map(maps->m);
- my_putstr("\nenemy's positions:\n");
- print_map(maps->e);
- my_putchar('\n', 1);
- }
- char *read_map_file(char *path)
- {
- }
- int fill_map(map_t *map, char *s)
- {
- int *in = malloc(sizeof(int) * 3);
- int x = 0;
- char *ln;
- while ((ln = get_line(s, x++)) != NULL) {
- if (ln[2] != ln[5] && ln[3] != ln[6])
- return (0);
- in[0] = ln[0] - '0';
- in[1] = ((ln[3] - 48) * 8) - (8 - (ln[2] - 64)) - 1;
- in[2] = ((ln[6] - 48) * 8) - (8 - (ln[5] - 64)) - 1;
- if (in[2] - in[1] > 7) {
- if (((in[2] - in[1]) / 8) + 1 != in[0])
- return (0);
- } else if (in[2] - in[1] + 1 != in[0])
- return (0);
- for (int i = in[1]; i <= in[2]; i += ((in[2] - in[1] > 7) * 7) + 1)
- if (map->m[i] == '.')
- map->m[i] = (char) (in[0] + '0');
- else
- return (0);
- free(ln);
- }
- return (1);
- }
- map_t *get_maps(char *path)
- {
- map_t *map = malloc(sizeof(map_t));
- char *s = "8:A1:H1\n2:B2:B3";
- map->m = malloc(sizeof(char) * 64);
- map->e = malloc(sizeof(char) * 64);
- for (int i = 0; i < 64; ++i)
- map->e[i] = '.';
- for (int i = 0; i < 64; ++i)
- map->m[i] = '.';
- if (fill_map(map, s) == 0)
- return (NULL);
- return (map);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement