private void openFile()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Balls file (*.bll)|*.bll";
            openFileDialog.Title  = "Open balls doc file";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileName = openFileDialog.FileName;
                try
                {
                    using (FileStream fileStream = new FileStream(FileName, FileMode.Open))
                    {
                        IFormatter formater = new BinaryFormatter();
                        ballsDoc = (BallsDoc)formater.Deserialize(fileStream);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not read file: " + FileName);
                    FileName = null;
                    return;
                }
                Invalidate(true);
            }
        }
Exemplo n.º 2
0
 public Form1()
 {
     InitializeComponent();
     BallsDoc            = new BallsDoc();
     Color               = Color.Red;
     Filename            = string.Empty;
     Random              = new Random();
     _left               = 10;
     _top                = menuStrip1.Height + toolStrip1.Height + Ball.Radius;
     _height             = this.Height - (int)(_top * 2);
     _width              = this.Width - (int)(_left * 3.5);
     this.DoubleBuffered = true;
 }
Exemplo n.º 3
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            if (MessageBox.Show("Are you sure you want to start a new game?", "Start a new game",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                BallsDoc = new BallsDoc();
                GenerateHoles();
                Filename = string.Empty;
                Invalidate(true);
            }

            timer1.Start();
        }
 public Form1()
 {
     InitializeComponent();
     ballsDoc            = new BallsDoc();
     currentColor        = Color.Red;
     this.DoubleBuffered = true;
     timer          = new Timer();
     timer.Interval = 50;
     timer.Tick    += new EventHandler(timer_Tick);
     timer.Start();
     leftX  = 20;
     topY   = 60;
     width  = this.Width - (3 * leftX);
     height = this.Height - (int)(2.5 * topY);
 }
Exemplo n.º 5
0
Arquivo: Form1.cs Projeto: AtanasK/VP
 public Form1()
 {
     InitializeComponent();
     ballsDoc = new BallsDoc();
     currentColor = Color.Red;
     this.DoubleBuffered = true;
     timer = new Timer();
     timer.Interval = 50;
     timer.Tick += new EventHandler(timer_Tick);
     timer.Start();
     leftX = 20;
     topY = 60;
     width = this.Width - (3 * leftX);
     height = this.Height - (int)(2.5 * topY);
     ballsDoc.GenerateHoles(leftX, topY, width, height);
 }
Exemplo n.º 6
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.White);

            var pen = new Pen(Color.Black, 3);

            e.Graphics.DrawRectangle(pen, _left, _top, _width, _height);
            pen.Dispose();

            BallsDoc.DrawHoles(e.Graphics, new Font("Arial", 20));
            BallsDoc.DrawBalls(e.Graphics);

            if (Filename != string.Empty)
            {
                this.Text = $"Balls in Holes | {Filename.Substring(Filename.LastIndexOf(@"\") + 1)}";
            }
            else
            {
                this.Text = "Balls in Holes";
            }
        }
Exemplo n.º 7
0
        private void GenerateHoles()
        {
            timer1.Stop();
            BallsDoc.ClearHoles();
            while (true)
            {
                if (BallsDoc.HolesCount() == 5)
                {
                    break;
                }
                int x      = Random.Next(_left + Hole.Radius * 2, _width - Hole.Radius * 2);
                int y      = Random.Next(_top + Hole.Radius * 2, _height - Hole.Radius * 2);
                var center = new Point(x, y);

                if (BallsDoc.HolesCount() == 0)
                {
                    BallsDoc.AddHole(center);
                }
                else
                {
                    var  h    = new Hole(center);
                    bool flag = true;
                    for (int i = 0; i < BallsDoc.HolesCount(); i++)
                    {
                        if (BallsDoc.Holes[i].TouchAnotherHole(h))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        BallsDoc.AddHole(center);
                    }
                }
            }

            Invalidate();
            timer1.Start();
        }
 private void newToolStripButton_Click(object sender, EventArgs e)
 {
     ballsDoc = new BallsDoc();
     Invalidate(true);
 }
Exemplo n.º 9
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     BallsDoc.MoveBalls(_left, _top, _width, _height);
     BallsDoc.BallsSwallow();
     Invalidate(true);
 }
Exemplo n.º 10
0
 private void statusStrip1_Paint(object sender, PaintEventArgs e)
 {
     lblBrTopcinja.Text = $"# Balls: {BallsDoc.BallsCount()}";
 }
Exemplo n.º 11
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     BallsDoc.AddBall(e.Location, Color);
     Invalidate(true);
 }
Exemplo n.º 12
0
Arquivo: Form1.cs Projeto: AtanasK/VP
 private void openFile()
 {
     OpenFileDialog openFileDialog = new OpenFileDialog();
     openFileDialog.Filter = "Balls file (*.bll)|*.bll";
     openFileDialog.Title = "Open balls doc file";
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         FileName = openFileDialog.FileName;
         try
         {
             using (FileStream fileStream = new FileStream(FileName, FileMode.Open))
             {
                 IFormatter formater = new BinaryFormatter();
                 ballsDoc = (BallsDoc)formater.Deserialize(fileStream);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Could not read file: " + FileName);
             FileName = null;
             return;
         }
         Invalidate(true);
     }
 }
Exemplo n.º 13
0
Arquivo: Form1.cs Projeto: AtanasK/VP
 private void newToolStripButton_Click(object sender, EventArgs e)
 {
     ballsDoc = new BallsDoc();
     Invalidate(true);
 }