This is a school project that I'm currently working on. I have a problem with returning the multidimensional array Map[25][60]
. The method get_map()
has to return the whole map so I can use it as a parameter in the function move_left()
.
// ProjectX v3.0.cpp : Defines the entry point for the console application.
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <thread>
#include <fstream>
using namespace std;
class wallz
{
int i;
int j;
public:
wallz();
~wallz();
void set_i(int def_i);
void set_j(int def_j);
int get_i();
int get_j();
void move_left(int Map[25][60], wallz wallz_temp);
};
wallz::wallz()
{
}
wallz::~wallz()
{
}
void wallz::set_i(int def_i)
{
i = def_i;
}
void wallz::set_j(int def_j)
{
j = def_j;
}
int wallz::get_i()
{
return i;
}
int wallz::get_j()
{
return j;
}
void wallz::move_left(int Map[25][60], wallz wallz_temp)
{
int x = 0;
while (x == 0)
{
if (Map[wallz_temp.get_i()][wallz_temp.get_j()] == 11)
{
Map[wallz_temp.get_i()][wallz_temp.get_j()] = 0;
Map[wallz_temp.get_i() - 1][wallz_temp.get_j()] = 11;
}
if (Map[wallz_temp.get_i() - 1][wallz_temp.get_j()] == 11)
{
Map[wallz_temp.get_i()][wallz_temp.get_j()] = 11;
Map[wallz_temp.get_i() - 1][wallz_temp.get_j()] = 0;
}
}
}
class map
{
wallz wallz_mass[30];
int char_X;
int char_Y;
int i;
int j;
int Map[25][60];
public:
map(int Map[25][60]);
~map();
void map_print();
void controlz();
int get_map();
wallz get_wallz(int h);
void map1_set_wallz();
void map2_set_wallz();
void map3_set_wallz();
void map4_set_wallz();
void map5_set_wallz();
void move_left();
void move_right();
void move_horizontal();
void move_up();
void move_down();
void move_vertical();
};
map::map(int m[25][60])
{
char_X = 1;
char_Y = 1;
for (int i = 0; i<25; i++)
for (int j = 0; j<60; j++)
Map[i][j] = m[i][j];
}
map::~map()
{
}
void map::map_print()
{
int MapCounter = 0;
for (int i = 0; i<25; i++)
{
for (int j = 0; j<60; j++)
{
if (MapCounter == 60)
{
cout << "" << endl;
MapCounter = 0;
}
if (i == char_X && j == char_Y)
{
cout << char(35);
}
else if (Map[i][j] == 1)
{
cout << char(186);//vertikalna liniq
}
else if (Map[i][j] == 0)
{
cout << " ";
}
else if (Map[i][j] == 2)//horizontalna liniq
{
cout << char(205);
}
else if (Map[i][j] == 3)
{
cout << char(200);//dolen lqv ugul
}
else if (Map[i][j] == 4)
{
cout << char(201);//goren lqv ugul
}
else if (Map[i][j] == 5)
{
cout << char(188);//dolen desen ugul
}
else if (Map[i][j] == 6)
{
cout << char(187);//goren desen ugul
}
else if (Map[i][j] == 7)
{
cout << char(204);//lqv vodoprovod
}
else if (Map[i][j] == 8)
{
cout << char(185);//desen vodoprovod
}
else if (Map[i][j] == 9)
{
cout << char(202);//goren vodoprovod
}
else if (Map[i][j] == 10)
{
cout << char(203);//desen vodoprovod
}
else if (Map[i][j] == 11)
{
cout << char(254); //
}
MapCounter++;
}
}
}
void map::controlz()
{
if (GetAsyncKeyState(VK_UP) != 0)
{
if (Map[char_X - 1][char_Y] == 0)
{
char_X--;
}
}
if (GetAsyncKeyState(VK_DOWN) != 0)
{
if (Map[char_X + 1][char_Y] == 0)
{
char_X++;
}
}
if (GetAsyncKeyState(VK_LEFT) != 0)
{
if (Map[char_X][char_Y - 1] == 0)
{
char_Y--;
}
}
if (GetAsyncKeyState(VK_RIGHT) != 0)
{
if (Map[char_X][char_Y + 1] == 0)
{
char_Y++;
}
}
}
int map::get_map()
{
return Map[25][60];
}
wallz map::get_wallz(int h)
{
return wallz_mass[h];
}
void map::map1_set_wallz()
{
wallz_mass[0].set_i(6);
wallz_mass[0].set_j(2);
}
void move_left(map map1)
{
map1.get_wallz(0).move_left(map1.get_map(), map1.get_wallz(0));
}
int main()
{
int x, y;
COORD ord;
ord.X = x = 0;
ord.Y = y = 0;
system("cls");
int Map[25][60] = {
4, 2, 6, 0, 0, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 0, 0, 0, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10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, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 7, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 9, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 9, 2, 2, 2, 2, 2, 2, 9, 2, 6, 2, 2, 2, 6, 0, 0, 0, 1,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
0, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 9, 2, 2, 2, 9, 2, 2, 2, 5,
};
map map1(Map);
bool stop = false;
while (stop == false)
{
map1.controlz();
map1.map_print();
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), ord);
}
thread first(move_left, map1);
first.join();
system("pause>nul");
return 0;
}