Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. namespace sdadas {
  2.  
  3.     using namespace System;
  4.     using namespace System::ComponentModel;
  5.     using namespace System::Collections;
  6.     using namespace System::Windows::Forms;
  7.     using namespace System::Data;
  8.     using namespace System::Drawing;
  9.     using namespace System::IO;
  10.  
  11.     //Opis kafli
  12.     #define KAFEL_PUSTY 0;
  13.  
  14.     public ref class Mapa
  15.     {
  16.     private:
  17.         Mapa(int szerokosc, int wysokosc)
  18.         {
  19.             this->width = szerokosc;
  20.             this->height = wysokosc;
  21.  
  22.             tab_kafle = gcnew array<int>(width * height);
  23.         }
  24.  
  25.         int width, height;
  26.         array<int>^ tab_kafle;
  27.     public:
  28.         void UstawKafel(int x, int y, int id)
  29.         {
  30.             int offset = y * width + x;
  31.             if(offset < width * height)
  32.                 tab_kafle[offset] = id;
  33.         }
  34.  
  35.         int PobierzKafel(int x, int y)
  36.         {
  37.             int offset = y * width + x;
  38.             if(offset < width * height)
  39.                 return tab_kafle[offset];
  40.             else
  41.                 return KAFEL_PUSTY;
  42.         }
  43.  
  44.         static Mapa^ LoadMap(String^ sciezka)
  45.         {
  46.             StreamReader^ strumien = File::OpenText(sciezka);
  47.             String^ str_wymiary = strumien->ReadLine();
  48.  
  49.             int szerokosc = Convert::ToInt32(str_wymiary->Split(';')[0]);
  50.             int wysokosc = Convert::ToInt32(str_wymiary->Split(';')[1]);
  51.  
  52.             Mapa^ mapa = gcnew Mapa(szerokosc, wysokosc);
  53.  
  54.             for(int i = 0; i < wysokosc; i++)
  55.             {
  56.                 array<String^>^ wiersz = strumien->ReadLine()->Split(',');
  57.                 for(int j = 0; j < szerokosc; j++)
  58.                     mapa->UstawKafel(j, i, Convert::ToInt32(wiersz[j]));
  59.             }
  60.  
  61.             strumien->Close();
  62.  
  63.             return mapa;
  64.         }
  65.     };
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement