Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <cstdlib>
- #include <windows.h>
- #include <mmsystem.h>
- namespace SkyWars {
- 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::Drawing::Drawing2D;
- /// <summary>
- /// Summary for MainForm
- /// </summary>
- public ref class MainForm : public System::Windows::Forms::Form
- {
- protected:
- int A; // square size(size of grid element)
- int M, N; // size of cartesian grid element
- int bomb_x, bomb_y, ship_x, ship_y;
- int *grid; // table of grid points (0 - empty, positive value - bomb color)
- int Maxy, Maxz;
- bool music1 = true;
- private: int _x, _y;
- private: int pv, ph;
- Bitmap^ ship_image;
- Bitmap^ stone_image;
- private: System::Windows::Forms::Timer^ timer1;
- private: System::Windows::Forms::Timer^ timer2;
- private: System::Windows::Forms::ToolStripMenuItem^ newGameToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
- private: System::Windows::Forms::Timer^ przyspieszanie;
- private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem1;
- private: System::Windows::Forms::ToolStripMenuItem^ muteToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ playToolStripMenuItem;
- private: System::Windows::Forms::Timer^ statek1;
- private: System::Windows::Forms::Timer^ timer_statek;
- public:
- MainForm(void)
- : A(0)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- this->Maxy = 0;
- this->Maxz = 0;
- this->A = 30;
- this->M = 34; this->N = 62;
- this->grid = new int[M*N];
- for (int i = 0; i < (M*N); i++) grid[i] = 0;
- // zaladuj mape bitowa statku
- ship_image = gcnew System::Drawing::Bitmap("rakieta.bmp");
- stone_image = gcnew System::Drawing::Bitmap("stone.bmp");
- //ustaw pozycje statku
- ph = 15;
- pv = 25; ///bylo 30
- grid[ph + pv*N] = 1000;
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~MainForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::MenuStrip^ menuStrip1;
- protected:
- private: System::Windows::Forms::ToolStripMenuItem^ gameToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ startToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ pauseToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ stopToolStripMenuItem;
- private: System::ComponentModel::IContainer^ components;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->components = (gcnew System::ComponentModel::Container());
- System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));
- this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
- this->gameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->startToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->pauseToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->stopToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->newGameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->toolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->muteToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->playToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
- this->timer2 = (gcnew System::Windows::Forms::Timer(this->components));
- this->timer_statek = (gcnew System::Windows::Forms::Timer(this->components));
- this->przyspieszanie = (gcnew System::Windows::Forms::Timer(this->components));
- this->statek1 = (gcnew System::Windows::Forms::Timer(this->components));
- this->menuStrip1->SuspendLayout();
- this->SuspendLayout();
- //
- // menuStrip1
- //
- this->menuStrip1->ImageScalingSize = System::Drawing::Size(20, 20);
- this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
- this->gameToolStripMenuItem,
- this->toolStripMenuItem1, this->exitToolStripMenuItem
- });
- this->menuStrip1->Location = System::Drawing::Point(0, 0);
- this->menuStrip1->Name = L"menuStrip1";
- this->menuStrip1->Padding = System::Windows::Forms::Padding(5, 2, 0, 2);
- this->menuStrip1->Size = System::Drawing::Size(1920, 28);
- this->menuStrip1->TabIndex = 0;
- this->menuStrip1->Text = L"menuStrip1";
- this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &MainForm::menuStrip1_ItemClicked);
- //
- // gameToolStripMenuItem
- //
- this->gameToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {
- this->startToolStripMenuItem,
- this->pauseToolStripMenuItem, this->stopToolStripMenuItem, this->newGameToolStripMenuItem
- });
- this->gameToolStripMenuItem->Name = L"gameToolStripMenuItem";
- this->gameToolStripMenuItem->Size = System::Drawing::Size(60, 24);
- this->gameToolStripMenuItem->Text = L"Game";
- //
- // startToolStripMenuItem
- //
- this->startToolStripMenuItem->Name = L"startToolStripMenuItem";
- this->startToolStripMenuItem->Size = System::Drawing::Size(181, 26);
- this->startToolStripMenuItem->Text = L"&Start";
- this->startToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::startToolStripMenuItem_Click);
- //
- // pauseToolStripMenuItem
- //
- this->pauseToolStripMenuItem->Name = L"pauseToolStripMenuItem";
- this->pauseToolStripMenuItem->Size = System::Drawing::Size(181, 26);
- this->pauseToolStripMenuItem->Text = L"&Pause";
- this->pauseToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::pauseToolStripMenuItem_Click);
- //
- // stopToolStripMenuItem
- //
- this->stopToolStripMenuItem->Name = L"stopToolStripMenuItem";
- this->stopToolStripMenuItem->Size = System::Drawing::Size(181, 26);
- this->stopToolStripMenuItem->Text = L"Stop";
- //
- // newGameToolStripMenuItem
- //
- this->newGameToolStripMenuItem->Name = L"newGameToolStripMenuItem";
- this->newGameToolStripMenuItem->Size = System::Drawing::Size(181, 26);
- this->newGameToolStripMenuItem->Text = L"New Game";
- this->newGameToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::newGameToolStripMenuItem_Click);
- //
- // toolStripMenuItem1
- //
- this->toolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
- this->muteToolStripMenuItem,
- this->playToolStripMenuItem
- });
- this->toolStripMenuItem1->Name = L"toolStripMenuItem1";
- this->toolStripMenuItem1->Size = System::Drawing::Size(59, 24);
- this->toolStripMenuItem1->Text = L"Music";
- this->toolStripMenuItem1->Click += gcnew System::EventHandler(this, &MainForm::toolStripMenuItem1_Click);
- //
- // muteToolStripMenuItem
- //
- this->muteToolStripMenuItem->Name = L"muteToolStripMenuItem";
- this->muteToolStripMenuItem->Size = System::Drawing::Size(118, 26);
- this->muteToolStripMenuItem->Text = L"Mute";
- this->muteToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::muteToolStripMenuItem_Click);
- //
- // playToolStripMenuItem
- //
- this->playToolStripMenuItem->Name = L"playToolStripMenuItem";
- this->playToolStripMenuItem->Size = System::Drawing::Size(118, 26);
- this->playToolStripMenuItem->Text = L"Play";
- this->playToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::playToolStripMenuItem_Click);
- //
- // exitToolStripMenuItem
- //
- this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
- this->exitToolStripMenuItem->Size = System::Drawing::Size(45, 24);
- this->exitToolStripMenuItem->Text = L"Exit";
- this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::exitToolStripMenuItem_Click);
- //
- // timer1
- //
- this->timer1->Enabled = true;
- this->timer1->Tick += gcnew System::EventHandler(this, &MainForm::timer1_Tick);
- //
- // timer2
- //
- this->timer2->Enabled = true;
- this->timer2->Interval = 200;
- this->timer2->Tick += gcnew System::EventHandler(this, &MainForm::timer2_Tick);
- //
- // timer_statek
- //
- this->timer_statek->Enabled = true;
- this->timer_statek->Interval = 50;
- this->timer_statek->Tick += gcnew System::EventHandler(this, &MainForm::timer_statek_Tick);
- //
- // przyspieszanie
- //
- this->przyspieszanie->Enabled = true;
- this->przyspieszanie->Interval = 10000;
- this->przyspieszanie->Tick += gcnew System::EventHandler(this, &MainForm::przyspieszanie_Tick);
- //
- // MainForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(1920, 1080);
- this->Controls->Add(this->menuStrip1);
- this->ForeColor = System::Drawing::Color::Crimson;
- this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
- this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
- this->KeyPreview = true;
- this->MainMenuStrip = this->menuStrip1;
- this->Margin = System::Windows::Forms::Padding(3, 2, 3, 2);
- this->MaximizeBox = false;
- this->Name = L"MainForm";
- this->RightToLeftLayout = true;
- this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
- this->Text = L"MainForm";
- this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load);
- this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MainForm::MainForm_KeyDown);
- this->menuStrip1->ResumeLayout(false);
- this->menuStrip1->PerformLayout();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e) {
- }
- //protected:
- // square size (size of grid element)
- //int A;
- private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
- //display timer
- Graphics^ formGraphics = this->CreateGraphics();
- formGraphics->FillRectangle(Brushes::Black, A, A, A*N, A*M);
- //rysuj kolorowe booooomby -booom-
- System::Drawing::Brush^ brush;
- int colornum;
- for (int x = 0; x < N; x++)
- for (int y = 0; y < M; y++) {
- colornum = grid[x + y*N];
- if (colornum != 0) {
- switch (colornum) {
- case 1: brush = Brushes::White; break;
- case 2: brush = Brushes::White; break;
- case 3: brush = Brushes::Coral; break;
- case 4: brush = Brushes::White; break;
- case 5: brush = Brushes::Gold; break;
- case 6: brush = Brushes::Blue; break;
- default: brush = Brushes::Black; break;
- }
- formGraphics->DrawImage(stone_image, A + A*(x), A + (y)*A, A, A);
- if (colornum == 1000)
- {
- formGraphics->DrawImage(ship_image, A + A*(x), A + (y)*A - 100);
- }
- //ZDERZENIA
- // jezeli jest rozne od 0 i 1000, to continue
- // jesli jest inaczej, wyjeb
- // if ((grid[ph + pv*N] == 1000) && (grid[x + y*N] == 1 || grid[x + y*N] == 2 || grid[x + y*N] == 3 || grid[x + y*N] == 4 || grid[x + y*N] == 5 || grid[x + y*N] == 6)) {
- if (grid[ph + (pv*N)] != 0) MainForm::Close();
- // MainForm::Close();
- // }
- }
- // delete formGraphics;
- }
- }
- private: System::Void startToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- //start bomb timer
- this->timer2->Interval;
- this->timer2->Start();
- pauza = true;
- }
- private: System::Void stopToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- //stop bomb timer
- this->timer2->Stop();
- }
- private: System::Void timer2_Tick(System::Object^ sender, System::EventArgs^ e) {
- //bomb timer tick
- //moves all bombs down - zrzuca bomby
- for (int x = 0; x < N; x++)
- for (int y = M - 1; y >= 0; y--) {
- if(grid[x + y*N] != 1000**grid)
- if (grid[x + y*N] == 1000) continue;
- else
- if (grid[x + y*N] > 0) {
- if (y < M - 1) grid[x + (y + 1)*N] = grid[x + y*N];
- grid[x + y*N] = 0;
- }
- }
- //randomly generates a bomb
- int x = rand()*(N - 1) / RAND_MAX;
- grid[x + 0 * N] = (rand() + 1) * 6 / (RAND_MAX + 1);
- }
- private: System::Void menuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e) {
- }
- private: System::Void timer_statek_Tick(System::Object^ sender, System::EventArgs^ e) {
- }
- bool pauza = true;
- private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- MainForm::Close();
- PlaySound(TEXT("LukHash_-_THE_OTHER_SIDE.wav"), NULL, SND_LOOP | SND_ASYNC);
- }
- private: System::Void pauseToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- this->timer2->Stop();
- pauza = false;
- }
- private: System::Void przyspieszanie_Tick(System::Object^ sender, System::EventArgs^ e) {
- if (this->timer2->Interval > 10)
- this->timer2->Interval -= 10;
- }
- private: System::Void toolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void muteToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- music1 = false;
- PlaySound(NULL, 0, 0);
- }
- private: System::Void playToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- if (!music1)
- PlaySound(TEXT("Eye of the tiger"), NULL, SND_LOOP | SND_ASYNC);
- music1 = true;
- }
- private: System::Void newGameToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- MainForm::Close();
- MainForm^ mainform = gcnew MainForm();
- mainform->Show();
- }
- private: System::Void MainForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
- switch (e->KeyCode)
- {
- case Keys::A:
- //if (Maxy > -540)
- {
- //Maxy -= 10;
- grid[ph + pv*N] = 0;
- ph -= 1;
- grid[ph + pv*N] = 1000;
- break;
- }
- case Keys::D:
- //if (Maxy < 540)
- {
- //Maxy += 10;
- grid[ph + pv*N] = 0;
- ph += 1;
- grid[ph + pv*N] = 1000;
- break;
- }
- case Keys::W:
- //if ((Maxz >= 0 && (Maxz < 600))
- //{
- //pictureBox1->Top -= 10;
- break;
- // }
- case Keys::S:
- //pictureBox1->Top += 10;
- break;
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement