Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "windows.h"
- #include <list>
- namespace ships {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- using namespace System::Threading;
- using namespace System::Collections::Generic;
- /// <summary>
- /// Сводка для MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- Image^ ship1 = Image::FromFile("C:/Users/golubova/Desktop/ship1.png");
- Image^ ship1_2 = Image::FromFile("C:/Users/golubova/Desktop/ship_135.png");
- Image^ ship2 = Image::FromFile("C:/Users/golubova/Desktop/ship2.png");
- Image^ ship2_3 = Image::FromFile("C:/Users/golubova/Desktop/ship_225.png");
- Image^ ship3 = Image::FromFile("C:/Users/golubova/Desktop/ship3.png");
- Image^ ship3_4 = Image::FromFile("C:/Users/golubova/Desktop/ship_315.png");
- Image^ ship4 = Image::FromFile("C:/Users/golubova/Desktop/ship4.png");
- Image^ ship4_1 = Image::FromFile("C:/Users/golubova/Desktop/ship_45.png");
- int height, width;
- const double metrPerPixels = 2;
- int secondsPerModelStep = 1;
- double x1 = 0;
- double y1 = 0;
- int direction; //направление, в котором движется судно
- //1-восток, 2-юг, 3-запад, 4-север
- const int EAST = 1;
- const int SOUTH = 2;
- const int WEST = 3;
- const int NORTH = 4;
- double speed = 2; //м/c
- double FULL_SPEED = 2.0;
- const double SLOW_SPEED = 0.5;
- int shipMode; //режим судна
- const int ROADS_MODE = 0; //0-на рейде
- const int FULL_SPEED_MODE = 1; //1-полный ход
- const int SLOW_SPEED_MODE = 2; //2-малый ход
- const int UNLOAD_MODE = 3; //3-разгрузка
- const int LOAD_MODE = 4; //4-загрузка
- int targetPointIndex = 0; //номер точки, к которой движется судно
- const int PASS_MAX_CAPACITY = 1000; //вместимость пассажиров
- const int PASS_CHARGE_RATE = 5; //посадка пассажиров в секунду
- int passengersOnBoard = PASS_MAX_CAPACITY;
- /*Список точек, к которым движется судно*/
- List<Tuple<int, int, int,int,double, String^>^>^ route = gcnew List<Tuple<int, int, int, int, double, String^>^>();
- bool isEmpty = false;
- void modelStep() //функция, описывающая движение судна
- {
- for (int k = 0; k < secondsPerModelStep; k++)
- {
- if (speed > 0)
- {
- int tx = route[targetPointIndex]->Item1;
- int ty = route[targetPointIndex]->Item2;
- double d = Math::Sqrt((x1 - tx)*(x1 - tx) + (y1 - ty)*(y1 - ty));
- if (d < speed)
- {
- if (targetPointIndex == route->Count - 1)
- {
- listBox1->Items->Add("Конец маршрута");
- return;
- }
- direction = route[targetPointIndex]->Item3;
- shipMode = route[targetPointIndex]->Item4;
- speed = route[targetPointIndex]->Item5;
- listBox1->Items->Add(route[targetPointIndex]->Item6);
- targetPointIndex++;
- x1 = tx;
- y1 = ty;
- continue;
- }
- if (direction == EAST)
- {
- x1 += speed;
- }
- else if (direction == SOUTH)
- {
- y1 += speed;
- }
- else if (direction == WEST)
- {
- x1 -= speed;
- }
- else
- {
- y1 -= speed;
- }
- }
- else if (shipMode == UNLOAD_MODE) //высадка пассажиров
- {
- if (passengersOnBoard >= PASS_CHARGE_RATE)
- {
- passengersOnBoard -= PASS_CHARGE_RATE;
- }
- else
- {
- passengersOnBoard = 0;
- }
- if (passengersOnBoard == 0)
- {
- shipMode = route[targetPointIndex+1]->Item4;
- listBox1->Items->Add(route[targetPointIndex+1]->Item6);
- speed = route[targetPointIndex + 1]->Item5;
- targetPointIndex++;
- }
- }
- else if (shipMode == LOAD_MODE) //посадка пассажиров
- {
- if (passengersOnBoard < PASS_MAX_CAPACITY)
- {
- passengersOnBoard += PASS_CHARGE_RATE;
- }
- if (passengersOnBoard >= PASS_MAX_CAPACITY)
- {
- passengersOnBoard = PASS_CHARGE_RATE;
- shipMode = route[targetPointIndex + 1]->Item4;
- listBox1->Items->Add(route[targetPointIndex + 1]->Item6);
- speed = route[targetPointIndex + 1]->Item5;
- targetPointIndex++;
- }
- }
- }
- }
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Timer^ timer1;
- private: System::Windows::Forms::TrackBar^ trackBar1;
- private: System::Windows::Forms::ListBox^ listBox1;
- private: System::Windows::Forms::PictureBox^ picPort;
- //private: System::Windows::Forms::PictureBox^ picPortKors; //временно убрана картинка порта
- protected:
- private: System::Windows::Forms::PictureBox^ picShip;
- private: System::ComponentModel::IContainer^ components;
- protected:
- protected:
- protected:
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->components = (gcnew System::ComponentModel::Container());
- System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
- this->picPort = (gcnew System::Windows::Forms::PictureBox());
- this->picShip = (gcnew System::Windows::Forms::PictureBox());
- this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
- this->trackBar1 = (gcnew System::Windows::Forms::TrackBar());
- this->listBox1 = (gcnew System::Windows::Forms::ListBox());
- //this->picPortKors = (gcnew System::Windows::Forms::PictureBox());
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->picPort))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->picShip))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->trackBar1))->BeginInit();
- //(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->picPortKors))->BeginInit();
- this->SuspendLayout();
- //
- // picPort
- //
- this->picPort->BackColor = System::Drawing::SystemColors::ActiveCaption;
- this->picPort->Dock = System::Windows::Forms::DockStyle::Fill;
- this->picPort->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"picPort.Image")));
- this->picPort->Location = System::Drawing::Point(0, 0);
- this->picPort->Name = L"picPort";
- this->picPort->Size = System::Drawing::Size(871, 613);
- this->picPort->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
- this->picPort->TabIndex = 0;
- this->picPort->TabStop = false;
- //
- // picShip
- //
- this->picShip->BackColor = System::Drawing::Color::LightSkyBlue;
- this->picShip->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"picShip.Image")));
- this->picShip->Location = System::Drawing::Point(0, 12);
- this->picShip->Name = L"picShip";
- this->picShip->Size = System::Drawing::Size(51, 20);
- this->picShip->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
- this->picShip->TabIndex = 1;
- this->picShip->TabStop = false;
- this->picShip->Visible = false;
- this->picShip->Click += gcnew System::EventHandler(this, &MyForm::pictureBox2_Click);
- //
- // timer1
- //
- this->timer1->Enabled = true;
- this->timer1->Interval = 20;
- this->timer1->Tick += gcnew System::EventHandler(this, &MyForm::timer1_Tick);
- //
- // trackBar1
- //
- this->trackBar1->Location = System::Drawing::Point(660, 520);
- this->trackBar1->Maximum = 20;
- this->trackBar1->Minimum = 1;
- this->trackBar1->Name = L"trackBar1";
- this->trackBar1->Size = System::Drawing::Size(189, 69);
- this->trackBar1->TabIndex = 2;
- this->trackBar1->TickFrequency = 75;
- this->trackBar1->Value = 1;
- this->trackBar1->Scroll += gcnew System::EventHandler(this, &MyForm::trackBar1_Scroll);
- //
- // listBox1
- //
- this->listBox1->FormattingEnabled = true;
- this->listBox1->ItemHeight = 20;
- this->listBox1->Location = System::Drawing::Point(604, 50);
- this->listBox1->Name = L"listBox1";
- this->listBox1->Size = System::Drawing::Size(245, 84);
- this->listBox1->TabIndex = 3;
- /*
- // picPortKors
- //
- this->picPortKors->BackColor = System::Drawing::Color::Transparent;
- this->picPortKors->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"picPortKors.Image")));
- this->picPortKors->Location = System::Drawing::Point(190, 499);
- this->picPortKors->Name = L"picPortKors";
- this->picPortKors->Size = System::Drawing::Size(81, 56);
- this->picPortKors->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
- this->picPortKors->TabIndex = 5;
- this->picPortKors->TabStop = false;
- */
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(9, 20);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(871, 613);
- //this->Controls->Add(this->picPortKors);
- this->Controls->Add(this->listBox1);
- this->Controls->Add(this->trackBar1);
- this->Controls->Add(this->picShip);
- this->Controls->Add(this->picPort);
- this->Name = L"MyForm";
- this->Text = L"Модель захода морских судов в порт";
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->picPort))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->picShip))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->trackBar1))->EndInit();
- //(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->picPortKors))->EndInit();
- this->ResumeLayout(false);
- this->PerformLayout();
- /*Маршут точек, по которым движутся суда*/
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(0, 250, 1, FULL_SPEED_MODE, FULL_SPEED, "Режим полный ход")); //старт
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(375, 250, 2, SLOW_SPEED_MODE, SLOW_SPEED, "Режим малый ход"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(375, 400, 2, UNLOAD_MODE, 0, "Приступаю к разгрузке"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(375, 400, 2, LOAD_MODE, 0, "Приступаю к погрузке"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(375, 400, 2, SLOW_SPEED_MODE, SLOW_SPEED, "Режим малый ход"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(375, 520, 1, SLOW_SPEED_MODE, SLOW_SPEED, "Режим малый ход"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(700, 520, 4, SLOW_SPEED_MODE, SLOW_SPEED, "Режим малый ход"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(700, 200, 1, SLOW_SPEED_MODE, SLOW_SPEED, "Режим малый ход"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(800, 200, 1, FULL_SPEED_MODE, FULL_SPEED, "Режим полный ход"));
- route->Add(gcnew Tuple<int, int, int, int, double, String^>(1210, 200, 1, ROADS_MODE, 0, "Конец маршрута"));
- x1 = route[0]->Item1;
- y1 = route[0]->Item2;
- direction = route[0]->Item3;
- shipMode = route[0]->Item4;
- speed = route[0]->Item5;
- }
- #pragma endregion
- private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void pictureBox2_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
- modelStep();
- if (direction == EAST)
- {
- picShip->Image = ship1;
- picShip->Width = ship1->Width;
- picShip->Height = ship1->Height;
- }
- else if (direction == SOUTH)
- {
- picShip->Image = ship2;
- picShip->Width = ship2->Width;
- picShip->Height = ship2->Height;
- }
- else if (direction == WEST)
- {
- picShip->Image = ship3;
- picShip->Width = ship3->Width;
- picShip->Height = ship3->Height;
- }
- else
- {
- picShip->Image = ship4;
- picShip->Width = ship4->Width;
- picShip->Height = ship4->Height;
- }
- int leftUpCornerY = y1 / metrPerPixels - picShip->Height / 2; //смещение координат на центр картинки
- int leftUpCornerX = x1 / metrPerPixels - picShip->Width / 2;
- picShip->Top = leftUpCornerY;
- picShip->Left = leftUpCornerX;
- picShip->Visible = true;
- }
- private: System::Void trackBar1_Scroll(System::Object^ sender, System::EventArgs^ e)
- {
- secondsPerModelStep = trackBar1->Value; //изменение скорости модельного времени
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement