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

namespace AppleHant
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 変数宣言
        Random rnd1;
        int hitcnt = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
            rnd1 = new Random();

            pictureBox1.Left = rnd1.Next(this.Width) ;
            pictureBox1.Top = -50;
            pictureBox1.Image = imageList1.Images[0];

            pictureBox2.Left = rnd1.Next(this.Width);
            pictureBox2.Top = -150;
            pictureBox2.Image = imageList1.Images[0];

            pictureBox3.Left = rnd1.Next(this.Width);
            pictureBox3.Top = -100;
            pictureBox3.Image = imageList1.Images[0];
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Top += 10;
            if (pictureBox1.Top >= this.Height)
            {
                pictureBox1.Left = rnd1.Next(this.Width);
                pictureBox1.Top = -50;
                pictureBox1.Image = imageList1.Images[0];
                pictureBox1.Enabled = true;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            pictureBox2.Top += 10;
            if (pictureBox2.Top >= this.Height)
            {
                pictureBox2.Left = rnd1.Next(this.Width);
                pictureBox2.Top = -150;
                pictureBox2.Image = imageList1.Images[0];
                pictureBox2.Enabled = true;
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            pictureBox3.Top += 8;
            if (pictureBox3.Top >= this.Height)
            {
                pictureBox3.Left = rnd1.Next(this.Width);
                pictureBox3.Top = -100;
                pictureBox3.Image = imageList1.Images[0];
                pictureBox3.Enabled = true;
            }
        }

        int cntdwn = 30;
        TypeConverter tc = new TypeConverter();
        private void timer4_Tick(object sender, EventArgs e)
        {
            cntdwn -= 1;
            label2.Text = tc.ConvertToString(cntdwn);
            if (cntdwn == 0)
            {
                timer1.Enabled = false;
                timer2.Enabled = false;
                timer3.Enabled = false;
                timer4.Enabled = false;
                MessageBox.Show("ゲーム終了");
                this.Close();
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            hitcnt += 1;
            label4.Text = tc.ConvertToString(hitcnt);
            pictureBox1.Image = imageList1.Images[1];
            pictureBox1.Enabled = false;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            hitcnt += 1;
            label4.Text = tc.ConvertToString(hitcnt);
            pictureBox2.Image = imageList1.Images[1];
            pictureBox2.Enabled = false;
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            hitcnt += 1;
            label4.Text = tc.ConvertToString(hitcnt);
            pictureBox3.Image = imageList1.Images[1];
            pictureBox3.Enabled = false;
        }
    }
}