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();
- private: bool isWait;
- public:
- MainForm(void)
- {
- InitializeComponent();
- this->cageBox->Image = cage->getImage();
- this->cageBox->Size = this->cageBox->Image->Size;
- this->cageBox->BackColor = Color::Transparent;
- this->parrotBox->BackColor = Color::Transparent;
- this->label1->BackColor = Color::Transparent;
- this->label1->ForeColor = Color::Red;
- 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);
- this->BackgroundImage = Image::FromFile("images/back.jpg");
- this->BackgroundImageLayout = ImageLayout::Stretch;
- }
- 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;
- timer2->Enabled = false;
- MessageBox::Show("Your parrot died.", "The End :(");
- this->~MainForm();
- this->Close();
- }
- else
- {
- timer1->Interval = 100;
- healthBar->Increment(-1);
- if (cage->isOpen() && !parrot->getFly())
- {
- timer2->Enabled = true;
- timer2->Interval = 5000;
- isWait = true;
- }
- }
- 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 (cage->isOpen())
- {
- cage->setType(1);
- parrot->setFly(false);
- parrot->setDraw(false);
- this->cageBtn->Text = "Open";
- cageBtn->Enabled = true;
- foodBtn->Enabled = true;
- timer2->Enabled = false;
- setImages();
- }
- else
- {
- cage->setType(-2);
- parrot->setFly(true);
- parrot->setDraw(true);
- this->cageBtn->Text = "Close";
- cageBtn->Enabled = false;
- foodBtn->Enabled = false;
- timer2->Interval = 50;
- timer2->Enabled = true;
- setImages();
- }
- }
- private:
- void flyTimer(System::Object^ sender, System::EventArgs^ e)
- {
- Point^ point = parrotBox->Location;
- if (isWait)
- {
- cage->setType(-2);
- parrot->setFly(true);
- parrot->setDraw(true);
- this->cageBtn->Text = "Close";
- cageBtn->Enabled = false;
- foodBtn->Enabled = false;
- setImages();
- isWait = false;
- timer2->Interval = 10;
- }
- else
- {
- 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 - 2, point->Y - 2);
- }
- else if (point->X < 600)
- {
- if (point->X <= 150)
- {
- Image^ img = parrotBox->Image;
- img->RotateFlip(RotateFlipType::RotateNoneFlipX);
- parrotBox->Image = img;
- }
- parrotBox->Location = Point(point->X + 4, point->Y);
- }
- if (point->X == 598)
- {
- 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 - 4, 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 + 2, point->Y + 2);
- }
- if (point->Y == 350)
- {
- parrot->setDirection(true);
- cage->setType(2);
- parrot->setFly(false);
- parrot->setDraw(false);
- cageBtn->Enabled = true;
- foodBtn->Enabled = true;
- timer2->Enabled = false;
- setImages();
- }
- }
- delete point;
- }
- }
- private: void setImages()
- {
- this->cageBox->Image = cage->getImage();
- this->cageBox->Size = this->cageBox->Image->Size;
- if (parrot->getDraw())
- {
- this->parrotBox->Image = parrot->getImage();
- this->parrotBox->Size = this->parrotBox->Image->Size;
- this->parrotBox->BackColor = Color::Transparent;
- parrotBox->Visible = true;
- }
- else
- {
- delete this->parrotBox->Image;
- parrotBox->Visible = false;
- }
- }
- private:
- #pragma region Windows Form Designer generated code
- void InitializeComponent(void)
- {
- this->components = (gcnew System::ComponentModel::Container());
- System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));
- 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(601, 237);
- 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->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
- this->MaximizeBox = false;
- this->MinimizeBox = false;
- this->Name = L"MainForm";
- this->Text = L"ParrotCage";
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->cageBox))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->parrotBox))->EndInit();
- this->ResumeLayout(false);
- this->PerformLayout();
- this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
- }
- #pragma endregion
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement