Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace sdadas {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- using namespace System::IO;
- //Opis kafli
- #define KAFEL_PUSTY 0;
- public ref class Mapa
- {
- private:
- Mapa(int szerokosc, int wysokosc)
- {
- this->width = szerokosc;
- this->height = wysokosc;
- tab_kafle = gcnew array<int>(width * height);
- }
- int width, height;
- array<int>^ tab_kafle;
- public:
- void UstawKafel(int x, int y, int id)
- {
- int offset = y * width + x;
- if(offset < width * height)
- tab_kafle[offset] = id;
- }
- int PobierzKafel(int x, int y)
- {
- int offset = y * width + x;
- if(offset < width * height)
- return tab_kafle[offset];
- else
- return KAFEL_PUSTY;
- }
- static Mapa^ LoadMap(String^ sciezka)
- {
- StreamReader^ strumien = File::OpenText(sciezka);
- String^ str_wymiary = strumien->ReadLine();
- int szerokosc = Convert::ToInt32(str_wymiary->Split(';')[0]);
- int wysokosc = Convert::ToInt32(str_wymiary->Split(';')[1]);
- Mapa^ mapa = gcnew Mapa(szerokosc, wysokosc);
- for(int i = 0; i < wysokosc; i++)
- {
- array<String^>^ wiersz = strumien->ReadLine()->Split(',');
- for(int j = 0; j < szerokosc; j++)
- mapa->UstawKafel(j, i, Convert::ToInt32(wiersz[j]));
- }
- strumien->Close();
- return mapa;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement