Advertisement
Guest User

wert

a guest
Apr 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. PictureBox bg;
  2. PictureBox[] bullet;
  3. PictureBox[][] pix;
  4. Boolean[][] isLocked;
  5. PictureBox[][] enemy;
  6. int bulletCount = 1000;
  7. int enemyCount = 10;
  8.  
  9. private void Form1_Load(object sender, EventArgs e)
  10. {
  11. pix = new PictureBox[3][];
  12. isLocked = new Boolean[3][];
  13.  
  14. enemy = new PictureBox[3][];
  15. bg = new PictureBox();
  16. this.Controls.Add(bg);
  17. bg.SizeMode = PictureBoxSizeMode.StretchImage;
  18. bg.SetBounds(0, 100, this.Width, this.Height - 100);
  19.  
  20. bullet = new PictureBox[bulletCount];
  21. for (int b = 0; b < bulletCount; b++)
  22. {
  23. bullet[b] = new PictureBox();
  24. bullet[b].SetBounds(0, 0, 20, 20);
  25. bullet[b].Visible = false;
  26. bullet[b].Image = Properties.Resources.bullet;
  27. bg.Controls.Add(bullet[b]);
  28. }
  29.  
  30. for (int y = 0; y < 3; y++)
  31. {
  32. pix[y] = new PictureBox[3];
  33. isLocked[y] = new Boolean[3];
  34. enemy[y] = new PictureBox[enemyCount];
  35. for (int x = 0; x < 3; x++)
  36. {
  37. isLocked[y][x] = false;
  38. pix[y][x] = new PictureBox();
  39. pix[y][x].SetBounds(300 + (110 * x), 90 + (180 * y), 100, 100);
  40. pix[y][x].BackColor = Color.Red;
  41. pix[y][x].MouseClick += new MouseEventHandler(this.mA);
  42. pix[y][x].MouseHover += new EventHandler(this.mB);
  43. pix[y][x].MouseLeave += new EventHandler(this.mC);
  44. bg.Controls.Add(pix[y][x]);
  45. }
  46. for (int z = 0; z < enemyCount; z++)
  47. {
  48. enemy[y][z] = new PictureBox();
  49. enemy[y][z].Image = Properties.Resources.e1;
  50. bg.Controls.Add(enemy[y][z]);
  51. enemy[y][z].Visible = false;
  52. }
  53.  
  54. }
  55. }
  56. void mA(object sender, MouseEventArgs e)
  57. {
  58. for (int y = 0; y < 3; y++)
  59. {
  60. for (int x = 0; x < 3; x++)
  61. {
  62. if (sender.Equals(pix[y][x]) & !isLocked[y][x])
  63. {
  64. pix[y][x].Image = tempImg;
  65. isLocked[y][x] = true;
  66. tempImg = null;
  67. }
  68. }
  69. }
  70. }
  71.  
  72. void mB(object sender, EventArgs e)
  73. {
  74. for (int y = 0; y < 3; y++)
  75. {
  76. for (int x = 0; x < 3; x++)
  77. {
  78. if (sender.Equals(pix[y][x]) & !isLocked[y][x])
  79. {
  80. pix[y][x].Image = tempImg;
  81. }
  82. }
  83. }
  84. }
  85. void mC(object sender, EventArgs e)
  86. {
  87. for (int y = 0; y < 3; y++)
  88. {
  89. for (int x = 0; x < 3; x++)
  90. {
  91. if (sender.Equals(pix[y][x]) & !isLocked[y][x])
  92. {
  93. pix[y][x].Image = null;
  94. }
  95. }
  96. }
  97. }
  98.  
  99. Image tempImg;
  100. private void place1_Click(object sender, EventArgs e)
  101. {
  102. tempImg = place1.Image;
  103. }
  104.  
  105. private void place2_Click(object sender, EventArgs e)
  106. {
  107. tempImg = place2.Image;
  108. }
  109.  
  110. private void place3_Click(object sender, EventArgs e)
  111. {
  112. tempImg = place3.Image;
  113. }
  114.  
  115. private void timer1_Tick(object sender, EventArgs e)
  116. {
  117. for (int x = 0; x < 3; x++)
  118. {
  119. for (int z = 0; z < enemyCount; z++)
  120. {
  121. if (enemy[x][z].Visible)
  122. {
  123. enemy[x][z].Location = new Point(enemy[x][z].Location.X - 10, enemy[x][z].Location.Y);
  124. }
  125. }
  126. }
  127. }
  128.  
  129.  
  130. private void bulletMove_Tick(object sender, EventArgs e)
  131. {
  132. for (int b = 0; b < bulletCount; b++)
  133. {
  134. if (bullet[b].Visible)
  135. {
  136. bullet[b].Location = new Point(bullet[b].Location.X + 10, bullet[b].Location.Y);
  137. for (int y = 0; y < 3; y++)
  138. {
  139. for (int z = 0; z < enemyCount; z++)
  140. {
  141. if (bullet[b].Bounds.IntersectsWith(enemy[y][z].Bounds))
  142. {
  143. bullet[b].Visible = false;
  144. enemy[y][z].Visible = false;
  145.  
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152.  
  153. Random ran = new Random();
  154. private void enemyGenerate_Tick(object sender, EventArgs e)
  155. {
  156. int y = ran.Next(3);
  157. for (int z = 0; z < enemyCount; z++)
  158. {
  159. if (!enemy[y][z].Visible)
  160. {
  161. enemy[y][z].SetBounds(bg.Width, 90 + (180 * y), 100, 100);
  162. enemy[y][z].Visible = true;
  163. break;
  164. }
  165. }
  166. }
  167.  
  168. Boolean[] isAlive = new Boolean[3];
  169. int bulletCtr = 0;
  170. private void rangeCheck_Tick(object sender, EventArgs e)
  171. {
  172. for (int y = 0; y < 3; y++)
  173. {
  174. isAlive[y] = false;
  175. for (int z = 0; z < enemyCount; z++)
  176. {
  177. if (enemy[y][z].Visible)
  178. {
  179. isAlive[y] = true;
  180. }
  181. }
  182.  
  183. if (isAlive[y])
  184. {
  185. for (int x = 0; x < 3; x++)
  186. {
  187. if (isLocked[y][x])
  188. {
  189. bullet[bulletCtr].Location = new Point(pix[y][x].Location.X + pix[y][x].Width, pix[y][x].Location.Y + 40);
  190. bullet[bulletCtr].Visible = true;
  191. if (bulletCtr < bulletCount - 1)
  192. {
  193. bulletCtr++;
  194. }
  195. else
  196. {
  197. bulletCtr = 0;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204.  
  205.  
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement