Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Threading;
- namespace BounceBall
- {
- public partial class Form1 : Form
- {
- Stopwatch stopwatch= new Stopwatch();
- Graphics paper;
- Paddle paddle = new Paddle();
- Ball ball = new Ball();
- Bricks bricks = new Bricks();
- Thread myThread;
- BallUpdate ballUpdate = new BallUpdate();
- int w, h;
- bool paused = false;
- TimeSpan ts;
- String elapsedtime;
- public Form2 f2 = null;
- int score;
- public Form1()
- {
- InitializeComponent();
- f2 = null;
- w = Width;
- h = Height;
- ballUpdate.getWH(w,h);
- myThread = new Thread(() => ballUpdate.ballMotion(ball, paddle, bricks));
- myThread.Start();
- stopwatch.Start();
- }
- public void Form1_Paint(object sender, PaintEventArgs e)
- {
- paper = e.Graphics;
- paddle.drawPaddle(paper);
- ball.drawBall(paper);
- bricks.drawBricks(paper);
- w = Width;
- h = Height;
- ballUpdate.getWH(w,h);
- ts = stopwatch.Elapsed;
- elapsedtime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
- ts.Hours, ts.Minutes, ts.Seconds,
- ts.Milliseconds / 10);
- label1.Text = elapsedtime;
- score=ballUpdate.getScore();
- label2.Text = "Score: " + score;
- }
- private void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- }
- private void Form1_MouseMove(object sender, MouseEventArgs e)
- {
- paddle.movePaddle(e.X);
- this.Invalidate();
- }
- private void Form1_MouseDown(object sender, MouseEventArgs e)
- {
- }
- private void Form1_MouseUp(object sender, MouseEventArgs e)
- {
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- this.Invalidate();
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- }
- private void timer3_Tick(object sender, EventArgs e)
- {
- }
- private void Form1_KeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- myThread.Abort();
- Close();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void pauseToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (paused == false)
- {
- paused = true;
- stopwatch.Stop();
- }
- else
- {
- paused = false;
- stopwatch.Start();
- }
- ballUpdate.getPause(paused);
- }
- private void brickPatternsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (f2 != null) return;
- f2 = new Form2();
- f2.ShowDialog();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement