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
|
#include <iostream>
#include <windows.h>
#include <conio.h>
#define xMAX 10
#define yMAX 10
using namespace std;
void mapcreation(char map[][xMAX])
{
for(int y=0; y<yMAX; y++)
{
for(int x=0; x<xMAX; x++)
{
if(x==(xMAX-1)) map[x][y] = '\0';
else map[x][y] = 'X';
}
}
}
char map2[10][20] = { "###################",
"#@ #",
"# #",
"# #",
"# #",
"# #",
"# #",
"###################" };
int main()
{
char map[yMAX][xMAX];
mapcreation(map);
// LOOP NO.1
for(int y = 0; y < yMAX; y++) /* this one works, prints the basic 10x10 array from mapcreation(),
BUT is very slow when working on a larger map */
{
for(int x = 0; x < xMAX; x++)
{
cout << map[x][y];
} cout << endl;
}
// LOOP NO.2
for(int y = 0; y < yMAX; y++) /* theoretically much faster map-printing loop using the same 10x10 array from mapcreation(),
supposed to print whole verse each loop, BUT does not work */
{
cout << map[y] << endl;
}
// LOOP NO.3
for(int y = 0; y < 10; y++) // THE SAME LOOP as in 2., WORKING, BUT using, not generated, premade char array
{
cout << map2[y] << endl;
}
getch();
return 0;
}
|