Advertisement
mk_1805

Untitled

Jan 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.94 KB | None | 0 0
  1. #pragma once
  2. #include <cstdlib>
  3. #include <windows.h>
  4. #include <mmsystem.h>
  5.  
  6.  
  7. namespace SkyWars {
  8.  
  9. using namespace System;
  10. using namespace System::ComponentModel;
  11. using namespace System::Collections;
  12. using namespace System::Windows::Forms;
  13. using namespace System::Data;
  14. using namespace System::Drawing;
  15. using namespace System::Drawing::Drawing2D;
  16. /// <summary>
  17. /// Summary for MainForm
  18. /// </summary>
  19. public ref class MainForm : public System::Windows::Forms::Form
  20. {
  21.  
  22. protected:
  23. int A; // square size(size of grid element)
  24. int M, N; // size of cartesian grid element
  25. int bomb_x, bomb_y, ship_x, ship_y;
  26. int *grid; // table of grid points (0 - empty, positive value - bomb color)
  27. int Maxy, Maxz;
  28. bool music1 = true;
  29. private: int _x, _y;
  30. private: int pv, ph;
  31. Bitmap^ ship_image;
  32. Bitmap^ stone_image;
  33.  
  34.  
  35.  
  36. private: System::Windows::Forms::Timer^ timer1;
  37. private: System::Windows::Forms::Timer^ timer2;
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. private: System::Windows::Forms::ToolStripMenuItem^ newGameToolStripMenuItem;
  45. private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
  46.  
  47. private: System::Windows::Forms::Timer^ przyspieszanie;
  48. private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem1;
  49. private: System::Windows::Forms::ToolStripMenuItem^ muteToolStripMenuItem;
  50. private: System::Windows::Forms::ToolStripMenuItem^ playToolStripMenuItem;
  51. private: System::Windows::Forms::Timer^ statek1;
  52.  
  53.  
  54.  
  55.  
  56. private: System::Windows::Forms::Timer^ timer_statek;
  57.  
  58.  
  59. public:
  60. MainForm(void)
  61. : A(0)
  62. {
  63. InitializeComponent();
  64. //
  65. //TODO: Add the constructor code here
  66. //
  67. this->Maxy = 0;
  68. this->Maxz = 0;
  69. this->A = 30;
  70. this->M = 34; this->N = 62;
  71. this->grid = new int[M*N];
  72. for (int i = 0; i < (M*N); i++) grid[i] = 0;
  73.  
  74. // zaladuj mape bitowa statku
  75.  
  76. ship_image = gcnew System::Drawing::Bitmap("rakieta.bmp");
  77. stone_image = gcnew System::Drawing::Bitmap("stone.bmp");
  78.  
  79.  
  80. //ustaw pozycje statku
  81. ph = 15;
  82. pv = 25; ///bylo 30
  83. grid[ph + pv*N] = 1000;
  84.  
  85. }
  86.  
  87. protected:
  88. /// <summary>
  89. /// Clean up any resources being used.
  90. /// </summary>
  91. ~MainForm()
  92. {
  93. if (components)
  94. {
  95. delete components;
  96. }
  97. }
  98. private: System::Windows::Forms::MenuStrip^ menuStrip1;
  99. protected:
  100.  
  101. private: System::Windows::Forms::ToolStripMenuItem^ gameToolStripMenuItem;
  102. private: System::Windows::Forms::ToolStripMenuItem^ startToolStripMenuItem;
  103. private: System::Windows::Forms::ToolStripMenuItem^ pauseToolStripMenuItem;
  104. private: System::Windows::Forms::ToolStripMenuItem^ stopToolStripMenuItem;
  105. private: System::ComponentModel::IContainer^ components;
  106.  
  107. private:
  108. /// <summary>
  109. /// Required designer variable.
  110. /// </summary>
  111.  
  112.  
  113. #pragma region Windows Form Designer generated code
  114. /// <summary>
  115. /// Required method for Designer support - do not modify
  116. /// the contents of this method with the code editor.
  117. /// </summary>
  118. void InitializeComponent(void)
  119.  
  120. {
  121. this->components = (gcnew System::ComponentModel::Container());
  122. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));
  123. this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
  124. this->gameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  125. this->startToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  126. this->pauseToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  127. this->stopToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  128. this->newGameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  129. this->toolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
  130. this->muteToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  131. this->playToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  132. this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  133. this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
  134. this->timer2 = (gcnew System::Windows::Forms::Timer(this->components));
  135. this->timer_statek = (gcnew System::Windows::Forms::Timer(this->components));
  136. this->przyspieszanie = (gcnew System::Windows::Forms::Timer(this->components));
  137. this->statek1 = (gcnew System::Windows::Forms::Timer(this->components));
  138. this->menuStrip1->SuspendLayout();
  139. this->SuspendLayout();
  140. //
  141. // menuStrip1
  142. //
  143. this->menuStrip1->ImageScalingSize = System::Drawing::Size(20, 20);
  144. this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
  145. this->gameToolStripMenuItem,
  146. this->toolStripMenuItem1, this->exitToolStripMenuItem
  147. });
  148. this->menuStrip1->Location = System::Drawing::Point(0, 0);
  149. this->menuStrip1->Name = L"menuStrip1";
  150. this->menuStrip1->Padding = System::Windows::Forms::Padding(5, 2, 0, 2);
  151. this->menuStrip1->Size = System::Drawing::Size(1920, 28);
  152. this->menuStrip1->TabIndex = 0;
  153. this->menuStrip1->Text = L"menuStrip1";
  154. this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &MainForm::menuStrip1_ItemClicked);
  155. //
  156. // gameToolStripMenuItem
  157. //
  158. this->gameToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {
  159. this->startToolStripMenuItem,
  160. this->pauseToolStripMenuItem, this->stopToolStripMenuItem, this->newGameToolStripMenuItem
  161. });
  162. this->gameToolStripMenuItem->Name = L"gameToolStripMenuItem";
  163. this->gameToolStripMenuItem->Size = System::Drawing::Size(60, 24);
  164. this->gameToolStripMenuItem->Text = L"Game";
  165. //
  166. // startToolStripMenuItem
  167. //
  168. this->startToolStripMenuItem->Name = L"startToolStripMenuItem";
  169. this->startToolStripMenuItem->Size = System::Drawing::Size(181, 26);
  170. this->startToolStripMenuItem->Text = L"&Start";
  171. this->startToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::startToolStripMenuItem_Click);
  172. //
  173. // pauseToolStripMenuItem
  174. //
  175. this->pauseToolStripMenuItem->Name = L"pauseToolStripMenuItem";
  176. this->pauseToolStripMenuItem->Size = System::Drawing::Size(181, 26);
  177. this->pauseToolStripMenuItem->Text = L"&Pause";
  178. this->pauseToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::pauseToolStripMenuItem_Click);
  179. //
  180. // stopToolStripMenuItem
  181. //
  182. this->stopToolStripMenuItem->Name = L"stopToolStripMenuItem";
  183. this->stopToolStripMenuItem->Size = System::Drawing::Size(181, 26);
  184. this->stopToolStripMenuItem->Text = L"Stop";
  185. //
  186. // newGameToolStripMenuItem
  187. //
  188. this->newGameToolStripMenuItem->Name = L"newGameToolStripMenuItem";
  189. this->newGameToolStripMenuItem->Size = System::Drawing::Size(181, 26);
  190. this->newGameToolStripMenuItem->Text = L"New Game";
  191. this->newGameToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::newGameToolStripMenuItem_Click);
  192. //
  193. // toolStripMenuItem1
  194. //
  195. this->toolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
  196. this->muteToolStripMenuItem,
  197. this->playToolStripMenuItem
  198. });
  199. this->toolStripMenuItem1->Name = L"toolStripMenuItem1";
  200. this->toolStripMenuItem1->Size = System::Drawing::Size(59, 24);
  201. this->toolStripMenuItem1->Text = L"Music";
  202. this->toolStripMenuItem1->Click += gcnew System::EventHandler(this, &MainForm::toolStripMenuItem1_Click);
  203. //
  204. // muteToolStripMenuItem
  205. //
  206. this->muteToolStripMenuItem->Name = L"muteToolStripMenuItem";
  207. this->muteToolStripMenuItem->Size = System::Drawing::Size(118, 26);
  208. this->muteToolStripMenuItem->Text = L"Mute";
  209. this->muteToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::muteToolStripMenuItem_Click);
  210. //
  211. // playToolStripMenuItem
  212. //
  213. this->playToolStripMenuItem->Name = L"playToolStripMenuItem";
  214. this->playToolStripMenuItem->Size = System::Drawing::Size(118, 26);
  215. this->playToolStripMenuItem->Text = L"Play";
  216. this->playToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::playToolStripMenuItem_Click);
  217. //
  218. // exitToolStripMenuItem
  219. //
  220. this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
  221. this->exitToolStripMenuItem->Size = System::Drawing::Size(45, 24);
  222. this->exitToolStripMenuItem->Text = L"Exit";
  223. this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::exitToolStripMenuItem_Click);
  224. //
  225. // timer1
  226. //
  227. this->timer1->Enabled = true;
  228. this->timer1->Tick += gcnew System::EventHandler(this, &MainForm::timer1_Tick);
  229. //
  230. // timer2
  231. //
  232. this->timer2->Enabled = true;
  233. this->timer2->Interval = 200;
  234. this->timer2->Tick += gcnew System::EventHandler(this, &MainForm::timer2_Tick);
  235. //
  236. // timer_statek
  237. //
  238. this->timer_statek->Enabled = true;
  239. this->timer_statek->Interval = 50;
  240. this->timer_statek->Tick += gcnew System::EventHandler(this, &MainForm::timer_statek_Tick);
  241. //
  242. // przyspieszanie
  243. //
  244. this->przyspieszanie->Enabled = true;
  245. this->przyspieszanie->Interval = 10000;
  246. this->przyspieszanie->Tick += gcnew System::EventHandler(this, &MainForm::przyspieszanie_Tick);
  247. //
  248. // MainForm
  249. //
  250. this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
  251. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  252. this->ClientSize = System::Drawing::Size(1920, 1080);
  253. this->Controls->Add(this->menuStrip1);
  254. this->ForeColor = System::Drawing::Color::Crimson;
  255. this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
  256. this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
  257. this->KeyPreview = true;
  258. this->MainMenuStrip = this->menuStrip1;
  259. this->Margin = System::Windows::Forms::Padding(3, 2, 3, 2);
  260. this->MaximizeBox = false;
  261. this->Name = L"MainForm";
  262. this->RightToLeftLayout = true;
  263. this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
  264. this->Text = L"MainForm";
  265. this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load);
  266. this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MainForm::MainForm_KeyDown);
  267. this->menuStrip1->ResumeLayout(false);
  268. this->menuStrip1->PerformLayout();
  269. this->ResumeLayout(false);
  270. this->PerformLayout();
  271.  
  272. }
  273.  
  274.  
  275. #pragma endregion
  276.  
  277. private: System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e) {
  278. }
  279. //protected:
  280. // square size (size of grid element)
  281. //int A;
  282.  
  283. private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
  284. //display timer
  285. Graphics^ formGraphics = this->CreateGraphics();
  286. formGraphics->FillRectangle(Brushes::Black, A, A, A*N, A*M);
  287.  
  288. //rysuj kolorowe booooomby -booom-
  289. System::Drawing::Brush^ brush;
  290. int colornum;
  291. for (int x = 0; x < N; x++)
  292. for (int y = 0; y < M; y++) {
  293. colornum = grid[x + y*N];
  294. if (colornum != 0) {
  295. switch (colornum) {
  296. case 1: brush = Brushes::White; break;
  297. case 2: brush = Brushes::White; break;
  298. case 3: brush = Brushes::Coral; break;
  299. case 4: brush = Brushes::White; break;
  300. case 5: brush = Brushes::Gold; break;
  301. case 6: brush = Brushes::Blue; break;
  302. default: brush = Brushes::Black; break;
  303. }
  304. formGraphics->DrawImage(stone_image, A + A*(x), A + (y)*A, A, A);
  305. if (colornum == 1000)
  306. {
  307. formGraphics->DrawImage(ship_image, A + A*(x), A + (y)*A - 100);
  308.  
  309. }
  310. //ZDERZENIA
  311. // jezeli jest rozne od 0 i 1000, to continue
  312. // jesli jest inaczej, wyjeb
  313. // 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)) {
  314. if (grid[ph + (pv*N)] != 0) MainForm::Close();
  315. // MainForm::Close();
  316. // }
  317.  
  318.  
  319. }
  320. // delete formGraphics;
  321. }
  322. }
  323.  
  324. private: System::Void startToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  325.  
  326. //start bomb timer
  327. this->timer2->Interval;
  328. this->timer2->Start();
  329. pauza = true;
  330.  
  331. }
  332. private: System::Void stopToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  333. //stop bomb timer
  334. this->timer2->Stop();
  335.  
  336. }
  337. private: System::Void timer2_Tick(System::Object^ sender, System::EventArgs^ e) {
  338. //bomb timer tick
  339.  
  340. //moves all bombs down - zrzuca bomby
  341. for (int x = 0; x < N; x++)
  342. for (int y = M - 1; y >= 0; y--) {
  343. if(grid[x + y*N] != 1000**grid)
  344. if (grid[x + y*N] == 1000) continue;
  345. else
  346. if (grid[x + y*N] > 0) {
  347. if (y < M - 1) grid[x + (y + 1)*N] = grid[x + y*N];
  348. grid[x + y*N] = 0;
  349. }
  350. }
  351. //randomly generates a bomb
  352.  
  353. int x = rand()*(N - 1) / RAND_MAX;
  354. grid[x + 0 * N] = (rand() + 1) * 6 / (RAND_MAX + 1);
  355. }
  356. private: System::Void menuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e) {
  357. }
  358. private: System::Void timer_statek_Tick(System::Object^ sender, System::EventArgs^ e) {
  359.  
  360. }
  361.  
  362. bool pauza = true;
  363.  
  364. private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  365. MainForm::Close();
  366. PlaySound(TEXT("LukHash_-_THE_OTHER_SIDE.wav"), NULL, SND_LOOP | SND_ASYNC);
  367. }
  368. private: System::Void pauseToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  369. this->timer2->Stop();
  370. pauza = false;
  371.  
  372. }
  373.  
  374. private: System::Void przyspieszanie_Tick(System::Object^ sender, System::EventArgs^ e) {
  375.  
  376. if (this->timer2->Interval > 10)
  377. this->timer2->Interval -= 10;
  378. }
  379. private: System::Void toolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e) {
  380. }
  381.  
  382. private: System::Void muteToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  383. music1 = false;
  384. PlaySound(NULL, 0, 0);
  385. }
  386. private: System::Void playToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  387. if (!music1)
  388. PlaySound(TEXT("Eye of the tiger"), NULL, SND_LOOP | SND_ASYNC);
  389. music1 = true;
  390. }
  391. private: System::Void newGameToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  392. MainForm::Close();
  393. MainForm^ mainform = gcnew MainForm();
  394. mainform->Show();
  395. }
  396.  
  397. private: System::Void MainForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
  398. switch (e->KeyCode)
  399. {
  400. case Keys::A:
  401. //if (Maxy > -540)
  402. {
  403. //Maxy -= 10;
  404. grid[ph + pv*N] = 0;
  405. ph -= 1;
  406. grid[ph + pv*N] = 1000;
  407.  
  408. break;
  409.  
  410. }
  411. case Keys::D:
  412. //if (Maxy < 540)
  413. {
  414. //Maxy += 10;
  415. grid[ph + pv*N] = 0;
  416. ph += 1;
  417. grid[ph + pv*N] = 1000;
  418. break;
  419. }
  420. case Keys::W:
  421. //if ((Maxz >= 0 && (Maxz < 600))
  422. //{
  423. //pictureBox1->Top -= 10;
  424. break;
  425. // }
  426. case Keys::S:
  427. //pictureBox1->Top += 10;
  428. break;
  429. }
  430.  
  431.  
  432. }
  433. };
  434. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement