-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap_Editor.c
More file actions
182 lines (178 loc) · 5.3 KB
/
Map_Editor.c
File metadata and controls
182 lines (178 loc) · 5.3 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define endl getCursorXY(&x,&y);gotoxy(x-3,y+1);
#define color(f_c,b_c) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),f_c | b_c<<4);
#define ps printf(" ");
#define def_color SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x07);
extern const int source,split,wall,normal; // source: Blue split:Yellow wall: Gray normal:Ajori
extern int x,y,cell_num,walls;
extern const int width,height;
#include "mapeditor.h"
void show_box_end(char* s){
int i,j;
x=width * 3 + 2;
y=height *3 + 2;
gotoxy(x,y);
print(12,11,"%c",201);
for(i=0;i<50;i++)
print(12,11,"%c",205);
print(12,11,"%c",187);
for(i=0;i<7;i++){
gotoxy(x,++y);
print(12,11,"%c",186);
for(j=0;j<50;j++)
print(12,11," ");
print(12,11,"%c",186);
}
gotoxy(x,y++);
print(12,11,"%c",200);
for(i=0;i<50;i++)
print(12,11,"%c",205);
print(12,11,"%c",188);
y-=7;
gotoxy(x+4,y++);
print(12,11,s);
}
void save_map(block arr_map[height][width],char arr_map_type[height][width],char *s){
FILE *f=fopen(s,"wb");
if(f==NULL){
gotoxy(0,0);
print(12,11,"Can`t create file");
return;
}
int i,j;
fwrite(&width,sizeof(int),1,f);
fwrite(&height,sizeof(int),1,f);
for(j=height-1;j>=0;j--)
for(i=0;i<width;i++){
fwrite(&arr_map[j][i].energy,sizeof(int),1,f);
fwrite(&arr_map_type[j][i],sizeof(char),1,f);
}
}
void color_box(){
int i;
for(i=0;i<10;i++){
printf("%d: ",i);
print(0,i," \n");
}
for(i=10;i<16;i++){
printf("%d: ",i);
print(0,i," \n");
}
}
void create_map(){
int i=0,j,source,split,wall,normal;
enter_width_height:
system("cls");
print(2,0,"Please enter Width & Height:\n");
scanf("%d %d",&width,&height);
system("cls");
print(2,0,"Enter the Number of Source block\n");
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
scanf("%d",&source);
i+=source;
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
system("cls");
print(2,0,"Enter the Number of Split block\n");
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
scanf("%d",&split);
i+=split;
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
system("cls");
print(2,0,"Enter the Number of Wall block\n");
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
scanf("%d",&wall);
i+=wall;
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
system("cls");
print(2,0,"Enter the Number of Normal block\n");
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
scanf("%d",&normal);
i+=normal;
gotoxy(40,0);
print(2,0,"Block remaining:%d\n",width * height - i);
system("cls");
if( i!= width * height){
system("cls");
print(2,0,"Please enter the amounts correctly!!");Sleep(1000);
i=0;
goto enter_width_height;
}
//----------------------------ENTER POSITIONS----------------------------//
block arr_map[height][width];
char arr_map_type[height][width];
for(i=0;i<height;i++)
for(j=0;j<width;j++){
arr_map[i][j].energy=0;
arr_map[i][j].type=8;
}
print_map(arr_map);
int source_c,wall_c,split_c,normal_c,e;
clear_text();
print(0,3,"Now Set the color of blocks.\n");
color_box();
print(0,3,"Source:");
scanf("%d",&source_c);
print(0,3,"Split:");
scanf("%d",&split_c);
print(0,3,"Wall:");
scanf("%d",&wall_c);
print(0,3,"Normal:");
scanf("%d",&normal_c);
system("cls");
print_map(arr_map);
clear_text();
position p;
print(0,3,"Now select source blocks\n");
for(i=0;i<source;i++){
print(0,3,"%d-th block position: ",i+1);
scanf("%d%d",&p.h,&p.w);
print(0,3,"%d-th block energy: ",i+1);
scanf("%d",&e);
arr_map[height-1-p.h][p.w].type=source_c;
arr_map[height-1-p.h][p.w].energy=e;
arr_map_type[height-1-p.h][p.w]='1';
print_map(arr_map);
clear_text();
}
print(0,3,"Now select split blocks\n");
for(i=0;i<source;i++){
print(0,3,"%d-th block position: ",i+1);
scanf("%d%d",&p.h,&p.w);
arr_map[height-1-p.h][p.w].type=split_c;
arr_map_type[height-1-p.h][p.w]='2';
print_map(arr_map);
clear_text();
}
print(0,3,"Now select wall blocks\n");
for(i=0;i<source;i++){
print(0,3,"%d-th block position: ",i+1);
scanf("%d%d",&p.h,&p.w);
arr_map[height-1-p.h][p.w].type=wall_c;
arr_map_type[height-1-p.h][p.w]='3';
print_map(arr_map);
clear_text();
}
print(0,3,"Now select normal blocks\n");
for(i=0;i<source;i++){
print(0,3,"%d-th block position: ",i+1);
scanf("%d%d",&p.h,&p.w);
arr_map[height-1-p.h][p.w].type=normal_c;
arr_map_type[height-1-p.h][p.w]='4';
print_map(arr_map);
clear_text();
}
Sleep(500);
char *s;
s=show_text_box("Now choose a name for your map:\n");
save_map(arr_map,arr_map_type,s);
show_box_end("Congratulation!! you have created a map.");
}