Advertisement
Guest User

arcasha

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace larsen
  12. {
  13. public partial class Form1 : Form
  14. {
  15. bool goRight;
  16. bool goLeft;
  17. int speed = 10;
  18.  
  19. int ballx = 5;
  20. int bally = 5;
  21.  
  22. int score = 0;
  23. private Random rnd = new Random();
  24.  
  25. public Form1()
  26. {
  27. InitializeComponent();
  28. foreach (Control x in this.Controls)
  29. {
  30. if(x is PictureBox && x.Tag == "block")
  31. {
  32. Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
  33. x.BackColor = randomColor;
  34. }
  35. }
  36. }
  37.  
  38. private void Form1_Paint(object sender, PaintEventArgs e)
  39. {
  40.  
  41. }
  42.  
  43. private void keyisdown(object sender, KeyEventArgs e)
  44. {
  45. if(e.KeyCode == Keys.Left && player.Left > 0)
  46. {
  47. goLeft = true;
  48. }
  49. if (e.KeyCode == Keys.Right && player.Left + player.Width < 920)
  50. {
  51. goRight = true;
  52.  
  53. }
  54. }
  55.  
  56.  
  57. private void keyisup(object sender, KeyEventArgs e)
  58. {
  59. if (e.KeyCode == Keys.Left)
  60. {
  61. goLeft = false;
  62. }
  63. if (e.KeyCode == Keys.Right)
  64. {
  65. goRight = false;
  66. }
  67. }
  68.  
  69. private void timer1_Tick(object sender, EventArgs e)
  70. {
  71. ball.Left += ballx;
  72. ball.Top += bally;
  73.  
  74. label1.Text = "Score" + score;
  75.  
  76. if (goLeft) { player.Left -= speed; }
  77. if (goRight) { player.Left += speed; }
  78.  
  79. if (player.Left < 1)
  80. {
  81. goLeft = false;
  82.  
  83. }
  84. else if (player.Left + player.Width > 920)
  85. {
  86. goRight = false;
  87. }
  88. if(ball.Left + ball.Width > ClientSize.Width || ball.Left < 0)
  89. {
  90. ballx = -ballx;
  91. }
  92. if(ball.Top < 0 || ball.Bounds.IntersectsWith (player.Bounds))
  93. {
  94. bally = -bally;
  95. }
  96. if (ball.Top + ball.Height > ClientSize.Height)
  97. {
  98. gameOver();
  99. }
  100. foreach (Control x in this.Controls)
  101. {
  102. if (x is PictureBox && x.Tag == "block")
  103. {
  104. if (ball.Bounds.IntersectsWith(x.Bounds))
  105. {
  106. this.Controls.Remove(x);
  107. bally = -bally;
  108. score++;
  109. }
  110. }
  111.  
  112. }
  113. if(score > 34)
  114. {
  115. gameOver();
  116. MessageBox.Show("NAVI NAVI NAVI");
  117.  
  118. }
  119. }
  120. private void gameOver()
  121. {
  122. timer1.Stop();
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement