-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHydresAdvDisplay.c
More file actions
138 lines (116 loc) · 4.19 KB
/
Copy pathHydresAdvDisplay.c
File metadata and controls
138 lines (116 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "HydresAdvDisplay.h"
void fieldCDisplay(const field* terrain, const int s_posx, const int e_posx, const int s_posy, const int e_posy)
{
if ((s_posx < 0) || (s_posy < 0) || (e_posx >= terrain->fsize_x) || (e_posy >= terrain->fsize_y))
{
fprintf(stdout,"Error: fieldCDisplay miscalled, either:\n");
fprintf(stdout,"s_posx %d < 0\n",s_posx);
fprintf(stdout,"s_posy %d < 0\n",s_posy);
fprintf(stdout,"e_posx %d >= terrain->fsize_x %d\n",e_posx,terrain->fsize_x);
fprintf(stdout,"e_posy %d >= terrain->fsize_y %d\n",e_posy,terrain->fsize_y);
return;
}
int i, j;
char* display = NULL;
for (j = s_posy ; j < e_posy ; j++)
{
display = malloc(sizeof(char) * (e_posx - s_posx + 1));
for (i = s_posx ; i < e_posx ; i++)
{
//putc(terrain->fbody[i][j].caractere,stdout);
display[i] = terrain->fbody[s_posx + i][j].caractere;
}
display[e_posx - s_posx] = '\0';
fputs(display,stdout);
putc('\n',stdout);
free(display);
}
/*
for (j = s_posy ; j <= e_posy ; j++)
{
for (i = s_posx ; i <= e_posx ; i++)
{
putc(terrain->fbody[i][j].caractere,stdout);
}
putc('\n',stdout);
}
*/
}
void fieldACDisplay(const field* terrain, const int s_posx, const int e_posx, const int s_posy, const int e_posy)
{
if ((s_posx < 0) || (s_posy < 0) || (e_posx >= terrain->fsize_x) || (e_posy >= terrain->fsize_y))
{
fprintf(stdout,"Error: fieldACDisplay miscalled, either:\n");
fprintf(stdout,"s_posx %d < 0\n",s_posx);
fprintf(stdout,"s_posy %d < 0\n",s_posy);
fprintf(stdout,"e_posx %d >= terrain->fsize_x %d\n",e_posx,terrain->fsize_x);
fprintf(stdout,"e_posy %d >= terrain->fsize_y %d\n",e_posy,terrain->fsize_y);
return;
}
HANDLE consoleSc = GetStdHandle(STD_OUTPUT_HANDLE);
if(consoleSc == INVALID_HANDLE_VALUE)
{
fprintf(stdout,"Error: GetStdHandle fail, screen displayed will be stripped of color\n");
fieldCDisplay(terrain, s_posx, e_posx, s_posy, e_posy);
}
int curCol = terrain->fbody[s_posx][s_posy].color, i, j, k = 0;
char* curStr = malloc(sizeof(char) * (4 * (e_posx - s_posx) + 2));
SetConsoleTextAttribute(consoleSc, curCol);
for (j = s_posy ; j <= e_posy ; j++)
{
for (i = s_posx ; i <= e_posx ; i++)
{
if((terrain->fbody[i][j].color != curCol) && (k != 0))
{
curStr[k] = '\0';
fputs(curStr,stdout);
free(curStr);
curStr = NULL;
k = 0;
curCol = terrain->fbody[i][j].color;
SetConsoleTextAttribute(consoleSc, curCol);
curStr = malloc(sizeof(char) * 4 * (e_posx - s_posx + 2));
}
curStr[k] = terrain->fbody[i][j].caractere;
k++;
if (k >= 4 * (e_posx - s_posx))
{
//curStr = realloc(curStr,sizeof(char) * (4 * (e_posx - s_posx + 3)));
curStr[k] = '\0';
fputs(curStr, stdout);
free(curStr);
curStr = NULL;
k = 0;
curCol = terrain->fbody[i][j].color;
SetConsoleTextAttribute(consoleSc, curCol);
curStr = malloc(sizeof(char) * 4 * (e_posx - s_posx + 2));
}
}
curStr[k] = '\n';
k++;
}
if (k != 0)
{
curStr[k] = '\0';
fputs(curStr, stdout);
}
if (!curStr)
free(curStr);
printf("advDisplay successfully finished.\n");
/*
int i, j;
for (j = s_posy ; j <= e_posy ; j++)
{
for (i = s_posx ; i <= e_posx ; i++)
{
SetConsoleTextAttribute(consoleSc, terrain->fbody[i][j].color);
putc(terrain->fbody[i][j].caractere,stdout);
}
putc('\n',stdout);
}
*/
}
void fieldADisplay(const field* terrain)
{
fieldACDisplay(terrain, 0, terrain->fsize_x - 1, 0, terrain->fsize_y - 1);
}