-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluca_formatted.cc
More file actions
308 lines (252 loc) · 5.97 KB
/
luca_formatted.cc
File metadata and controls
308 lines (252 loc) · 5.97 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
* Nome programma: ...
*/
//librerie
#include <iostream>
#include <string.h>
#include <fstream>
#include <windows.h>
#include <conio.h>
using namespace std;
char saveDir[] = "save.txt";
// int altChunk = 70;
const int larg = 118;
const int alt = 70*3;
bool debug = true;
bool init = false;
int x = 1, y = 1;
string key;
string icon = "*";
string wall = "#";
string land = " ";
string keyParla = "e";
int posTxtx = 0, posTxty = alt + 1;
string mappa[larg+1][alt+1];
int main();
void gotoxy(int x, int y);
void mv();
void printStatic();
void printDinamic();
void coordPos();
void anteprima();
void print(int thisx, int thisy, string tile = "");
void stringMappa();
void save();
void load();
void parla(int posx, int posy, string type, string frase = "", int txtx = posTxtx, int txty = posTxty, string keyp=keyParla);
void draw(int firstx, int firsty, int secondx = -1, int secondy = -1, string type = wall);
/****************
* Funzione main()
*****************/
int main()
{
//load();
stringMappa();
mv();
anteprima();
return 0;
}
/******************************
* mv():
* gestisce il movimento del personaggio
* con i tasti
* W, S, D, A. Tasto 0 per uscire
****************************/
void mv()
{
bool running = true;
bool scia = false;
printStatic();
do {
printDinamic();
/*#################################*/
save();
if((key=="w")||(key=="W"))
gotoxy(larg,y-10);
if((key=="s")||(key=="S"))
gotoxy(larg,y+10);
key=getch();
/*#################################*/
//MOVIMENTO
if((mappa[x][y-1]==land))
if((key=="w")||(key=="W"))
y--;
if((mappa[x][y+1]==land))
if((key=="s")||(key=="S"))
y++;
if((mappa[x+1][y]==land))
if((key=="d")||(key=="D"))
x++;
if((mappa[x-1][y]==land))
if((key=="a")||(key=="A"))
x--;
//TASTI
if(key=="0")
running = false;
//POSIZIONA PERSONA
print(x,y,icon);
//ANTI SCIA
if(!scia)
{
if(mappa[x+1][y]==icon)
print(x+1,y,land);
if(mappa[x-1][y]==icon)
print(x-1,y,land);
if(mappa[x][y+1]==icon)
print(x,y+1,land);
if(mappa[x][y-1]==icon)
print(x,y-1,land);
}
// coordPos();
} while(running); //fine ciclo infinito do while(), 0 per uscire
} //fine funzione mv()
/******************************
* load():
* carica il file di caratteri
* che funge da mappa
*******************************/
void load()
{
int riempimento = 0;
int ry=0;
string i;
ifstream file (saveDir);
if(file)
{
while(!file.eof())
{
file >> i;
if(i=="ì")
i=" ";
mappa[riempimento][ry] = i;
if(riempimento<=larg)
riempimento++;
else
{
if(ry<=alt)
ry++;
}
} //fine while
/* for(int i=0;i<=larg;i++)
{
for(int j=0;j<=alt;j++)
{
file >> mappa[j][i];
riempimento++;
}
}*/
} //fine if(!file)
anteprima();
file.close();
getch();
} //fine funzione load()
void stringMappa()
{
for(int i=0;i<=larg;i++)
{
for(int j=0;j<=alt;j++)
{
print(i,j,land);
}
}
}
void printDinamic()
{
// posTxtx = 0, posTxty ;
parla(11,11,"O","Grande Cerchio: Salve viandante!");
parla(12,3,"y"," ");
if(!init)
init = true;
} //fine printDinamico()
void printStatic()
{
draw(0,0,larg,0,wall); //SOPRA
draw(0,0,0,alt,wall); //SINIATRA
draw(larg,0,larg,alt,wall); //DESTRA
draw(0,alt,larg,alt,wall); //SOTTO
draw(3,3,10,10,".");
} //fine printStatic()
void coordPos()
{
gotoxy(110,29); cout << "\t\t";
gotoxy(110,29); cout << "(" << x << ";" << y << ")";
} //fine coordPos()
void print(int thisx, int thisy, string tile)
{
if((tile!=land)||(mappa[thisx][thisy]==icon))
{
gotoxy(thisx,thisy);
cout << tile;
}
mappa[thisx][thisy] = tile;
} //fine print()
void save()
{
ofstream file (saveDir);
for(int i=0;i<alt+1;i++)
{
for(int j=0;j<larg+1;j++)
{
file << mappa[j][i];
}
file << endl;
}
file.close();
} //fine save()
void parla(int posx, int posy, string type, string frase, int txtx, int txty, string keyp)
{
if(!init)
print(posx,posy,type);
if((((x==posx-1)&&(y==posy))||((x==posx+1)&&(y==posy))||((x==posx)&&(y==posy+1))||((x==posx)&&(y==posy-1)))&&(key==keyp))
{
gotoxy(txtx,txty); cout << frase;
getch();
gotoxy(txtx,txty); cout << "\t\t\t\t\t\t\t\t";
}
} //fine parla()
void draw(int firstx, int firsty, int secondx, int secondy, string type)
{
int l, h;
if((secondx>=0)&&(secondy>=0))
{
l = secondx - firstx;
h = secondy - firsty;
}
else
{
secondx = firstx + 1;
secondy = firsty + 1;
l = 1;
h = 1;
}
for(int i=firstx;i<=firstx+l;i++)
{
for(int j=firsty;j<=firsty+h;j++)
{
print(i,j,type);
}
}
} //fine draw()
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
} //fine gotoxy()
void anteprima()
{
system("cls");
gotoxy(0,0);
for(int i=0;i<alt+1;i++)
{
for(int j=0;j<larg+1;j++)
{
cout << mappa[j][i];
}
cout << endl;
}
print(0,alt+1,"SALVATO!");
getch();
} //fine anteprima
//fine programma