Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.75 KB | None | 0 0
  1. #include <windows.h>
  2. #include <list>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. wchar_t klasa[] = TEXT("Klasa");
  8.  
  9. class Obiekt{
  10. protected:
  11.     POINT p;
  12. public:
  13.     Obiekt(int x, int y)
  14.     {
  15.         p.x = x;
  16.         p.y = y;
  17.     };
  18.  
  19.         virtual void Rysuj(HDC AAA) = 0;
  20. };
  21.  
  22. class Mur:public Obiekt{
  23. public:
  24.     Mur(int x, int y): Obiekt(x,y) {};
  25.  
  26.     void Rysuj(HDC AAA){
  27.         int S = SaveDC(AAA);
  28.         HBRUSH b = CreateSolidBrush(0x000000FF);
  29.         SelectObject(AAA,b);
  30.         Rectangle(AAA,p.x,p.y,p.x+10,p.y+10);
  31.         RestoreDC(AAA, S);
  32.         DeleteObject(b);
  33.     }
  34.  
  35.  
  36. };
  37.  
  38. class Romb:public Obiekt{
  39. public:
  40.     Romb(int x, int y): Obiekt(x,y) {};
  41.  
  42.     void Rysuj(HDC AAA){
  43.         MoveToEx(AAA,p.x,p.y-5,0);
  44.         LineTo(AAA,p.x+5,p.y);
  45.         LineTo(AAA,p.x+10,p.y-5);
  46.         LineTo(AAA,p.x+5,p.y-10);
  47.         LineTo(AAA,p.x,p.y-5);
  48.     }
  49. };
  50.  
  51. class Paczka:public Obiekt{
  52. public:
  53.     Paczka(int x, int y): Obiekt(x,y) {};
  54.  
  55.     void Rysuj(HDC AAA){
  56.         int S = SaveDC(AAA);
  57.         HBRUSH b = CreateSolidBrush(0x0000FFFF);
  58.         SelectObject(AAA,b);
  59.         Rectangle(AAA,p.x,p.y,p.x+10,p.y+10);
  60.         MoveToEx(AAA,p.x,p.y,0);
  61.         LineTo(AAA,p.x+10,p.y+10);
  62.         MoveToEx(AAA,p.x,p.y+10,0);
  63.         LineTo(AAA,p.x+10,p.y);
  64.         RestoreDC(AAA,S);
  65.         DeleteObject(b);
  66.     }
  67. };
  68.  
  69. class Pracownik:public Obiekt{
  70. public:
  71.     Pracownik(int x, int y): Obiekt(x,y) {};
  72.  
  73.     void Rysuj(HDC AAA){
  74.         int S = SaveDC(AAA);
  75.         HPEN pen = CreatePen(PS_SOLID,1,0x00FF0000);
  76.         SelectObject(AAA,pen);
  77.         Ellipse(AAA,p.x,p.y,p.x+10,p.y+10);
  78.         RestoreDC(AAA, S);
  79.         DeleteObject(pen);
  80.     }
  81. };
  82.  
  83. list<Obiekt*> Mapa;
  84.  
  85. void WczytajMape(list<Obiekt*> &Mapa){
  86.     FILE *plik;
  87.     char bufor=' ';
  88.     plik = fopen("mapa.txt","r");
  89.     if(!plik){
  90.         MessageBox(0,L"Nie ma plika we wskazniku!",L"Alert",MB_OK);
  91.         return;
  92.     }
  93.     rewind(plik);
  94.     for(int i=0; i<16; i++){
  95.         for(int j=0; j<21; j++){
  96.             fscanf(plik,"%c",&bufor);
  97.             if(bufor=='#') Mapa.push_back(new Mur(j*10,i*10));
  98.             if(bufor=='x') Mapa.push_back(new Romb(j*10,i*10));
  99.             if(bufor=='P') Mapa.push_back(new Paczka(j*10, i*10));
  100.             if(bufor=='@') Mapa.push_back(new Pracownik(j*10, i*10));
  101.         }
  102.     }  
  103.     fclose(plik);
  104. }
  105.  
  106.  
  107. LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
  108.     switch(msg){
  109.         case WM_PAINT:{
  110.             PAINTSTRUCT ps;
  111.             RECT R;
  112.  
  113.             BeginPaint(hWnd,&ps);
  114.             GetClientRect(hWnd,&R);
  115.  
  116.             SetMapMode(ps.hdc,MM_ISOTROPIC);
  117.             SetWindowExtEx(ps.hdc,200,160,0);
  118.             SetViewportExtEx(ps.hdc,R.right,R.bottom,0);
  119.             SetViewportOrgEx(ps.hdc,R.left,R.top,0);
  120.  
  121.             list<Obiekt*>::iterator it;
  122.            
  123.             for(it = Mapa.begin(); it != Mapa.end(); ++it){
  124.                 (*it)->Rysuj(ps.hdc);
  125.             }
  126.  
  127.             EndPaint(hWnd,&ps);
  128.  
  129.                       } break;
  130.  
  131.         case WM_DESTROY:{
  132.             PostQuitMessage(1337);
  133.                         } break;
  134.  
  135.         default: return DefWindowProc(hWnd, msg, wParam, lParam);
  136.  
  137.     }
  138.     return 0;
  139. }
  140.  
  141. int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE AAA, LPWSTR lpCmdLine, int nShowCmd){
  142.     WNDCLASSEX wc;
  143.  
  144.     wc.cbClsExtra = wc.cbWndExtra = 0;
  145.     wc.cbSize = sizeof(WNDCLASSEX);
  146.     wc.hbrBackground = (HBRUSH)(1 + COLOR_WINDOW);
  147.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  148.     wc.hIcon = wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  149.     wc.hInstance = hInst;
  150.     wc.lpfnWndProc = &WinProc;
  151.     wc.lpszClassName = klasa;
  152.     wc.lpszMenuName = 0;
  153.     wc.style = CS_HREDRAW | CS_VREDRAW;
  154.  
  155.     if(!RegisterClassEx(&wc)){
  156.         MessageBox(0,L"Nie zadeklarowano klasy",L"Alert",MB_OK | MB_ICONERROR);
  157.         return 0;
  158.     }
  159.  
  160.     HWND Okno = CreateWindowEx(0, klasa, TEXT("APP"), WS_OVERLAPPEDWINDOW, 10, 10, 800, 640, 0, 0, hInst, 0);
  161.  
  162.     if(!Okno){
  163.         MessageBox(0,L"Nie stworzono okna",L"Alert",MB_OK | MB_ICONERROR);
  164.         return 0;
  165.     }
  166.  
  167.     WczytajMape(Mapa);
  168.  
  169.     ShowWindow(Okno,nShowCmd);
  170.     UpdateWindow(Okno);
  171.  
  172.     MSG msg;
  173.  
  174.     while(GetMessage(&msg,0,0,0)>0){
  175.         TranslateMessage(&msg);
  176.         DispatchMessage(&msg);
  177.     }
  178.  
  179.     Mapa.clear();
  180.     UnregisterClass(klasa,hInst);
  181.     return msg.wParam;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement