Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "TImage.h"
- #include "Cage.h"
- #include "Parrot.h"
- namespace ParrotInCage {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- public ref class MainForm : public Form
- {
- private:
- private: System::Windows::Forms::Button^ cageBtn;
- private: System::Windows::Forms::Button^ foodBtn;
- private: System::Windows::Forms::PictureBox^ cageBox;
- private: System::Windows::Forms::PictureBox^ parrotBox;
- Parrot^ parrot = gcnew Parrot();
- private: System::Windows::Forms::ProgressBar^ healthBar;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Timer^ timer1;
- private: System::Windows::Forms::Timer^ timer2;
- private: Cage^ cage = gcnew Cage();
- public:
- MainForm(void)
- {
- InitializeComponent();
- this->cageBox->Image = cage->getImage();
- this->cageBox->Size = this->cageBox->Image->Size;
- this->parrotBox->Image = parrot->getImage();
- this->parrotBox->Size = this->parrotBox->Image->Size;
- this->cageBtn->Click += gcnew EventHandler(this, &MainForm::moveClick);
- this->healthBar->Maximum = 1000;
- this->healthBar->Minimum = 0;
- this->healthBar->Value = 500;
- this->timer1->Tick += gcnew EventHandler(this, &MainForm::barInc);
- this->foodBtn->Click += gcnew EventHandler(this, &MainForm::onBtnFeed);
- this->timer2->Tick += gcnew EventHandler(this, &MainForm::flyTimer);
- }
- protected:
- ~MainForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::ComponentModel::IContainer^ components;
- protected:
- private:
- void barInc(System::Object^ sender, System::EventArgs^ e)
- {
- if (parrot->getEat())
- {
- healthBar->Value = healthBar->Maximum;
- parrot->setEat(false);
- timer1->Interval = 5000;
- }
- else if ( (healthBar->Value - 5 <= 0) )
- {
- healthBar->Value = 0;
- timer1->Enabled = false;
- }
- else
- {
- timer1->Interval = 100;
- healthBar->Increment(-1);
- }
- label1->Text = (healthBar->Value / 10).ToString() + "%";
- }
- private:
- void onBtnFeed(System::Object^ sender, System::EventArgs^ e)
- {
- if (!parrot->getFly() )
- {
- parrot->setEat(true);
- }
- }
- private:
- void moveClick(Object^ sender, EventArgs^ e)
- {
- if (this->cageBtn->Text == "Close")
- {
- this->cageBtn->Text = "Open";
- cage->setBool(false);
- cageBtn->Enabled = true;
- toFreeParrot(true);
- }
- else
- {
- this->cageBtn->Text = "Close";
- cage->setBool(true);
- cageBtn->Enabled = false;
- toFreeParrot(false);
- }
- }
- private:
- void flyTimer(System::Object^ sender, System::EventArgs^ e)
- {
- Point^ point = parrotBox->Location;
- if (parrot->getDirection())
- {
- if ((point->X > 10) && (point->Y > 50))
- {
- if (point->X == 450)
- {
- this->parrotBox->Image->RotateFlip(RotateFlipType::RotateNoneFlipX);
- }
- parrotBox->Location = Point(point->X - 1, point->Y - 1);
- }
- else if (point->X < 600)
- {
- if ( point->X <= 150)
- {
- Image^ img = parrotBox->Image;
- img->RotateFlip(RotateFlipType::Rotate180FlipXY);
- parrotBox->Image = img;
- }
- parrotBox->Location = Point(point->X + 2, point->Y);
- }
- if (point->X == 600)
- {
- Image^ img = parrotBox->Image;
- img->RotateFlip(RotateFlipType::RotateNoneFlipX);
- parrotBox->Image = img;
- parrot->setDirection(false);
- }
- }
- else
- {
- if (point->X > 150 && point->Y == 50)
- {
- parrotBox->Location = Point(point->X - 2, point->Y);
- }
- else if ((point->X < 450) && (point->Y < 350))
- {
- if (point->Y == 50)
- {
- Image^ img = parrotBox->Image;
- img->RotateFlip(RotateFlipType::Rotate180FlipY);
- parrotBox->Image = img;
- }
- parrotBox->Location = Point(point->X + 1, point->Y + 1);
- }
- if (point->Y == 350)
- {
- parrot->setDirection(true);
- cage->setBool(true);
- cageBtn->Enabled = true;
- toFreeParrot(true);
- }
- }
- delete point;
- }
- private: void toFreeParrot(bool isOpenAlready)
- {
- parrot->setFly(!isOpenAlready);
- timer2->Enabled = !isOpenAlready;
- foodBtn->Enabled = isOpenAlready;
- this->cageBox->Image = cage->getImage();
- this->cageBox->Size = this->cageBox->Image->Size;
- this->parrotBox->Image = parrot->getImage();
- this->parrotBox->Size = this->parrotBox->Image->Size;
- this->parrotBox->Image->RotateFlip(RotateFlipType::RotateNoneFlipX);
- }
- private:
- #pragma region Windows Form Designer generated code
- void InitializeComponent(void)
- {
- this->components = (gcnew System::ComponentModel::Container());
- this->cageBtn = (gcnew System::Windows::Forms::Button());
- this->foodBtn = (gcnew System::Windows::Forms::Button());
- this->healthBar = (gcnew System::Windows::Forms::ProgressBar());
- this->cageBox = (gcnew System::Windows::Forms::PictureBox());
- this->parrotBox = (gcnew System::Windows::Forms::PictureBox());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
- this->timer2 = (gcnew System::Windows::Forms::Timer(this->components));
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->cageBox))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->parrotBox))->BeginInit();
- this->SuspendLayout();
- //
- // cageBtn
- //
- this->cageBtn->Location = System::Drawing::Point(5, 335);
- this->cageBtn->Name = L"cageBtn";
- this->cageBtn->Size = System::Drawing::Size(100, 40);
- this->cageBtn->TabIndex = 0;
- this->cageBtn->Text = L"Open";
- this->cageBtn->UseVisualStyleBackColor = true;
- //
- // foodBtn
- //
- this->foodBtn->Location = System::Drawing::Point(5, 398);
- this->foodBtn->Name = L"foodBtn";
- this->foodBtn->Size = System::Drawing::Size(100, 40);
- this->foodBtn->TabIndex = 1;
- this->foodBtn->Text = L"Feed";
- this->foodBtn->UseVisualStyleBackColor = true;
- //
- // healthBar
- //
- this->healthBar->BackColor = System::Drawing::SystemColors::Control;
- this->healthBar->Location = System::Drawing::Point(12, 13);
- this->healthBar->Name = L"healthBar";
- this->healthBar->Size = System::Drawing::Size(681, 23);
- this->healthBar->TabIndex = 2;
- //
- // cageBox
- //
- this->cageBox->Location = System::Drawing::Point(600, 218);
- this->cageBox->Name = L"cageBox";
- this->cageBox->Size = System::Drawing::Size(147, 221);
- this->cageBox->TabIndex = 3;
- this->cageBox->TabStop = false;
- //
- // parrotBox
- //
- this->parrotBox->Location = System::Drawing::Point(450, 350);
- this->parrotBox->Name = L"parrotBox";
- this->parrotBox->Size = System::Drawing::Size(138, 137);
- this->parrotBox->TabIndex = 4;
- this->parrotBox->TabStop = false;
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(712, 23);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(27, 13);
- this->label1->TabIndex = 5;
- this->label1->Text = L"50%";
- //
- // timer1
- //
- this->timer1->Enabled = true;
- //
- // timer2
- //
- this->timer2->Interval = 10;
- //
- // MainForm
- //
- this->ClientSize = System::Drawing::Size(760, 450);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->parrotBox);
- this->Controls->Add(this->cageBox);
- this->Controls->Add(this->healthBar);
- this->Controls->Add(this->foodBtn);
- this->Controls->Add(this->cageBtn);
- this->Name = L"MainForm";
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->cageBox))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->parrotBox))->EndInit();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement