Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
kr_cherevatov_2pi-12.docx
Скачиваний:
1
Добавлен:
01.05.2025
Размер:
2 Мб
Скачать
☆

7.2 Необхідні файли

Для нормального функціонування програми необхідними є exe-файл для запуску, а також компоненти середовища виконання бібліотек Visual C++;

7.3 Встановлення програми

Для запуску даної програми необхідно встановити “Розповсюджуваний пакет Microsoft Visual C + + 2010”. Для його встановлення необхідно запустити “vcredist_x86.exe”. Після цього достатньо скопіювати exe-файл проекту на комп’ютер і запустити.

Висновки

В процесі роботи над курсовою роботою було створено проект на тему «Депутати». Засобами обраної мови програмування (С++) були реалізовані наближені методи, які забезпечували взаємодію між мікрооб’єктами між собою та робочою областю.

При створенні курсової роботи були використані чисельні засоби мови С++, такі як: створення динамічних масивів першого і другого типів, графічне відображення мікрооб’єктів засобами WinApi, серіалізація та десеріалізація, робота з діалоговими вікнами та інше. Це і надало певних навичок проектування програмного продукту.

Перелік посилань

(1.Бьярне Страуструп  Программирование: принципы и практика использования C++, исправленное издание = Programming: Principles and Practice Using C++. — М.: «Вильямс», 2011. —  1248 с.)

(2.Борис Пахомов C/C++ и MS Visual С++ 2010 для начинающих - Санкт-Петербург : «БХВ-Петербург», 2011. – 300 с. )

(3.Зубенко В.В. Програмування : навчальний посібник (гриф МОН України) / В.В. Зубенко, Л.Л. Омельчук. - К. : ВПЦ "Київський університет", 2011. - 623 c.)

(4. Джереми Сик, Лай-Кван Ли, Эндрю Ламсдэйн C++ Boots Graph Library – Санкт-Петербург: «Питер», 2006. – 304 с.)

(5. Джефф Элджер С++ - Санкт-Петербург: «Питер», 2008. – 259 с. )

(6. Стивен Дьюхерст С++. Священные знания – М.: «Символ-Плюс», 2012. – 232 с.)

(7. Stephen Prata C++ Primer Plus, 6th edition – Addison-Wesley, 2012. – 1438 с.)

(8. Гербер Шилд С++. Руководство для начинающих, 2-е издание – М.: «Вильямс», 2005. – 245 с.)

(9.Лавров С.С. Програмирование. Математические основи, средства,теория / С.С. Лавров. - СПб. : БХВ-Петербург,2001. - 251с.)

Додаток А

Лістинг модуля Class.h

class Deputy

{

public:

char *name;

int size;

int x;

int y;

int type;

bool active;

bool belong;

Deputy(char *name_="Депутат", int x_=rand()%800+100, int y_=rand()%600+100)//конструктор

{

size=20;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=name_[i];

x=x_;

y=y_;

active=false;

belong=false;

type =1;

}

Deputy(const Deputy & arg)//конструктор копіювання

{

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=1;

};

Deputy & operator = (Deputy &arg)//Перевантажений оператор =

{

if( this == &arg ) return (*this);

delete [] name;

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=1;

return (*this);

};

virtual ~Deputy()//деструктор

{

}

virtual void Draw(HDC hdc);

bool select_obj(int x1, int y1);

void unactive();

void moveto(int x1, int y1);

bool new_spiker();

bool new_vyla();

void move_timer(HWND hWnd);

bool belong_f();

int add_new_deputy();

int kill(int i);

int all_parlament();

};

class Lider_par: public Deputy

{

public:

Lider_par(char *name_="Лiдер", int x_=rand()%800+100, int y_=rand()%600+100)//конструктор

{

size=20;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=name_[i];

x=x_;

y=y_;

active=false;

belong=false;

type=2;

}

Lider_par (const Lider_par & arg)//конструктор копіювання

{

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=2;

};

Lider_par & operator = (Lider_par &arg)//Перевантажений оператор =

{

if( this == &arg ) return (*this);

delete [] name;

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=2;

return (*this);

};

void Draw(HDC hdc);

int newdep();

};

class Vyla: public Lider_par

{

public:

Vyla(char *name_="Ляшко", int x_=rand()%800+100, int y_=rand()%600+100)//конструктор

{

size=20;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=name_[i];

x=x_;

y=y_;

active=false;

belong=false;

type=3;

}

Vyla(const Vyla & arg)//конструктор копіювання

{

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=3;

};

Vyla & operator = (Vyla &arg)//Перевантажений оператор =

{

if( this == &arg ) return (*this);

delete [] name;

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=3;

return (*this);

};

void Draw(HDC hdc);

int KILL(int i);

};

class Spiker: public Lider_par

{

public:

Spiker(char *name_="Спiкер", int x_=rand()%800+100, int y_=rand()%600+100)//конструктор

{

size=20;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=name_[i];

x=x_;

y=y_;

active=false;

belong=false;

type=4;

}

Spiker(const Spiker & arg)//конструктор копіювання

{

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=4;

};

Spiker & operator = (Spiker &arg)//Перевантажений оператор =

{

if( this == &arg ) return (*this);

delete [] name;

size=arg.size;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=arg.name[i];

x=arg.x; y=arg.y;

active=false;

belong=false;

type=4;

return (*this);

};

void Draw(HDC hdc);

int parlament();

};

//макрообєкти

class Rada

{

public:

char *name;

int size;

int x;

int y;

bool active;

Rada (char *name_="Верховна Рада", int x_=300, int y_=400)//конструктор

{

size=20;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=name_[i];

x=x_+5;

y=y_;

active=false;

}

~Rada()//деструктор

{

}

void Draw(HDC hdc);

bool select_obj(int x1, int y1);

void unactive();

void moveto(int x1, int y1);

};

class Mityng

{

char *name;

int size;

public:

int x;

int y;

bool active;

Mityng (char *name_="Владу геть!", int x_=700, int y_=200)//конструктор

{

size=20;

name=new char[size];

for(int i=0;i<size;i++)

name[i]=name_[i];

x=x_;

y=y_;

active=false;

}

~Mityng()//деструктор

{

}

void Draw(HDC hdc,int i,int g,int c);

bool select_obj(int x1, int y1);

void unactive();

void moveto(int x1, int y1);

};

extern Deputy **arr;

extern Rada rad;

extern Mityng mit;

extern int num;

Додаток Б

Лістинг модуля 3_lab.cpp

#include "stdafx.h"

#include "3_lab.h"

#include <time.h>

#include "class.h"

#include <string>

#include <stdlib.h>

#include <cwchar>

#include <fstream>

#include <commdlg.h>

using namespace std;

static OPENFILENAME ofn;

#define MAX_LOADSTRING 100

int l,g,c;

UINT timerid;

const unsigned int TIMER_7SEC = 2;

RECT rect;

// Global Variables:

HINSTANCE hInst; // current instance

TCHAR szTitle[MAX_LOADSTRING]; // The title bar text

TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:

ATOM MyRegisterClass(HINSTANCE hInstance);

BOOL InitInstance(HINSTANCE, int);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

INT_PTR CALLBACK AddObj(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPTSTR lpCmdLine,

int nCmdShow)

{

UNREFERENCED_PARAMETER(hPrevInstance);

UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.

MSG msg;

HACCEL hAccelTable;

// Initialize global strings

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

LoadString(hInstance, IDC_MY3_LAB, szWindowClass, MAX_LOADSTRING);

MyRegisterClass(hInstance);

// Perform application initialization:

if (!InitInstance (hInstance, nCmdShow))

{

return FALSE;

}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY3_LAB));

// Main message loop:

while (GetMessage(&msg, NULL, 0, 0))

{

if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

return (int) msg.wParam;

}

//

// FUNCTION: MyRegisterClass()

//

// PURPOSE: Registers the window class.

//

// COMMENTS:

//

// This function and its usage are only necessary if you want this code

// to be compatible with Win32 systems prior to the 'RegisterClassEx'

// function that was added to Windows 95. It is important to call this function

// so that the application will get 'well formed' small icons associated

// with it.

//

ATOM MyRegisterClass(HINSTANCE hInstance)

{

WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;

wcex.lpfnWndProc = WndProc;

wcex.cbClsExtra = 0;

wcex.cbWndExtra = 0;

wcex.hInstance = hInstance;

wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MY3_LAB));

wcex.hCursor = LoadCursor(NULL, IDC_ARROW);

wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MY3_LAB);

wcex.lpszClassName = szWindowClass;

wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);

}

//

// FUNCTION: InitInstance(HINSTANCE, int)

//

// PURPOSE: Saves instance handle and creates main window

//

// COMMENTS:

//

// In this function, we save the instance handle in a global variable and

// create and display the main program window.

//

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)

{

HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)

{

return FALSE;

}

ShowWindow(hWnd, 3);

UpdateWindow(hWnd);

return TRUE;

}

//

// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)

//

// PURPOSE: Processes messages for the main window.

//

// WM_COMMAND - process the application menu

// WM_PAINT - Paint the main window

// WM_DESTROY - post a quit message and return

//

//

static wchar_t szFileName[_MAX_PATH];

static wchar_t szTitleName[_MAX_FNAME + _MAX_EXT];

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

int wmId, wmEvent;

PAINTSTRUCT ps;

HDC hdc;

int x1,y1;

static bool first = true;

if(first)

{

srand(time(NULL));

first = false;

num=6;

arr = new Deputy*[num];

setlocale(LC_ALL,"Ukrainian");

arr[0] = new Deputy( "Яценюк",rand()%800+100,rand()%500+100);

arr[1] = new Deputy( "Тигiпко",rand()%800+100,rand()%500+100);

arr[2] = new Vyla( "Ляшко",rand()%800+100,rand()%500+100);

arr[3] = new Lider_par( "Кличко",rand()%800+100,rand()%500+100);

arr[4] = new Lider_par( "Тягнибок",rand()%800+100,rand()%500+100);

arr[5] = new Spiker( "Рибак",rand()%800+100,rand()%500+100);

timerid=SetTimer( hWnd, TIMER_7SEC, 1, NULL);

}

switch (message)

{

case WM_COMMAND:

wmId = LOWORD(wParam);

wmEvent = HIWORD(wParam);

// Parse the menu selections:

switch (wmId)

{

case IDM_ABOUT:

DialogBox(hInst, MAKEINTRESOURCE(ABOUT1), hWnd, About);

break;

case IDM_EXIT:

DestroyWindow(hWnd);

break;

case ID_NEWOBJ:

::DialogBox(hInst, MAKEINTRESOURCE(IDD_ADDOBJ), hWnd, AddObj);

break;

case IDM_SUR:

memset(&ofn,0,sizeof(ofn) );

GetCurrentDirectory( sizeof(szFileName), szFileName );

wcscat( szFileName, L"\\*.*" );

ofn.lStructSize = sizeof(ofn);

ofn.hwndOwner = NULL; //hWnd;

ofn.lpstrFile = szFileName;

ofn.lpstrFile[0]=L'\0';

ofn.nMaxFile = sizeof(szFileName);

ofn.lpstrFilter = L"All\0*.*\0Text\0*.TXT\0";

ofn.nFilterIndex = 1;

ofn.lpstrFileTitle = NULL;

ofn.lpstrInitialDir = NULL;

ofn.Flags = OFN_PATHMUSTEXIST;

ofn.Flags = OFN_CREATEPROMPT;

if( GetSaveFileName(&ofn) )

{

::MessageBoxW(hWnd,(LPCWSTR)ofn.lpstrFile,L"File name", MB_OK );

char buffer[200];

wcstombs ( buffer, (LPCWSTR)ofn.lpstrFile, sizeof(buffer) );

ofstream ofs (buffer, std::ofstream::out );

ofs<<num<<endl;

for(int i=0;i<num;++i)

{

if(arr[i]->type==1)

{

ofs<<arr[i]->type<<" "<<arr[i]->name<<" "<<" "<<arr[i]->x<<" "<<arr[i]->y<<endl;

}

if(arr[i]->type==2)

{

ofs<<arr[i]->type<<" "<<arr[i]->name<<" "<<" "<<arr[i]->x<<" "<<arr[i]->y<<endl;

}

if(arr[i]->type==3)

{

ofs<<arr[i]->type<<" "<<arr[i]->name<<" "<<" "<<arr[i]->x<<" "<<arr[i]->y<<endl;

}

if(arr[i]->type==4)

{

ofs<<arr[i]->type<<" "<<arr[i]->name<<" "<<" "<<arr[i]->x<<" "<<arr[i]->y<<endl;

}

}

ofs.close();

}

break;

case IDM_DES:

memset(&ofn,0,sizeof(ofn) );

GetCurrentDirectory( sizeof(szFileName), szFileName );

wcscat( szFileName, L"\\*.*" );

ofn.lStructSize = sizeof(ofn);

ofn.hwndOwner = NULL; //hWnd;

ofn.lpstrFile = szFileName;

ofn.lpstrFile[0]=L'\0';

ofn.nMaxFile = sizeof(szFileName);

ofn.lpstrFilter = L"All\0*.*\0Text\0*.TXT\0";

ofn.nFilterIndex = 1;

ofn.lpstrFileTitle = NULL;

ofn.nMaxFileTitle = 0;

ofn.lpstrInitialDir = NULL;

ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

int type,x,y;

char name[100];

ofn.lpstrFileTitle = L"Open model";

if( GetOpenFileName(&ofn) )

{

char buffer[200];

char buf[100];

wcstombs ( buffer, (LPCWSTR)ofn.lpstrFile, sizeof(buffer) );

ifstream ifs;

ifs.open( buffer );

if( ifs.is_open() )

{

ifs>>num;

ifs.getline( buf, sizeof(buf), '\n' );

for(int i=0;i<num;++i)

{

ifs>>type;

if(type==1)

{

ifs>>name>>x>>y;

ifs.getline( buf, sizeof(buf), '\n' );

arr[i]=new Deputy(name,x,y);

}

if(type==2)

{

ifs>>name>>x>>y;

ifs.getline( buf, sizeof(buf), '\n' );

arr[i]=new Lider_par(name,x,y);

}

if(type==3)

{

ifs>>name>>x>>y;

ifs.getline( buf, sizeof(buf), '\n' );

arr[i]=new Vyla(name,x,y);

}

if(type==4)

{

ifs>>name>>x>>y;

ifs.getline( buf, sizeof(buf), '\n' );

arr[i]=new Spiker(name,x,y);

}

}

}}

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

break;

case WM_TIMER:

::GetClientRect( hWnd, &rect );

for(int i=0;i<num;i++)

if(arr[i]->active == false) arr[i]->move_timer(hWnd);

break;

case WM_KEYDOWN:

switch(wParam)

{

case VK_UP:

if(rad.active==true)

rad.moveto(0,-5);

if(mit.active==true)

mit.moveto(0,-5);

for(int i=0;i<num;i++)

{

if((arr[i])->active==true)

arr[i]->moveto(0,-5);

}

InvalidateRect(hWnd, 0, false) ;

break;

case VK_DOWN:

if(rad.active==true)

rad.moveto(0,5);

if(mit.active==true)

mit.moveto(0,5);

for(int i=0;i<num;i++)

{

if((arr[i])->active==true)

arr[i]->moveto(0,5);

}

InvalidateRect(hWnd, 0, false) ;

break;

case VK_RIGHT:

if(rad.active==true)

rad.moveto(5,0);

if(mit.active==true)

mit.moveto(5,0);

for(int i=0;i<num;i++)

{

if((arr[i])->active==true)

arr[i]->moveto(5,0);

}

InvalidateRect(hWnd, 0, false) ;

break;

case VK_LEFT:

if(rad.active==true)

rad.moveto(-5,0);

if(mit.active==true)

mit.moveto(-5,0);

for(int i=0;i<num;i++)

{

if((arr[i])->active==true)

arr[i]->moveto(-5,0);

}

InvalidateRect(hWnd, 0,false) ;

break;

case VK_INSERT:

{

DialogBox(hInst, MAKEINTRESOURCE(IDD_ADDOBJ), hWnd,AddObj);

::InvalidateRect(hWnd,NULL,false);

}

break;

case VK_ESCAPE://деактивація виділеного обєкта

rad.active=false;

mit.active=false;

for(int i=0;i<num;i++)

{

arr[i]->active=false;

}

InvalidateRect(hWnd, 0, false) ;

break;

case VK_DELETE://видалення обєкта

int p;

for(int i=0;i<num;i++)

if(arr[i]->active==true)

{

p=i;

delete arr[p];

for(int i=p;i<num-1;i++)

arr[i]=arr[i+1];

num--;

}

InvalidateRect(hWnd, 0, false) ;

break;

case '1'://створення звичайного депутата

{

Deputy **arr1=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr1[i]=arr[i];

arr1[num]=new Deputy;

delete [] arr;

num++;

arr=arr1;

InvalidateRect(hWnd, 0, false) ;

break;

}

case '2'://створення лідера партії

{

Deputy **arr2=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr2[i]=arr[i];

arr2[num]=new Lider_par;

delete [] arr;

num++;

arr=arr2;

InvalidateRect(hWnd, 0, false) ;

break;

}

case '3'://створення Ляшка, якшо його було видалено

{

for(int i =0;i<num;i++)

{

if(arr[i]->new_vyla()==true)break;

if(arr[i]->new_vyla()==false&&i==(num-1))

{

Deputy **arr3=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr3[i]=arr[i];

arr3[num]=new Vyla;

delete [] arr;

num++;

arr=arr3;

}

}

InvalidateRect(hWnd, 0, false) ;

break;

}

case '4'://створення спікера, якшо його було видалено

{

for(int i =0;i<num;i++)

{

if(arr[i]->new_spiker()==true)break;

if(arr[i]->new_spiker()==false&&i==(num-1))

{

Deputy **arr5=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr5[i]=arr[i];

arr5[num]=new Spiker;

delete [] arr;

num++;

arr=arr5;

}

}

InvalidateRect(hWnd, 0, false) ;

break;

}

case 'R'://створення нового обєкта якщо виділений спікер

case 'r':

{

for(int i=0;i<num;i++)

{

if(arr[i]->active==true)

{

arr[i]->add_new_deputy();

}

}

InvalidateRect(hWnd, 0, false) ;

break;

}

case 'K'://вбивство Ляшком іншого депутата

case 'k':

{

{

for(int i=0;i<num;i++)

if (arr[i]->active==true)

arr[i]->kill(i);

}

InvalidateRect(hWnd, 0, false) ;

break;

}

case 'P'://скликання парламенту спікером

case 'p':

{

{

for(int i=0;i<num;i++)

if (arr[i]->active==true)

arr[i]->all_parlament();

}

InvalidateRect(hWnd, 0, false) ;

break;

}

}

case WM_LBUTTONDOWN: //виділення обєкта

x1=LOWORD(lParam);

y1=HIWORD(lParam);

for(int i=0;i<num;i++)

{

if(arr[i]->select_obj(x1,y1)==true)

{

arr[i]->active=true;

rad.active=false;

mit.active=false;

for(int j=0;j<num;j++)

{

if(j!=i)

arr[j]->active=false;

}

}

}

InvalidateRect(hWnd, 0,false) ;

break;

case WM_RBUTTONDOWN: //виділення макрообєкта

x1=LOWORD(lParam);

y1=HIWORD(lParam);

if(rad.select_obj(x1,y1)==true)

{

rad.active=true;

mit.active=false;

for(int i=0;i<num;i++)

{

arr[i]->active=false;

}

for(int i=0;i<num;i++)

{

if(arr[i]->x-35>=rad.x-300&&arr[i]->x+35<=rad.x+300&&arr[i]->y-40>=rad.y-400&&arr[i]->y+145<=rad.y+220)

{

arr[i]->active=true;

}

}

}

if(mit.select_obj(x1,y1)==true)

{

mit.active=true;

rad.active=false;

for(int i=0;i<num;i++)

{

arr[i]->active=false;

}

for(int i=0;i<num;i++)

{

if(arr[i]->x-35>=mit.x-50&&arr[i]->x+35<=mit.x+250&&arr[i]->y-40>=mit.y-50&&arr[i]->y+145<=mit.y+350)

{

arr[i]->active=true;

}

}

}

InvalidateRect(hWnd, 0, false) ;

break;

case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);

RECT rec;

HDC hdcMem;

HBITMAP hMemBitmap;

::GetClientRect(hWnd, &rec );

hdcMem = CreateCompatibleDC(hdc);

hMemBitmap = CreateCompatibleBitmap(hdc, rec.right, rec.bottom );

SelectObject(hdcMem,hMemBitmap);

::Rectangle(hdcMem, rec.left, rec.top, rec.right, rec.bottom );

rad.Draw(hdcMem);

l=0;g=0;c=0;

mit.Draw(hdcMem,l,g,c);

for(int i=0;i<num;i++)

arr[i]->Draw(hdcMem);

::StretchBlt(hdc, rec.left, rec.top, rec.right, rec.bottom, hdcMem, rec.left, rec.top, rec.right, rec.bottom, SRCCOPY);

::DeleteObject( hMemBitmap );

::DeleteDC( hdcMem );

EndPaint(hWnd, &ps);

break;

case WM_DESTROY:

KillTimer(hWnd, TIMER_7SEC);

PostQuitMessage(0);

for(int i=0; i<num; i++)

{

delete arr[i];

}

delete [] arr;

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

return 0;

}

// Message handler for about box.

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

UNREFERENCED_PARAMETER(lParam);

HWND hwndCtrl;

switch (message)

{

case WM_INITDIALOG:

hwndCtrl= ::GetDlgItem(hDlg, IDC_STATIC);

return (INT_PTR)TRUE;

case WM_COMMAND:

if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)

{

EndDialog(hDlg, LOWORD(wParam));

return (INT_PTR)TRUE;

}

break;

}

return (INT_PTR)FALSE;

}

INT_PTR CALLBACK AddObj (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

HWND hwndCtrl;

char name[20];

int x,y;

char buf[20];

UNREFERENCED_PARAMETER(lParam);

switch (message)

{

case WM_INITDIALOG:

hwndCtrl= ::GetDlgItem(hDlg, IDC_RADIO1);

hwndCtrl= ::GetDlgItem(hDlg, IDC_RADIO2);

hwndCtrl= ::GetDlgItem(hDlg, IDC_RADIO3);

hwndCtrl= ::GetDlgItem(hDlg, IDC_RADIO4);

hwndCtrl= ::GetDlgItem(hDlg, IDC_CHECK2);

hwndCtrl= ::GetDlgItem(hDlg, IDC_EDIT1);

hwndCtrl= ::GetDlgItem(hDlg, IDC_EDIT2);

hwndCtrl= ::GetDlgItem(hDlg, IDC_EDIT3);

return (INT_PTR)TRUE;

case WM_COMMAND:

if (LOWORD(wParam) == IDOK)

{

hwndCtrl = GetDlgItem(hDlg, IDC_CHECK2);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO1);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

Deputy **arr1=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr1[i]=arr[i];

arr1[num]=new Deputy;

delete [] arr;

num++;

arr=arr1;

}

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO2);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

Deputy **arr1=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr1[i]=arr[i];

arr1[num]=new Lider_par;

delete [] arr;

num++;

arr=arr1;

}

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO3);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

for(int i =0;i<num;i++)

{

if(arr[i]->new_vyla()==true)break;

if(arr[i]->new_vyla()==false&&i==(num-1))

{

Deputy **arr3=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr3[i]=arr[i];

arr3[num]=new Vyla;

delete [] arr;

num++;

arr=arr3;

}

}

}

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO4);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

for(int i =0;i<num;i++)

{

if(arr[i]->new_spiker()==true)break;

if(arr[i]->new_spiker()==false&&i==(num-1))

{

Deputy **arr5=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr5[i]=arr[i];

arr5[num]=new Spiker;

delete [] arr;

num++;

arr=arr5;

}

}

}

::InvalidateRect(hDlg,NULL,false);

}

hwndCtrl = GetDlgItem(hDlg, IDC_CHECK2);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 0)

{

hwndCtrl = GetDlgItem(hDlg, IDC_EDIT1);

::GetWindowTextA( hwndCtrl, (LPSTR)buf, 50 );

sscanf(buf,"%i",&x);

hwndCtrl = GetDlgItem(hDlg, IDC_EDIT2);

::GetWindowTextA( hwndCtrl, (LPSTR)buf, 50 );

sscanf(buf,"%i",&y);

hwndCtrl = GetDlgItem(hDlg, IDC_EDIT3);

::GetWindowTextA( hwndCtrl, (LPSTR)name, 50 );

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO1);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

Deputy **arr1=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr1[i]=arr[i];

arr1[num]=new Deputy(name,x,y);

delete [] arr;

num++;

arr=arr1;

}

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO2);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

Deputy **arr1=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr1[i]=arr[i];

arr1[num]=new Lider_par(name,x,y);

delete [] arr;

num++;

arr=arr1;

}

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO3);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

for(int i =0;i<num;i++)

{

if(arr[i]->new_vyla()==true)break;

if(arr[i]->new_vyla()==false&&i==(num-1))

{

Deputy **arr3=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr3[i]=arr[i];

arr3[num]=new Vyla(name,x,y);

delete [] arr;

num++;

arr=arr3;

}

}

}

hwndCtrl = GetDlgItem(hDlg, IDC_RADIO4);

if (SendMessage(hwndCtrl, BM_GETCHECK, 0, 0) == 1)

{

for(int i =0;i<num;i++)

{

if(arr[i]->new_spiker()==true)break;

if(arr[i]->new_spiker()==false&&i==(num-1))

{

Deputy **arr5=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr5[i]=arr[i];

arr5[num]=new Spiker(name,x,y);

delete [] arr;

num++;

arr=arr5;

}

}

}

::InvalidateRect(hDlg,NULL,false);

}

EndDialog(hDlg, LOWORD(wParam));

return (INT_PTR)TRUE;

}

if (LOWORD(wParam) == IDCANCEL)

{

EndDialog(hDlg, LOWORD(wParam));

return (INT_PTR)TRUE;

}

::InvalidateRect(hDlg,NULL,false);

break;

}

return (INT_PTR)FALSE;

}

Додаток В

Лістинг модуля func.cpp

#include "stdafx.h"

#include "class.h"

Deputy **arr;

Rada rad;

int num;

Mityng mit;

int dx=1,p=1,p2;

void Deputy::Draw(HDC hdc)

{

HBRUSH hbr;

HPEN hpen;

hpen = CreatePen(PS_SOLID,0,RGB(0,0,0));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(250,248,186));//holova

SelectObject(hdc,hbr);

::Ellipse(hdc,x-12,y-17,x+12,y+12);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(0,0,0));//kostyum

SelectObject(hdc,hbr);

POINT p1[4]={x-20,y+12,x-35,y+40,x-22,y+40,x-20,y+32};

POINT p1_2[4]={x+20,y+12,x+35,y+40,x+22,y+40,x+20,y+32};

POINT p2[4]={x-35,y+40,x-35,y+70,x-25,y+70,x-22,y+40};

POINT p2_2[4]={x+35,y+40,x+35,y+70,x+25,y+70,x+22,y+40};

POINT p3[4]={x-20,y+75,x-20,y+140,x-5,y+140,x,y+75};

POINT p3_2[4]={x+20,y+75,x+20,y+140,x+5,y+140,x,y+25};

::Polygon(hdc,p1,4);::Polygon(hdc,p1_2,4);

::Polygon(hdc,p2,4);::Polygon(hdc,p2_2,4);

::Polygon(hdc,p3,4);::Polygon(hdc,p3_2,4);

::Rectangle(hdc,x-20,y+12,x+20,y+75);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(0,0,0));//ochi

SelectObject(hdc,hbr);

::Ellipse(hdc,x-7,y-6,x-2,y-4);::Ellipse(hdc,x+7,y-6,x+2,y-4);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(255,255,255));//sorochka

SelectObject(hdc,hbr);

POINT p4[3]={x-10,y+12,x,y+40,x+10,y+12};

::Polygon(hdc,p4,3);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(233,122,122));//huby

SelectObject(hdc,hbr);

POINT p5[5]={x-5,y+4,x-2,y+6,x+2,y+6,x+5,y+4,x-5,y+4};

::Polygon(hdc,p5,5);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(0,0,0));//text

::SelectObject(hdc,hbr);

::TextOutA(hdc,x-25,y-40,name,strlen(name));

::DeleteObject(hbr);

::DeleteObject(hpen);

if(active==true)

{

HPEN hpen1;

hpen1 = CreatePen(PS_SOLID,2,RGB(0,0,255));

SelectObject(hdc,hpen1);

::MoveToEx(hdc,x-35,y-40,NULL);

::LineTo(hdc,x-35,y+145);

::LineTo(hdc,x+35,y+145);

::LineTo(hdc,x+35,y-40);

::LineTo(hdc,x-35,y-40);

::DeleteObject(hpen1);

}

}

void Lider_par::Draw(HDC hdc)

{

Deputy::Draw(hdc);

HBRUSH hbr;

HPEN hpen;

hpen = CreatePen(PS_SOLID,0,RGB(0,0,0));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(244,227,200));//okulyary

SelectObject(hdc,hbr);

MoveToEx(hdc,x-8,y-5,NULL);::LineTo(hdc,x-11,y-10);

MoveToEx(hdc,x+8,y-5,NULL);::LineTo(hdc,x+11,y-10);

POINT p_ok1[5]={x-8,y-8,x-8,y-3,x-1,y-3,x-1,y-8,x-8,y-8};

POINT p_ok2[5]={x+8,y-8,x+8,y-3,x+1,y-3,x+1,y-8,x+8,y-8};

::Polygon(hdc,p_ok1,5);::Polygon(hdc,p_ok2,5);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(0,0,0));//ochi

SelectObject(hdc,hbr);

::Ellipse(hdc,x-7,y-6,x-2,y-4);::Ellipse(hdc,x+7,y-6,x+2,y-4);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(221,172,253));//sorochka

SelectObject(hdc,hbr);

POINT p4[3]={x-10,y+12,x,y+40,x+10,y+12};

::Polygon(hdc,p4,3);

::DeleteObject(hbr);

::DeleteObject(hpen);

}

void Vyla::Draw(HDC hdc)

{

Lider_par::Draw(hdc);

HBRUSH hbr;

HPEN hpen;

hpen = CreatePen(PS_SOLID,2,RGB(0,5,0));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(78,52,39));//Vyla

SelectObject(hdc,hbr);

::Rectangle(hdc,x-30,y+140,x-25,y+10);

Arc(hdc, x-40, y+10, x-15, y-20, x-300, y-210, x+300, y-210);

::MoveToEx(hdc,x-28,y-15,NULL);LineTo(hdc,x-28,y+10);

::DeleteObject(hbr);

::DeleteObject(hpen);

}

void Spiker::Draw(HDC hdc)

{

Lider_par::Draw(hdc);

HBRUSH hbr;

HPEN hpen;

hpen = CreatePen(PS_SOLID,0,RGB(128,128,128));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(128,128,128));

SelectObject(hdc,hbr);

POINT p1[4]={x-20,y+12,x-35,y+40,x-22,y+40,x-20,y+32};

POINT p1_2[4]={x+20,y+12,x+35,y+40,x+22,y+40,x+20,y+32};

POINT p2[4]={x-35,y+40,x-35,y+70,x-25,y+70,x-22,y+40};

POINT p2_2[4]={x+35,y+40,x+35,y+70,x+25,y+70,x+22,y+40};

POINT p3[4]={x-20,y+75,x-20,y+140,x-5,y+140,x,y+75};

POINT p3_2[4]={x+20,y+75,x+20,y+140,x+5,y+140,x,y+25};

::Polygon(hdc,p1,4);::Polygon(hdc,p1_2,4);

::Polygon(hdc,p2,4);::Polygon(hdc,p2_2,4);

::Polygon(hdc,p3,4);::Polygon(hdc,p3_2,4);

::Rectangle(hdc,x-20,y+12,x+20,y+75);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(221,172,253));//sorochka

SelectObject(hdc,hbr);

POINT p4[3]={x-10,y+12,x,y+40,x+10,y+12};

::Polygon(hdc,p4,3);

::DeleteObject(hbr);

::DeleteObject(hpen);

}

void Rada::Draw(HDC hdc)

{

HBRUSH hbr;

HPEN hpen;

hpen = CreatePen(PS_SOLID,0,RGB(0,0,0));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(192,192,192));

SelectObject(hdc,hbr);

::Rectangle(hdc,x-300,y-400,x+300,y+220);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(140,81,0));

SelectObject(hdc,hbr);

Pie(hdc, x-300, y-750, x+300, y+200, x-300, y-210, x+300, y-210);

::DeleteObject(hbr);

::DeleteObject(hpen);

hpen = CreatePen(PS_SOLID,2,RGB(94,54,0));

SelectObject(hdc,hpen);

Arc(hdc, ((x-200)+(x-100))/2, ((y-550)+(y-350))/2, ((x+200)+(x+100))/2, ((y)+(y-200))/2, x-300, y-210, x+300, y-210);

Arc(hdc, ((x-200)+((x-200)+(x-100))/2)/2,((y-550)+((y-550)+(y-350))/2)/2,((x+200)+((x+200)+(x+100))/2)/2,

(y+((y)+(y-200))/2)/2,x-300,y-210,x+300,y-210);

Arc(hdc, ((x-100)+((x-200)+(x-100))/2)/2,((y-350)+((y-550)+(y-350))/2)/2,((x+100)+((x+200)+(x+100))/2)/2,

((y-200)+((y)+(y-200))/2)/2,x-300,y-210,x+300,y-210);

Arc(hdc, ((x-200)+(x-300))/2, ((y-550)+(y-750))/2, ((x+200)+(x+300))/2, ((y)+(y+200))/2, x-300, y-210, x+300, y-210);

Arc(hdc, ((x-200)+((x-200)+(x-300))/2)/2,((y-550)+((y-550)+(y-750))/2)/2,((x+200)+((x+200)+(x+300))/2)/2,

(y+((y)+(y+200))/2)/2,x-300,y-210,x+300,y-210);

Arc(hdc, ((x-300)+((x-200)+(x-300))/2)/2,((y-750)+((y-550)+(y-750))/2)/2,((x+300)+((x+200)+(x+300))/2)/2,

((y+200)+((y)+(y+200))/2)/2,x-300,y-210,x+300,y-210);

::DeleteObject(hpen);

hpen = CreatePen(PS_SOLID,8,RGB(94,54,0));

SelectObject(hdc,hpen);

Arc(hdc, x-300, y-750, x+300, y+200, x-300, y-210, x+300, y-210);

Arc(hdc, x-190, y-560, x+190, y-10, x-300, y-200, x+300, y-200);

::DeleteObject(hpen);

hpen = CreatePen(PS_SOLID,0,RGB(192,192,192));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(192,192,192));

SelectObject(hdc,hbr);

Pie(hdc, x-100, y-350, x+100, y-200, x-300, y-210, x+300, y-210);

::DeleteObject(hpen);

hpen = CreatePen(PS_SOLID,30,RGB(192,192,192));

SelectObject(hdc,hpen);

::MoveToEx(hdc,x,y-275,NULL);

::LineTo(hdc,x,y+200);

::DeleteObject(hpen);

hpen = CreatePen(PS_SOLID,20,RGB(192,192,192));

SelectObject(hdc,hpen);

::MoveToEx(hdc,x,y-275,NULL);

::LineTo(hdc,x+270,y-20);

::MoveToEx(hdc,x,y-275,NULL);

::LineTo(hdc,x-270,y-20);

Arc(hdc, x-200, y-550, x+200, y, x-300, y-210, x+300, y-210);

::DeleteObject(hpen);

::DeleteObject(hbr);

hpen = CreatePen(PS_SOLID,0,RGB(94,54,0));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(140,81,0));

SelectObject(hdc,hbr);

::Rectangle(hdc,x-70,y-300,x+70,y-255);

POINT p1[4]={x-70,y-300,x-75,y-310,x+75,y-310,x+70,y-300};

::Polygon(hdc,p1,4);

POINT p2[4]={x-70,y-255,x-75,y-265,x-75,y-310,x-70,y-300};

::Polygon(hdc,p2,4);

POINT p3[4]={x+70,y-255,x+75,y-265,x+75,y-310,x+70,y-300};

::Polygon(hdc,p3,4);

::DeleteObject(hbr);

::DeleteObject(hpen);

hbr = CreateSolidBrush(RGB(191,0,0));

SelectObject(hdc,hbr);

Rectangle(hdc,x-10,y-330,x+10,y-310);

Rectangle(hdc,x-50,y-330,x-30,y-310);

Rectangle(hdc,x+30,y-330,x+50,y-310);

::DeleteObject(hbr);

::TextOutA(hdc,x-53,y-295,name,strlen(name));

if(active==true)

{

HPEN hpen1;

hpen1 = CreatePen(PS_SOLID,2,RGB(0,0,255));

SelectObject(hdc,hpen1);

::MoveToEx(hdc,x-300,y-400,NULL);

::LineTo(hdc,x-300,y+220);

::LineTo(hdc,x+300,y+220);

::LineTo(hdc,x+300,y-400);

::LineTo(hdc,x-300,y-400);

::DeleteObject(hpen1);

}

}

void Mityng::Draw(HDC hdc,int i,int g,int c)

{ HBRUSH hbr;

HPEN hpen;

for(g=0;g<=200;g+=40)

{

c=100;

for(i=0;i<=200;i+=40,c+=50)

{

hpen = CreatePen(PS_SOLID,0,RGB(0,0,0));

SelectObject(hdc,hpen);

hbr = CreateSolidBrush(RGB(237,188,18));//holova

SelectObject(hdc,hbr);

::Ellipse(hdc,x-12+i,y-17+g,x+12+i,y+12+g);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(c,c,100));//kostyum

SelectObject(hdc,hbr);

POINT p1[4]={x-20+i,y+12+g,x-35+i,y+40+g,x-22+i,y+40+g,x-20+i,y+32+g};

POINT p1_2[4]={x+20+i,y+12+g,x+35+i,y+40+g,x+22+i,y+40+g,x+20+i,y+32+g};

POINT p2[4]={x-35+i,y+40+g,x-35+i,y+70+g,x-25+i,y+70+g,x-22+i,y+40+g};

POINT p2_2[4]={x+35+i,y+40+g,x+35+i,y+70+g,x+25+i,y+70+g,x+22+i,y+40+g};

POINT p3[4]={x-20+i,y+75+g,x-20+i,y+140+g,x-5+i,y+140+g,x+i,y+75+g};

POINT p3_2[4]={x+20+i,y+75+g,x+20+i,y+140+g,x+5+i,y+140+g,x+i,y+25+g};

::Polygon(hdc,p1,4);::Polygon(hdc,p1_2,4);

::Polygon(hdc,p2,4);::Polygon(hdc,p2_2,4);

::Polygon(hdc,p3,4);::Polygon(hdc,p3_2,4);

::Rectangle(hdc,x-20+i,y+12+g,x+20+i,y+75+g);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(0,0,0));//ochi

SelectObject(hdc,hbr);

::Ellipse(hdc,x-7+i,y-6+g,x-2+i,y-4+g);::Ellipse(hdc,x+7+i,y-6+g,x+2+i,y-4+g);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(c,c,255));//sorochka

SelectObject(hdc,hbr);

POINT p4[3]={x-10+i,y+12+g,x+i,y+40+g,x+10+i,y+12+g};

::Polygon(hdc,p4,3);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(233,122,122));//huby

SelectObject(hdc,hbr);

POINT p5[5]={x-5+i,y+4+g,x-2+i,y+6+g,x+2+i,y+6+g,x+5+i,y+4+g,x-5+i,y+4+g};

::Polygon(hdc,p5,5);

::DeleteObject(hbr);

hbr = CreateSolidBrush(RGB(255,255,255));

SelectObject(hdc,hbr);

::Rectangle(hdc,x+50,y-40,x+150,y+30);

::TextOutA(hdc,x+60,y-20,name,strlen(name));

::DeleteObject(hbr);

::DeleteObject(hpen);

if(active==true)

{

HPEN hpen1;

hpen1 = CreatePen(PS_SOLID,2,RGB(0,0,255));

SelectObject(hdc,hpen1);

::MoveToEx(hdc,x-50,y-50,NULL);

::LineTo(hdc,x-50,y+350);

::LineTo(hdc,x+250,y+350);

::LineTo(hdc,x+250,y-50);

::LineTo(hdc,x-50,y-50);

::DeleteObject(hpen1);

}

}

}

}

int Vyla::KILL(int i)

{

for(int j=0;j<num;j++)

{

if(i==j)j++;

if(arr[j]->active==false&&arr[i]->x-35>arr[j]->x-35&&arr[i]->x-35<arr[j]->x+35&&arr[i]->y-40>arr[j]->y-40&&

arr[i]->y-40<arr[j]->y+145)

{

p2=j;

delete arr[p2];

for(int j=p2;j<num-1;j++)

arr[j]=arr[j+1];

num--;

}

}

return 0;

}

bool Deputy::select_obj(int x1,int y1)//перевірка чи виділений депутат

{

if(x1<=x+35 && x1>=x-35 && y1<=y+145 && y1>=y-4)

return true;

else return false;

}

void Deputy::moveto(int x1, int y1)//рух депутата

{

x=x+x1;

y=y+y1;

}

bool Rada::select_obj(int x1,int y1)//перевірка чи виділена рада

{

if(x1<=x+300 && x1>=x-300 && y1<=y+220 && y1>=y-400)

return true;

else return false;

}

bool Mityng::select_obj(int x1,int y1)//перевірка чи виділений міинг

{

if(x1<=x+250 && x1>=x-50 && y1<=y+350 && y1>=y-50)

return true;

else return false;

}

void Rada::moveto(int x1, int y1)//рух ради

{

x=x+x1;

y=y+y1;

}

void Mityng::moveto(int x1, int y1)//рух мітинга

{

x=x+x1;

y=y+y1;

}

//використання dynamic_cast<>

int Deputy::add_new_deputy()//перевірка чи даний активний обєкт явлється cпікером який може призвати нових депутатів

{

if(this->active==true)

{

Lider_par *pd = dynamic_cast<Lider_par *>(this);

Spiker *ph = dynamic_cast<Spiker *>(this);

Vyla *pk = dynamic_cast<Vyla *>(this);

if( pd!=NULL&&ph==NULL&&pk==NULL ){ pd->newdep();return 0;}

}

return 0;

};

int Lider_par:: newdep()

{

Deputy **arr4=new Deputy*[num+1];

for(int i=0;i<num;i++)

arr4[i]=arr[i];

arr4[num]=new Deputy;

delete [] arr;

num++;

arr=arr4;

return 0;

}

int Spiker::parlament()

{

for(int i=0;i<num;i++)

{

arr[i]->x=rand()%400+(rad.x-200);

arr[i]->y=rand()%320+(rad.y-300);

}

return 0;

}

int Deputy::all_parlament()

{

Spiker *pd = dynamic_cast<Spiker *>(this);

if( pd != NULL ){ pd->parlament();return 0;}

return 0;

}

bool Deputy::new_spiker()

{

Spiker *pd = dynamic_cast<Spiker *>(this);

if( pd != NULL ) return true;

return false;

}

bool Deputy::new_vyla()

{

Vyla *pd = dynamic_cast<Vyla *>(this);

if( pd != NULL ) return true;

return false;

}

int Deputy::kill(int i)

{

Vyla *pd = dynamic_cast<Vyla *>(this);

if( pd != NULL ) {pd->KILL(i);return 0;}

return 0;

}

void Deputy::move_timer(HWND hWnd)

{

belong=false;

if(x-35>=rad.x-300&&x+35<=rad.x+300&&y-40>=rad.y-400&&y+145<=rad.y+220)

{

belong=true;

if(x-35>rad.x-300&&x+35!=rad.x+300&&y-40!=rad.y-400&&y+145!=rad.y+220)x--;

if(x-35==rad.x-300)y--;

if(y-40==rad.y-400)x++;

if(x+35==rad.x+300)y++;

if(y+145==rad.y+220)x--;

}

if(x-35>=mit.x-50&&x+35<=mit.x+250&&y-40>=mit.y-50&&y+145<=mit.y+350)

{

belong=true;

if(x-35>mit.x-50&&x+35!=mit.x+250&&y-40!=mit.y-50&&y+145!=mit.y+350)x--;

if(x-35==mit.x-50)y--;

if(y-40==mit.y-50)x++;

if(x+35==mit.x+250)y++;

if(y+145==mit.y+350)x--;

}

if(belong==false)

{

x+=dx;p++;

if(p==300){dx=-1;p=-300;}

if(p==0){dx=1;p++;}

}

::InvalidateRect(hWnd, NULL, false);

};

Рисунок 3.7 – Діаграма стану

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]