Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- заголовочный
- #pragma once
- class Location
- {
- protected:
- int X;
- int Y;
- public:
- Location(int _X, int _Y);
- ~Location();
- int GetX();
- int GetY();
- };
- class Point : public Location
- {
- protected:
- bool isVisible;
- public:
- Point(int _X, int _Y);
- ~Point();
- virtual void Show();
- virtual void Hide();
- //void MoveTo(int NewX, int NewY);
- //void Drag(int Step);
- };
- class Grinder : public Point
- {
- protected:
- int Scale;
- public:
- Grinder(int _X, int _Y, int _Scale);
- ~Grinder();
- virtual void Show();
- virtual void Hide();
- void ChangeSize(int delta);
- };
- реализация
- #include <windows.h>
- #include "Classes.h"
- #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
- extern HDC hdc;
- Location::Location(int _X, int _Y)
- {
- X = _X;
- Y = _Y;
- }
- Location::~Location(){}
- int Location::GetX()
- {
- return X;
- }
- int Location::GetY()
- {
- return Y;
- }
- Point::Point(int _X, int _Y) : Location(_X, _Y)
- {
- isVisible = false;
- }
- Point::~Point(){}
- void Point::Show()
- {
- isVisible = true;
- SetPixel(hdc, X, Y, RGB(0, 0, 255));
- }
- void Point::Hide()
- {
- isVisible = false;
- SetPixel(hdc, X, Y, RGB(255, 0, 0));
- }
- Grinder::Grinder(int _X, int _Y, int _Scale) : Point(_X, _Y)
- {
- X = _X;
- Y = _Y;
- Scale = _Scale;
- }
- Grinder::~Grinder(){}
- void Grinder::Show()
- {
- HPEN pen;
- pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
- SelectObject(hdc, pen);
- HBRUSH brush;
- MoveToEx(hdc, X, Y, NULL);
- //vent
- brush = CreateSolidBrush(RGB(255, 0, 0));
- SelectObject(hdc, brush);
- Rectangle(hdc, X + 440 * Scale, Y + 200 * Scale, X + 460 * Scale, Y + 100 * Scale);
- //bottom
- brush = CreateSolidBrush(RGB(255, 155, 0));
- SelectObject(hdc, brush);
- Rectangle(hdc, X + 305 * Scale, Y + 200 * Scale, X + 495 * Scale, Y + 320 * Scale);
- //top
- brush = CreateSolidBrush(RGB(0, 0, 255));
- SelectObject(hdc, brush);
- POINT vertices[] = { {X + 400 * Scale, Y + 100 * Scale}, {X + 500 * Scale, Y + 200 * Scale}, {X + 300 * Scale, Y + 200 * Scale} };
- Polygon(hdc, vertices, sizeof(vertices) / sizeof(vertices[0]));
- //window
- brush = CreateSolidBrush(RGB(155, 0, 255));
- SelectObject(hdc, brush);
- Rectangle(hdc, X + 365 * Scale, Y + 230 * Scale, X + 435 * Scale, Y + 290 * Scale);
- SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
- pen = CreatePen(PS_SOLID, 2, RGB(0, 255, 255));
- SelectObject(hdc, pen);
- MoveToEx(hdc, X + 400 * Scale, Y + 230 * Scale, NULL);
- LineTo(hdc, X + 400 * Scale, Y + 290 * Scale);
- MoveToEx(hdc, X + 365 * Scale, Y + 260 * Scale, NULL);
- LineTo(hdc, X + 435 * Scale, Y + 260 * Scale);
- MoveToEx(hdc, X, Y, NULL);
- //outbilding
- brush = CreateSolidBrush(RGB(60, 155, 30));
- SelectObject(hdc, brush);
- pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
- SelectObject(hdc, pen);
- Rectangle(hdc, X + 495 * Scale, Y + 320 * Scale, X + 550 * Scale, Y + 250 * Scale);
- //wheel
- SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
- pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
- SelectObject(hdc, pen);
- Ellipse(hdc, X + 475 * Scale, Y + 350 * Scale, X + 575 * Scale, Y + 250 * Scale);
- brush = CreateSolidBrush(RGB(0, 0, 0));
- SelectObject(hdc, brush);
- Ellipse(hdc, X + 520 * Scale, Y + 305 * Scale, X + 530 * Scale, Y + 295 * Scale);
- SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
- pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
- MoveToEx(hdc, 880 * Scale, 335 * Scale, NULL);
- LineTo(hdc, 770 * Scale, 265 * Scale);
- MoveToEx(hdc, 790 * Scale, 355 * Scale, NULL);
- LineTo(hdc, 860 * Scale, 245 * Scale);
- DeleteObject(pen);
- DeleteObject(brush);
- }
- void Grinder::Hide()
- {
- isVisible = false;
- HBRUSH rubber;
- rubber = CreateSolidBrush(RGB(100, 100, 100));
- HPEN pen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));
- SelectObject(hdc, pen);
- SelectObject(hdc, rubber);
- MoveToEx(hdc, X, Y, NULL);
- Rectangle(hdc, X - 5, Y - 25 * Scale, X + 205 * Scale, Y + 205 * Scale);
- DeleteObject(pen);
- DeleteObject(rubber);
- }
- void Grinder::ChangeSize(int delta)
- {
- Hide();
- Scale = delta;
- Show();
- }
- мэйн
- # pragma once
- #include <windows.h>
- #include <conio.h>
- #include <iostream>
- using namespace std;
- #include "Classes.h"
- #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)) & 0x8000 ? 1 : 0)
- void PressKey(int VkCode);
- HDC hdc;
- int main()
- {
- int X_0 = 300;
- int Y_0 = 0;
- int Scale_0 = 1;
- system("color F0");
- HWND hwnd = GetConsoleWindow();
- if (hwnd != NULL)
- {
- hdc = GetWindowDC(hwnd);
- if (hdc != 0)
- {
- PressKey(50);//2
- Point* p = new Grinder(X_0, Y_0, Scale_0);
- p->Show();
- PressKey(51);//3
- p->Hide();
- }
- }
- }
- void PressKey(int VkCode)
- {
- while (1)
- {
- if (KEY_DOWN(VkCode))
- {
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement