Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <list>
- #include <string>
- using namespace std;
- wchar_t klasa[] = TEXT("Klasa");
- class Obiekt{
- protected:
- POINT p;
- public:
- Obiekt(int x, int y)
- {
- p.x = x;
- p.y = y;
- };
- virtual void Rysuj(HDC AAA) = 0;
- };
- class Mur:public Obiekt{
- public:
- Mur(int x, int y): Obiekt(x,y) {};
- void Rysuj(HDC AAA){
- int S = SaveDC(AAA);
- HBRUSH b = CreateSolidBrush(0x000000FF);
- SelectObject(AAA,b);
- Rectangle(AAA,p.x,p.y,p.x+10,p.y+10);
- RestoreDC(AAA, S);
- DeleteObject(b);
- }
- };
- class Romb:public Obiekt{
- public:
- Romb(int x, int y): Obiekt(x,y) {};
- void Rysuj(HDC AAA){
- MoveToEx(AAA,p.x,p.y-5,0);
- LineTo(AAA,p.x+5,p.y);
- LineTo(AAA,p.x+10,p.y-5);
- LineTo(AAA,p.x+5,p.y-10);
- LineTo(AAA,p.x,p.y-5);
- }
- };
- class Paczka:public Obiekt{
- public:
- Paczka(int x, int y): Obiekt(x,y) {};
- void Rysuj(HDC AAA){
- int S = SaveDC(AAA);
- HBRUSH b = CreateSolidBrush(0x0000FFFF);
- SelectObject(AAA,b);
- Rectangle(AAA,p.x,p.y,p.x+10,p.y+10);
- MoveToEx(AAA,p.x,p.y,0);
- LineTo(AAA,p.x+10,p.y+10);
- MoveToEx(AAA,p.x,p.y+10,0);
- LineTo(AAA,p.x+10,p.y);
- RestoreDC(AAA,S);
- DeleteObject(b);
- }
- };
- class Pracownik:public Obiekt{
- public:
- Pracownik(int x, int y): Obiekt(x,y) {};
- void Rysuj(HDC AAA){
- int S = SaveDC(AAA);
- HPEN pen = CreatePen(PS_SOLID,1,0x00FF0000);
- SelectObject(AAA,pen);
- Ellipse(AAA,p.x,p.y,p.x+10,p.y+10);
- RestoreDC(AAA, S);
- DeleteObject(pen);
- }
- };
- list<Obiekt*> Mapa;
- void WczytajMape(list<Obiekt*> &Mapa){
- FILE *plik;
- char bufor=' ';
- plik = fopen("mapa.txt","r");
- if(!plik){
- MessageBox(0,L"Nie ma plika we wskazniku!",L"Alert",MB_OK);
- return;
- }
- rewind(plik);
- for(int i=0; i<16; i++){
- for(int j=0; j<21; j++){
- fscanf(plik,"%c",&bufor);
- if(bufor=='#') Mapa.push_back(new Mur(j*10,i*10));
- if(bufor=='x') Mapa.push_back(new Romb(j*10,i*10));
- if(bufor=='P') Mapa.push_back(new Paczka(j*10, i*10));
- if(bufor=='@') Mapa.push_back(new Pracownik(j*10, i*10));
- }
- }
- fclose(plik);
- }
- LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
- switch(msg){
- case WM_PAINT:{
- PAINTSTRUCT ps;
- RECT R;
- BeginPaint(hWnd,&ps);
- GetClientRect(hWnd,&R);
- SetMapMode(ps.hdc,MM_ISOTROPIC);
- SetWindowExtEx(ps.hdc,200,160,0);
- SetViewportExtEx(ps.hdc,R.right,R.bottom,0);
- SetViewportOrgEx(ps.hdc,R.left,R.top,0);
- list<Obiekt*>::iterator it;
- for(it = Mapa.begin(); it != Mapa.end(); ++it){
- (*it)->Rysuj(ps.hdc);
- }
- EndPaint(hWnd,&ps);
- } break;
- case WM_DESTROY:{
- PostQuitMessage(1337);
- } break;
- default: return DefWindowProc(hWnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE AAA, LPWSTR lpCmdLine, int nShowCmd){
- WNDCLASSEX wc;
- wc.cbClsExtra = wc.cbWndExtra = 0;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.hbrBackground = (HBRUSH)(1 + COLOR_WINDOW);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hIcon = wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc.hInstance = hInst;
- wc.lpfnWndProc = &WinProc;
- wc.lpszClassName = klasa;
- wc.lpszMenuName = 0;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- if(!RegisterClassEx(&wc)){
- MessageBox(0,L"Nie zadeklarowano klasy",L"Alert",MB_OK | MB_ICONERROR);
- return 0;
- }
- HWND Okno = CreateWindowEx(0, klasa, TEXT("APP"), WS_OVERLAPPEDWINDOW, 10, 10, 800, 640, 0, 0, hInst, 0);
- if(!Okno){
- MessageBox(0,L"Nie stworzono okna",L"Alert",MB_OK | MB_ICONERROR);
- return 0;
- }
- WczytajMape(Mapa);
- ShowWindow(Okno,nShowCmd);
- UpdateWindow(Okno);
- MSG msg;
- while(GetMessage(&msg,0,0,0)>0){
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- Mapa.clear();
- UnregisterClass(klasa,hInst);
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement