﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Animacija
{
    public partial class Igra : Form
    {
        // beležimo rezultat
        int zadetki = 0;

        // tabela, kjer shranimo diamante
        PictureBox[] diamanti = new PictureBox[7];

        public Igra()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            
            // poskrbimo, da zmaj ne gre ven iz okna
            if((rdeci_zmaj.Left+2)<(this.Width-rdeci_zmaj.Width))
                {
                rdeci_zmaj.Left += 2;
                }
            //presečišče zmaja in diamanta
            // && diamant_1.Visible - dodamo, ker drugač je več presečišč
            for (int i = 0; i < diamanti.Length; i++)
            {
                if (rdeci_zmaj.Bounds.IntersectsWith(diamanti[i].Bounds) && diamanti[i].Visible)
                {
                    // diamant "izgine"
                    diamanti[i].Hide();
                    zadetki += 1;
                    // dodamo v GUI
                    rezultat.Text = zadetki.ToString();

                }
            }

        }

        private void Animacija_Load(object sender, EventArgs e)
        {
            // preden se igra začne, dodajmo diamante v tabelo
            diamanti[0] = diamant_1;
            diamanti[1] = diamant_2;
            diamanti[2] = diamant_3;
            diamanti[3] = diamant_4;
            diamanti[4] = diamant_5;
            diamanti[5] = diamant_6;
            diamanti[6] = diamant_7;
            premik_zmaja.Start();
        }


        /// <summary>
        /// Potrebno je uporabiti overide, ker drugače program ne odreagira na pristik tipk na tipkovnici.
        /// </summary>
        /// <param name="keyData"></param>
        /// <returns></returns>
        protected override bool ProcessDialogKey(Keys keyData)
        {
            // premikamo zmaja gor in dol
            if (keyData == Keys.Up)
            {
                rdeci_zmaj.Top -= 5;
            }

            if (keyData == Keys.Down)
            {
                rdeci_zmaj.Top += 5;
            }
            return base.ProcessDialogKey(keyData);
        }

        private void Ustavitev_Click(object sender, EventArgs e2)
        {
            premik_zmaja.Stop();
        }

        private void naprej_Click(object sender, EventArgs e2)
        {
            premik_zmaja.Start();
        }

        /// <summary>
        /// Vrnemo se na začetek in popravimo podatke.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void na_zacetek_Click(object sender, EventArgs e)
        {
            rdeci_zmaj.Location = new Point(15, 200);
            zadetki = 0;
            for (int i = 0; i < diamanti.Length; i++)
            {
                diamanti[i].Visible=true;
                rezultat.Text = zadetki.ToString();
            }
        }


    }
}

