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;
- namespace _1_A
- {
- public partial class Form1 : Form
- {
- Random rnd = new Random();
- //Green Ball
- private int ball1Size = 50;
- private int ball1PosX;
- private int ball1PosY;
- private int step1X;
- private int step1Y;
- //Red Ball
- private int ball2Size = 100;
- private int ball2PosX;
- private int ball2PosY;
- private int step2X;
- private int step2Y;
- public Form1()
- {
- InitializeComponent();
- //Green Ball random starting point and Stepping
- ball1PosX = rnd.Next(0, this.panel1.Width - ball1Size);
- ball1PosY = rnd.Next(0, this.panel1.Height - ball1Size);
- step1X = rnd.Next(1, 5);
- step1Y = rnd.Next(1, 5);
- //Red Ball random starting point and Stepping
- ball2PosX = rnd.Next(0, this.panel1.Width - ball2Size);
- ball2PosY = rnd.Next(0, this.panel1.Height - ball2Size);
- step2X = rnd.Next(-5, -1);
- step2Y = rnd.Next(-5, -1);
- }
- private void Button_Click(object sender, EventArgs e)
- {
- richTextBox1.Text = "Some Text HERE";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- this.timer1.Enabled = true;
- }
- private void Paint_Circle(object sender, PaintEventArgs e)
- {
- e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- e.Graphics.Clear(this.BackColor);
- //Green Ball
- e.Graphics.FillEllipse(Brushes.Green, ball1PosX, ball1PosY, ball1Size, ball1Size);
- e.Graphics.DrawEllipse(Pens.Black, ball1PosX, ball1PosY, ball1Size, ball1Size);
- //Red Ball
- e.Graphics.FillEllipse(Brushes.Red, ball2PosX, ball2PosY, ball2Size, ball2Size);
- e.Graphics.DrawEllipse(Pens.Black, ball2PosX, ball2PosY, ball2Size, ball2Size);
- }
- private void MoveBall(object sender, EventArgs e)
- {
- //Green Ball Update position
- ball1PosX += step1X;
- if ( ball1PosX < 0 || ball1PosX + ball1Size > this.panel1.Width)
- {
- step1X = -step1X;
- }
- ball1PosY += step1Y;
- if (ball1PosY < 0 || ball1PosY + ball1Size > this.panel1.Height)
- {
- step1Y = -step1Y;
- }
- //Green Ball Update position
- ball2PosX += step2X;
- if (ball2PosX < 0 || ball2PosX + ball2Size > this.panel1.Width)
- {
- step2X = -step2X;
- }
- ball2PosY += step2Y;
- if (ball2PosY < 0 || ball2PosY + ball2Size > this.panel1.Height)
- {
- step2Y = -step2Y;
- }
- //Refresh Balls
- this.panel1.Refresh();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement