Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zamiana statycznych tablic na std::vector (#30) #37

Merged
merged 2 commits into from
Oct 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ctime> /* time */
#include <dirent.h>
#include <fstream>
#include <vector>

// code from https://gist.github.com/Nircek
// under MIT license
Expand Down Expand Up @@ -45,8 +46,9 @@ typedef struct{int x; int y;} COORDS;
string mapy="maps"; //folder, w którym są mapy
string file_name; //ścieżka do mapy
string prev_file; //nazwa poprzedniej mapy
#define SIZE 100
string mapa[SIZE], bufor[SIZE];
size_t SIZE=0;
string *bufor = NULL;
vector<string> mapa;
char user_ch='X', end_ch='O';
COORDS player_coords;
COORDS end_coords;
Expand All @@ -61,28 +63,29 @@ if(file.good()==false)
throw "File does not exist";

}
mapa.clear();
SIZE = 0;
string line;
size_t i=0;
while (getline(file, line))
{
mapa[i] = line;
i++;
while (getline(file, line)) {
mapa.push_back(line);
++SIZE;
}

file.close();
}

bool isExist(COORDS p) { // sprawdza czy dane pole jest na mapie
if(p.y>=SIZE)return false;
return mapa[p.y].size()>=p.x;
}

bool isWall(COORDS c) // czy na podanych kordach nie ma spacji
{
if(!isExist(c))return true;
if (mapa[c.y][c.x] == ' ') //sprawdza czy space
return false; //zwraca, czy jest, czy nie
else return true;
}

bool isExist(COORDS p) { // sprawdza czy dane pole jest na mapie
if(p.y>=SIZE)return false;
return mapa[p.y].size()>=p.x;
}
COORDS randomCoords(bool notWall=true) {
COORDS c;
do {
Expand Down Expand Up @@ -122,6 +125,8 @@ char drawOnBufor(COORDS C, char c) { // narysuj na x i y znak c i zwróć poprze
return oc;
}
void refreshBufor() { // załaduj mapę do bufora i nanieś na nie usera i wyjście
if(!bufor) delete[] bufor;
bufor = new string[SIZE];
for(size_t i=0; i<SIZE; ++i)
bufor[i] = mapa[i];
drawOnBufor(player_coords, user_ch);
Expand Down