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

namespace BilaPani
{
    public partial class FormHledaniCesty : Form
    {
        public FormHledaniCesty()
        {
            InitializeComponent();
        }

        private void konecToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void nahrátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                if (ManipulaceSeSoubory.ExistujeSoubor(openFileDialog1.FileName))
                {
                    ManipulaceSeSoubory.NahratMapu(openFileDialog1.FileName);
                    Vykreslovani.Init(platno.CreateGraphics());
                    Vykreslovani.Vykreslit();
                    label1.Text = "Celkem kroků: "+ mapa.NajdiCestu().ToString();
                }
        }

        private void buttonKrokVpred_Click(object sender, EventArgs e)
        {
            mapa.PosunBilePani(1);
            Vykreslovani.Vykreslit();
        }

        private void buttonKrokVzad_Click(object sender, EventArgs e)
        {
            mapa.PosunBilePani(-1);
            Vykreslovani.Vykreslit();
        }


        Thread vlakno;
        private void buttonAnimovat_Click(object sender, EventArgs e)
        {
            vlakno = new Thread(new ThreadStart(ref AnimacePohybu));
            vlakno.Start();
        }

        private void AnimacePohybu()
        {
            while (!mapa.PosunBilePani(0))
            {
                mapa.PosunBilePani(1);
                Vykreslovani.Vykreslit();
                Thread.Sleep(60);
            }
        }

        private void buttonZastavitAnimaci_Click(object sender, EventArgs e)
        {
            vlakno.Abort();
        }

        private void FormHledaniCesty_Load(object sender, EventArgs e)
        {
            vlakno = new Thread(new ThreadStart(ref AnimacePohybu));
        }
    }
}