using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cardvisa
{
    public partial class MusicGame : Form
    {
        public MusicGame()
        {
            InitializeComponent();
        }
        List<PictureBox> pictureBoxes = new List<PictureBox>();
        private void MusicGame_Load(object sender, EventArgs e)
        {   
            CreateSprite("\\res\\hakunefish.png");
            Thread thd = new Thread(() => {
                int count = 0;
                while (count <300)
                {
                    Thread.Sleep(25);
                    count = GamePlay(count);
                }
            });
            thd.Start();
        }
        private void CreateSprite(string path)
        {
            PictureBox pictureBox = new PictureBox();
            pictureBox.Location = new Point(0, 300);
            pictureBox.Size = new Size(100, 100);
            pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
            pictureBox.BackColor = Color.Transparent;
            pictureBox.Image = Image.FromFile(Application.StartupPath + path);
            pictureBox.Click += (object sender, EventArgs e)=>{
                PictureBox pbn = sender as PictureBox;
                pbn.Location = new Point(pbn.Location.X,pbn.Location.Y - 10);
            };
            Controls.Add(pictureBox);
            pictureBoxes.Add(pictureBox);
        }
        private int GamePlay(int count)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new Func<int,int>(GamePlay),count);
            }
            else
            {
                PictureBox pic = pictureBoxes[0];
                pic.Location = new Point(pic.Location.X + 1, pic.Location.Y);
            }
            return count + 1;
        }
    }
}
