Advertisement
Guest User

Untitled

a guest
Apr 6th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 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. using System.Diagnostics;
  11.  
  12.  
  13. using System.Threading;
  14.  
  15. namespace BounceBall
  16. {
  17. public partial class Form1 : Form
  18. {
  19. Stopwatch stopwatch= new Stopwatch();
  20. Graphics paper;
  21. Paddle paddle = new Paddle();
  22. Ball ball = new Ball();
  23. Bricks bricks = new Bricks();
  24.  
  25. Thread myThread;
  26. BallUpdate ballUpdate = new BallUpdate();
  27. int w, h;
  28. bool paused = false;
  29. TimeSpan ts;
  30. String elapsedtime;
  31.  
  32. public Form2 f2 = null;
  33. int score;
  34.  
  35. public Form1()
  36. {
  37. InitializeComponent();
  38. f2 = null;
  39. w = Width;
  40. h = Height;
  41. ballUpdate.getWH(w,h);
  42.  
  43. myThread = new Thread(() => ballUpdate.ballMotion(ball, paddle, bricks));
  44. myThread.Start();
  45. stopwatch.Start();
  46. }
  47.  
  48. public void Form1_Paint(object sender, PaintEventArgs e)
  49. {
  50. paper = e.Graphics;
  51. paddle.drawPaddle(paper);
  52. ball.drawBall(paper);
  53. bricks.drawBricks(paper);
  54. w = Width;
  55. h = Height;
  56. ballUpdate.getWH(w,h);
  57.  
  58. ts = stopwatch.Elapsed;
  59. elapsedtime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
  60. ts.Hours, ts.Minutes, ts.Seconds,
  61. ts.Milliseconds / 10);
  62. label1.Text = elapsedtime;
  63. score=ballUpdate.getScore();
  64. label2.Text = "Score: " + score;
  65.  
  66. }
  67.  
  68. private void Form1_MouseClick(object sender, MouseEventArgs e)
  69. {
  70. }
  71.  
  72. private void Form1_MouseMove(object sender, MouseEventArgs e)
  73. {
  74. paddle.movePaddle(e.X);
  75. this.Invalidate();
  76. }
  77.  
  78. private void Form1_MouseDown(object sender, MouseEventArgs e)
  79. {
  80. }
  81.  
  82. private void Form1_MouseUp(object sender, MouseEventArgs e)
  83. {
  84. }
  85.  
  86. private void timer1_Tick(object sender, EventArgs e)
  87. {
  88. this.Invalidate();
  89. }
  90. private void timer2_Tick(object sender, EventArgs e)
  91. {
  92. }
  93. private void timer3_Tick(object sender, EventArgs e)
  94. {
  95. }
  96.  
  97. private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  98. {
  99. }
  100.  
  101. private void Form1_KeyDown(object sender, KeyEventArgs e)
  102. {
  103. }
  104.  
  105. private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  106. {
  107. myThread.Abort();
  108. Close();
  109. }
  110.  
  111. private void Form1_Load(object sender, EventArgs e)
  112. {
  113. }
  114.  
  115. private void pauseToolStripMenuItem_Click(object sender, EventArgs e)
  116. {
  117. if (paused == false)
  118. {
  119. paused = true;
  120. stopwatch.Stop();
  121. }
  122. else
  123. {
  124. paused = false;
  125. stopwatch.Start();
  126. }
  127.  
  128. ballUpdate.getPause(paused);
  129. }
  130.  
  131. private void brickPatternsToolStripMenuItem_Click(object sender, EventArgs e)
  132. {
  133. if (f2 != null) return;
  134. f2 = new Form2();
  135. f2.ShowDialog();
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement