-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.c
89 lines (80 loc) · 1.89 KB
/
output.c
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
#include "output.h"
void debugOutput(output_t o)
{
printf("name: %s\n", o.name);
printf("time: %d\n", o.time);
printf("diaReq: %d\n", o.diaReq);
printf("row, col: %d,%d\n", o.row, o.col);
}
void initArray(output_t *o)
{
o->arr = (char **)malloc(o->row * sizeof(char *));
for (int i = 0; i < o->row; i++)
{
o->arr[i] = (char *)malloc(o->col * sizeof(char));
}
for (int row = 0; row < o->row; row++)
{
for (int col = 0; col < o->col; col++)
{
if (row == 0 || row == o->row - 1)
{
o->arr[row][col] = borderTile;
}
else if (col == 0 || col == o->col - 1)
{
o->arr[row][col] = borderTile;
}
else
{
o->arr[row][col] = emptyTile;
}
}
}
}
void debugArray(output_t o)
{
for (int row = 0; row < o.row; row++)
{
for (int col = 0; col < o.col; col++)
{
printf("%c", o.arr[row][col]);
}
printf("\n");
}
}
void exportOutput(output_t o, char *fileName)
{
FILE *fp = fopen(fileName, "w");
if (fp == NULL)
{
printf("fileio error!");
return;
}
fprintf(fp, "%s\n", o.name);
fprintf(fp, "%d %d\n", o.row, o.col);
for (int row = 0; row < o.row; row++)
{
for (int col = 0; col < o.col; col++)
{
if (o.arr[row][col] == playerTile)
{
fprintf(fp, "%d %d\n", row, col);
break;
}
}
}
fprintf(fp, "%d\n", o.diaReq);
fprintf(fp, "%d %d\n", o.time, 1400);
fprintf(fp, "%c\n", '-');
for (int row = 0; row < o.row; row++)
{
for (int col = 0; col < o.col; col++)
{
fprintf(fp, "%c", o.arr[row][col]);
}
fprintf(fp, "\n");
}
fclose(fp);
fp = NULL;
}