Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <conio.h>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class Mapa
- {
- vector<char> linia;
- vector<vector<char> > calaMapa;
- int maxMapX, maxMapY, startoweX, startoweY;
- public:
- Mapa(string nazwaMapy);
- void setPunktNaMapie(char znak, int oX, int oY);
- void wyswietlMape();
- int getStartoweX();
- int getStartoweY();
- };
- class Postac
- {
- public:
- int obecneX, obecneY, nastepneX, nastepneY;
- char wyglad;
- public:
- void ruch(char przycisk);
- void ustawNaMapie(Mapa *ma);
- Postac(Mapa mapa);
- char getWyglad();
- int getObecneX();
- int getObecneY();
- };
- int main()
- {
- Mapa mapka("mapa.txt");
- Mapa buf(mapka);
- Postac boh(mapka);
- buf.setPunktNaMapie(boh.getWyglad(),boh.getObecneX(),boh.getObecneY());
- buf.wyswietlMape();
- return 0;
- }
- Mapa::Mapa(string nazwaMapy)
- {
- short punktNaMapie;
- ifstream plikMapy;
- plikMapy.open(nazwaMapy.c_str());
- plikMapy >> maxMapX;
- plikMapy >> maxMapY;
- plikMapy >> startoweX;
- plikMapy >> startoweY;
- calaMapa.clear();
- for(int y=0;y<maxMapY;y++)
- {
- linia.clear();
- for(int x=0;x<maxMapX;x++)
- {
- plikMapy >> punktNaMapie;
- if(punktNaMapie==1)
- {
- linia.push_back(char(219));
- }
- else if(punktNaMapie==0)
- {
- linia.push_back(' ');
- }
- }
- calaMapa.push_back(linia);
- }
- plikMapy.close();
- }
- void Mapa::wyswietlMape()
- {
- for(int y=0;y<maxMapY;y++)
- {
- for(int x=0;x<maxMapX;x++)
- {
- cout << calaMapa[y][x];
- }
- cout << endl;
- }
- }
- int Mapa::getStartoweX()
- {
- return startoweX;
- }
- int Mapa::getStartoweY()
- {
- return startoweY;
- }
- void Mapa::setPunktNaMapie(char znak, int oX, int oY)
- {
- vector<vector<char> >tymczasowy(maxMapY);
- for(int y=0;y<maxMapY;y++)
- {
- for(int x=0;x<maxMapX;x++)
- {
- if(y!=oY || x!=oX)
- {
- tymczasowy[y].push_back(calaMapa[y][x]);
- }else
- {
- tymczasowy[y].push_back(znak);
- }
- }
- }
- tymczasowy.swap(calaMapa);
- }
- Postac::Postac(Mapa mapa)
- {
- obecneX=mapa.getStartoweX();
- obecneY=mapa.getStartoweY();
- wyglad='x';
- }
- char Postac::getWyglad()
- {
- return wyglad;
- }
- int Postac::getObecneX()
- {
- return obecneX;
- }
- int Postac::getObecneY()
- {
- return obecneY;
- }
- void Postac::ustawNaMapie(Mapa *ma)
- {
- ma.setPunktNaMapie(wyglad,obecneX,obecneY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement