Advertisement
Mihao

Snieg

Jan 18th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include "Platki_sniegu.h"
  4. #include <Windows.h>
  5. #include "stdio.h"
  6. #include <list>
  7. #include <ctime>
  8.  
  9.  
  10. using namespace std;
  11.  
  12.  
  13. #define SZE 100
  14. #define WYS 80
  15.  
  16. TCHAR Class_Name[] = TEXT("OKNO_TEST");
  17. MSG Komunikat;
  18. int zmienna = 0;
  19. char ilosc[128];
  20. HINSTANCE *hInst;
  21. HWND okno1;
  22. int roztopy=0;
  23. const WORD ID_TIMER = 1;
  24. RECT WymiaryOkna;
  25. int licznik = 0;
  26. int index = 0;
  27. int level = 0;
  28. HBRUSH tlo, platek_srodek;
  29. HPEN obrys;
  30. int inc = 0;
  31. RECT tablica[1000];
  32.  
  33. void DodajPlatek(int idx)
  34. {
  35.     RECT temp;
  36.     temp.left = rand() % 800+50; // (rand() % 98) + WymiaryOkna.right/100
  37.     temp.top = 30;
  38.     temp.right = temp.left + 30;
  39.     temp.bottom = 60;
  40.     tablica[idx] = temp;
  41. }
  42.  
  43. void WarstawNizej(int idx)
  44. {
  45.     for (int i = 0; i < idx - 1; i++)
  46.     {
  47.         int random = rand() % 30;
  48.         RECT temp = tablica[i];
  49.         if (temp.bottom + 30 < (WymiaryOkna.bottom - (i * 2)) )
  50.         {
  51.             if (rand() % 2)
  52.             {
  53.                
  54.                 temp.left -= random;
  55.                 temp.right -= random;
  56.             }
  57.             else
  58.             {
  59.                 temp.left += random;
  60.                 temp.right +=random;
  61.             }
  62.  
  63.             temp.top += 30;
  64.             temp.bottom += 30;
  65.         }
  66.         tablica[i] = temp;
  67.     }
  68. }
  69.  
  70. void Roztop(int roztopy) {
  71.    
  72.     for (int i = roztopy - 10; i < roztopy; i++)
  73.     {
  74.         RECT temp = tablica[i];
  75.         temp.left = 0;
  76.         temp.right = 0;
  77.         temp.top = 0;
  78.         temp.bottom = 0;
  79.         tablica[i] = temp;
  80.     }
  81. }
  82.  
  83. void Rysuj(int idx) {
  84.     HDC hdc = GetDC(okno1);
  85.  
  86.     FillRect(hdc, &WymiaryOkna, tlo);
  87.     Ellipse(hdc, 60, 60, 30, 30);
  88.     SelectObject(hdc, platek_srodek);
  89.     for (int i = 0; i < idx; i++)
  90.     {
  91.         Rectangle(hdc, tablica[i].left, tablica[i].top, tablica[i].right, tablica[i].bottom);
  92.     }
  93. }
  94.  
  95. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  96. {
  97.     GetClientRect(hwnd, &WymiaryOkna);
  98.  
  99.     switch (msg) {
  100.     case WM_CREATE:
  101.     {
  102.         SetTimer(hwnd, 1, 100, NULL);
  103.         tlo = CreateSolidBrush(RGB(128, 0, 128));
  104.         platek_srodek = CreateSolidBrush(RGB(115 , 215 , 215));
  105.  
  106.         obrys = CreatePen(PS_SOLID, 3, RGB(0, 20, 222));
  107.     }
  108.     case WM_TIMER:
  109.        
  110.         licznik++;
  111.  
  112.         DodajPlatek(index);
  113.         WarstawNizej(index);
  114.  
  115.  
  116.  
  117.         if (licznik == 9)
  118.         {
  119.             licznik = 0;
  120.             roztopy++;
  121.            
  122.         }
  123.  
  124.         if (inc == 99)
  125.         {
  126.             Roztop(roztopy);
  127.             inc = 0;
  128.            
  129.         }
  130.  
  131.         Rysuj(index);
  132.         index++;
  133.  
  134.         break;
  135.     case WM_LBUTTONDOWN:
  136.         KillTimer(hwnd, ID_TIMER);
  137.  
  138.         licznik = 0;
  139.         level = 0;
  140.         index = 0;
  141.         SetTimer(hwnd, 1, 100, NULL);
  142.  
  143.         break;
  144.     case WM_CLOSE:
  145.         if ((MessageBox(hwnd, TEXT("Czy chcesz wyłączyć okno ?"), TEXT("Pytanie"), MB_OKCANCEL)) == IDOK)
  146.             DestroyWindow(hwnd);
  147.         else break;
  148.     case WM_DESTROY:
  149.         PostQuitMessage(0);
  150.         break;
  151.     default:
  152.         return DefWindowProcW(hwnd, msg, wParam, lParam);
  153.     }
  154.     return 0;
  155. }
  156.  
  157. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  158. {
  159.     hInst = &hInstance;
  160.     WNDCLASSEX window;
  161.     window.cbClsExtra = NULL;
  162.     window.cbSize = sizeof(WNDCLASSEX);
  163.     window.cbWndExtra = NULL;
  164.     window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  165.     window.hCursor = LoadCursor(*hInst, IDC_ARROW);
  166.     window.hIcon = LoadIcon(*hInst, IDI_APPLICATION);
  167.     window.hIconSm = NULL;
  168.     window.hInstance = *hInst;
  169.     window.lpfnWndProc = WndProc;
  170.     window.lpszClassName = Class_Name;
  171.     window.lpszMenuName = 0;
  172.     window.style = NULL;
  173.  
  174.     if (!RegisterClassEx(&window)) {
  175.         MessageBox(NULL, TEXT("Zarejestrowanie klasy nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
  176.         return 1;
  177.     }
  178.  
  179.  
  180.     okno1 = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, TEXT("Okno 1"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1000, 800, NULL, NULL, *hInst, NULL);
  181.  
  182.     if (okno1 == NULL) {
  183.         MessageBox(NULL, TEXT("Stworzenie okna nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
  184.         return 2;
  185.     }
  186.  
  187.     ShowWindow(okno1, nCmdShow);
  188.     UpdateWindow(okno1);
  189.  
  190.     while (GetMessage(&Komunikat, NULL, 0, 0)) {
  191.  
  192.         TranslateMessage(&Komunikat);
  193.         DispatchMessage(&Komunikat);
  194.     }
  195.     UnregisterClass(Class_Name, *hInst);
  196.     return Komunikat.wParam;
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement