Advertisement
baadgeorge

Untitled

Apr 8th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. заголовочный
  2. #pragma once
  3. class Location
  4. {
  5. protected:
  6.     int X;
  7.     int Y;
  8. public:
  9.     Location(int _X, int _Y);
  10.     ~Location();
  11.     int GetX();
  12.     int GetY();
  13. };
  14.  
  15. class Point : public Location
  16. {
  17. protected:
  18.     bool isVisible;
  19.  
  20. public:
  21.     Point(int _X, int _Y);
  22.     ~Point();
  23.  
  24.     virtual void Show();
  25.     virtual void Hide();
  26.  
  27.     //void MoveTo(int NewX, int NewY);
  28.     //void Drag(int Step);
  29. };
  30.  
  31. class Grinder : public Point
  32. {
  33. protected:
  34.     int Scale;
  35. public:
  36.     Grinder(int _X, int _Y, int _Scale);
  37.     ~Grinder();
  38.  
  39.     virtual void Show();
  40.     virtual void Hide();
  41.  
  42.     void ChangeSize(int delta);
  43.    
  44. };
  45.  
  46. реализация
  47. #include <windows.h>
  48. #include "Classes.h"
  49. #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  50.  
  51. extern HDC hdc;
  52.  
  53. Location::Location(int _X, int _Y)
  54. {
  55.     X = _X;
  56.     Y = _Y;
  57. }
  58.  
  59. Location::~Location(){}
  60.  
  61. int Location::GetX()
  62. {
  63.     return X;
  64. }
  65.  
  66. int Location::GetY()
  67. {
  68.     return Y;
  69. }
  70.  
  71. Point::Point(int _X, int _Y) : Location(_X, _Y)
  72. {
  73.     isVisible = false;
  74. }
  75.  
  76.  
  77. Point::~Point(){}
  78.  
  79. void Point::Show()
  80. {
  81.     isVisible = true;
  82.     SetPixel(hdc, X, Y, RGB(0, 0, 255));
  83. }
  84.  
  85. void Point::Hide()
  86. {
  87.     isVisible = false;
  88.     SetPixel(hdc, X, Y, RGB(255, 0, 0));
  89.  
  90. }
  91.  
  92.  
  93. Grinder::Grinder(int _X, int _Y, int _Scale) : Point(_X, _Y)
  94. {
  95.     X = _X;
  96.     Y = _Y;
  97.     Scale = _Scale;
  98. }
  99.  
  100. Grinder::~Grinder(){}
  101.  
  102. void Grinder::Show()
  103. {
  104.     HPEN pen;
  105.     pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
  106.     SelectObject(hdc, pen);
  107.     HBRUSH brush;
  108.     MoveToEx(hdc, X, Y, NULL);
  109.  
  110.     //vent
  111.     brush = CreateSolidBrush(RGB(255, 0, 0));
  112.     SelectObject(hdc, brush);
  113.     Rectangle(hdc, X + 440 * Scale, Y + 200 * Scale, X + 460 * Scale, Y + 100 * Scale);
  114.  
  115.     //bottom
  116.     brush = CreateSolidBrush(RGB(255, 155, 0));
  117.     SelectObject(hdc, brush);
  118.     Rectangle(hdc, X + 305 * Scale, Y + 200 * Scale, X + 495 * Scale, Y + 320 * Scale);
  119.    
  120.     //top
  121.     brush = CreateSolidBrush(RGB(0, 0, 255));
  122.     SelectObject(hdc, brush);
  123.     POINT vertices[] = { {X + 400 * Scale, Y + 100 * Scale}, {X + 500 * Scale, Y + 200 * Scale}, {X + 300 * Scale, Y + 200 * Scale} };
  124.     Polygon(hdc, vertices, sizeof(vertices) / sizeof(vertices[0]));
  125.  
  126.     //window
  127.     brush = CreateSolidBrush(RGB(155, 0, 255));
  128.     SelectObject(hdc, brush);
  129.     Rectangle(hdc, X + 365 * Scale, Y + 230 * Scale, X + 435 * Scale, Y + 290 * Scale);
  130.     SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  131.     pen = CreatePen(PS_SOLID, 2, RGB(0, 255, 255));
  132.     SelectObject(hdc, pen);
  133.     MoveToEx(hdc, X + 400 * Scale, Y + 230 * Scale, NULL);
  134.     LineTo(hdc, X + 400 * Scale, Y + 290 * Scale);
  135.     MoveToEx(hdc, X + 365 * Scale, Y + 260 * Scale, NULL);
  136.     LineTo(hdc, X + 435 * Scale, Y + 260 * Scale);
  137.  
  138.     MoveToEx(hdc, X, Y, NULL);
  139.     //outbilding
  140.     brush = CreateSolidBrush(RGB(60, 155, 30));
  141.     SelectObject(hdc, brush);
  142.     pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
  143.     SelectObject(hdc, pen);
  144.     Rectangle(hdc, X + 495 * Scale, Y + 320 * Scale, X + 550 * Scale, Y + 250 * Scale);
  145.    
  146.     //wheel
  147.     SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  148.     pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
  149.     SelectObject(hdc, pen);
  150.     Ellipse(hdc, X + 475 * Scale, Y + 350 * Scale, X + 575 * Scale, Y + 250 * Scale);
  151.    
  152.     brush = CreateSolidBrush(RGB(0, 0, 0));
  153.     SelectObject(hdc, brush);
  154.     Ellipse(hdc, X + 520 * Scale, Y + 305 * Scale, X + 530 * Scale, Y + 295 * Scale);
  155.    
  156.     SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  157.     pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
  158.     MoveToEx(hdc, 880 * Scale, 335 * Scale, NULL);
  159.     LineTo(hdc, 770 * Scale, 265 * Scale);
  160.     MoveToEx(hdc, 790 * Scale, 355 * Scale, NULL);
  161.     LineTo(hdc, 860 * Scale, 245 * Scale);
  162.  
  163.     DeleteObject(pen);
  164.     DeleteObject(brush);
  165. }
  166.  
  167. void Grinder::Hide()
  168. {
  169.     isVisible = false;
  170.     HBRUSH rubber;
  171.     rubber = CreateSolidBrush(RGB(100, 100, 100));
  172.     HPEN pen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));
  173.     SelectObject(hdc, pen);
  174.     SelectObject(hdc, rubber);
  175.     MoveToEx(hdc, X, Y, NULL);
  176.     Rectangle(hdc, X - 5, Y - 25 * Scale, X + 205 * Scale, Y + 205 * Scale);
  177.     DeleteObject(pen);
  178.     DeleteObject(rubber);
  179. }
  180.  
  181. void Grinder::ChangeSize(int delta)
  182. {
  183.     Hide();
  184.     Scale = delta;
  185.     Show();
  186. }
  187.  
  188. мэйн
  189. # pragma once
  190.  
  191. #include <windows.h>
  192. #include <conio.h>
  193. #include <iostream>
  194.  
  195. using namespace std;
  196.  
  197. #include "Classes.h"
  198. #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)) & 0x8000 ? 1 : 0)
  199.  
  200. void PressKey(int VkCode);
  201.  
  202. HDC hdc;
  203.  
  204. int main()
  205. {
  206.     int X_0 = 300;
  207.     int Y_0 = 0;
  208.     int Scale_0 = 1;
  209.     system("color F0");
  210.  
  211.     HWND hwnd = GetConsoleWindow();
  212.  
  213.     if (hwnd != NULL)
  214.     {
  215.         hdc = GetWindowDC(hwnd);
  216.         if (hdc != 0)
  217.         {
  218.             PressKey(50);//2
  219.             Point* p = new Grinder(X_0, Y_0, Scale_0);
  220.             p->Show();
  221.             PressKey(51);//3
  222.             p->Hide();
  223.         }
  224.     }
  225.  
  226. }
  227. void PressKey(int VkCode)
  228. {
  229.     while (1)
  230.     {
  231.         if (KEY_DOWN(VkCode))
  232.         {
  233.             break;
  234.         }
  235.     }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement