diff --git a/w/w.c b/w/w.c index 6efd8bb..950b301 100644 --- a/w/w.c +++ b/w/w.c @@ -18,16 +18,16 @@ char pov[3][3]; typedef struct { int x; - int y; + int y; char orientation; } Location; typedef struct { - char name[10]; + char name[10]; Location location; -} GameState; +} Gamestate; -GameState gamestate; +Gamestate gamestate; void drawmap() { @@ -42,21 +42,21 @@ void drawmap() void loadstate() { gamestate.name[0] = '\0'; - FILE* file = fopen(statepath, "r+"); - if (file) - { - fread(&gamestate, sizeof(GameState), 1, file); + FILE* file = fopen(statepath, "r+"); + if (file) + { + fread(&gamestate, sizeof(Gamestate), 1, file); fclose(file); - } + } } void savestate() { - FILE* file = fopen(statepath, "w"); + FILE* file = fopen(statepath, "w"); - if (file) { - fwrite(&gamestate, sizeof(GameState), 1, file); - } + if (file) { + fwrite(&gamestate, sizeof(Gamestate), 1, file); + } fclose(file); } @@ -204,6 +204,7 @@ void init() gamestate.location.y = 1; gamestate.location.orientation = 'n'; } + updatepov(); } @@ -239,6 +240,143 @@ char replacechar(char in, int y) return in; } +void draw2() +{ + char screen[10][10]; + for (int i = 0; i < 10; i++) + { + memset(screen[i], ' ', 10); + } + + if (pov[2][0] != ' ') + { + // wall on the left + screen[0][0] = '\\'; + screen[1][1] = '\\'; + screen[9][0] = '/'; + screen[8][1] = '/'; + } + else + { + screen[1][0] = '_'; + screen[1][1] = '_'; + + screen[7][0] = '_'; + screen[7][1] = '_'; + + screen[2][1] = '|'; + screen[3][1] = '|'; + screen[4][1] = '|'; + screen[5][1] = '|'; + screen[6][1] = '|'; + screen[7][1] = '|'; + } + + if (pov[2][2] != ' ') + { + // wall on the right + screen[0][9] = '/'; + screen[1][8] = '/'; + screen[9][9] = '\\'; + screen[8][8] = '\\'; + } + else + { + screen[1][9] = '_'; + screen[1][8] = '_'; + + screen[7][9] = '_'; + screen[7][8] = '_'; + + screen[2][8] = '|'; + screen[3][8] = '|'; + screen[4][8] = '|'; + screen[5][8] = '|'; + screen[6][8] = '|'; + screen[7][8] = '|'; + } + + if (pov[1][1] == ' ') + { + // front is free + screen[3][4] = '_'; + screen[3][5] = '_'; + screen[5][4] = '_'; + screen[5][5] = '_'; + + if (pov[0][0] != ' ') + { + screen[2][2] = '\\'; + screen[3][3] = '\\'; + screen[4][3] = '|'; + screen[5][3] = '|'; + screen[7][2] = '/'; + screen[6][3] = '/'; + } + + if (pov[0][2] != ' ') + { + screen[3][6] = '/'; + screen[2][7] = '/'; + screen[4][6] = '|'; + screen[5][6] = '|'; + screen[6][6] = '\\'; + screen[7][7] = '\\'; + } + else + { + screen[2][8] = '|'; + screen[3][8] = '|'; + screen[4][8] = '|'; + screen[5][8] = '|'; + screen[6][8] = '|'; + screen[7][8] = '|'; + + screen[3][6] = '_'; + screen[3][7] = '_'; + screen[5][6] = '_'; + screen[5][7] = '_'; + } + } + else + { + // front is blocked + for (int i = 2; i < 8; i++) + { + screen[1][i] = '_'; + screen[7][i] = '_'; + } + + if (pov[2][0] != ' ') + { + // wall on the left + for (int i = 2; i < 8; i++) screen[i][1] = '|'; + } + + if (pov[2][2] != ' ') + { + // wall on the right + for (int i = 2; i < 8; i++) screen[i][8] = '|'; + } + else + { + for (int i = 8; i < 10; i++) + { + screen[1][i] = '_'; + screen[7][i] = '_'; + } + } + } + + for (int i = 0; i < 10; i++) + { + for (int j = 0; j < 10; j++) + { + printf("%c", screen[i][j]); + } + printf("\n"); + } +} void draw() { @@ -248,6 +386,10 @@ void draw() #else system("clear"); #endif + + draw2(); + + printf("\n\n\n"); printf(" o=======o\n"); @@ -278,6 +420,8 @@ void draw() } + + int main() { init();