using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Drawing;

namespace BouncingBalls
{
    public class Ball
    {
        public Rectangle Bounds;
        public int Vx, Vy;
        public Brush TheBrush;
        public Pen ThePen;
        public Ball(int x, int y, int width, int height, int vx, int vy, Brush brush, Pen pen)
        {
            Bounds = new Rectangle(x, y, width, height);
            Vx = vx;
            Vy = vy;
            TheBrush = brush;
            ThePen = pen;
        }

        // Update the ball's position. Return true if it bounces off an edge.
        public void Move(int xmax, int ymax)
        {
            // Update the X coordinate.
            Bounds.X += Vx;
            if (Bounds.X < 0)
            {
                Bounds.X = -Bounds.X;
                Vx = -Vx;
            }
            else if (Bounds.Right > xmax)
            {
                Bounds.X = xmax - (Bounds.Right - xmax) - Bounds.Width;
                Vx = -Vx;
            }

            // Update the Y coordinate.
            Bounds.Y += Vy;
            if (Bounds.Y < 0)
            {
                Bounds.Y = -Bounds.Y;
                Vy = -Vy;
            }
            else if (Bounds.Bottom > ymax)
            {
                Bounds.Y = ymax - (Bounds.Bottom - ymax) - Bounds.Height;
                Vy = -Vy;
            }
        }

        // Draw the ball.
        public void Draw(Graphics gr)
        {
            gr.FillEllipse(TheBrush, Bounds);
            gr.DrawEllipse(ThePen, Bounds);
        }
    }
}
