Пример #1
0
        void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (t.IsEnabled)
            {
                switch (e.Key)
                {
                case Key.Down:
                    break;

                case Key.Up:
                    for (int c = 0; c < d.LangeliuKoord.Count; c++)
                    {
                        Point tmp = d.LangeliuKoord[c];
                        myBoard.NuspalvintLangeli(Convert.ToInt32(tmp.X), Convert.ToInt32(tmp.Y), Colors.Black);
                        d.LangeliuKoord[c] = tmp;
                    }
                    d.DetalesPasukimas(myBoard);
                    for (int c = 0; c < d.LangeliuKoord.Count; c++)
                    {
                        Point tmp = d.LangeliuKoord[c];
                        myBoard.NuspalvintLangeli(Convert.ToInt32(tmp.X), Convert.ToInt32(tmp.Y), d.Spalva);
                    }
                    break;

                case Key.Left:
                    if (!d.ArLieciaKaireSiena(myBoard.UzimtiLangeliai) && !d.ArLieciaDetalesKaire(myBoard.UzimtiLangeliai))
                    {
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            Point koord = d.LangeliuKoord[i];
                            myBoard.NuspalvintLangeli(Convert.ToInt32(koord.X), Convert.ToInt32(koord.Y), Colors.Black);
                            koord.Y           -= 1;
                            d.LangeliuKoord[i] = koord;
                        }
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            Point koord = d.LangeliuKoord[i];
                            myBoard.NuspalvintLangeli(Convert.ToInt32(koord.X), Convert.ToInt32(koord.Y), d.Spalva);
                            d.LangeliuKoord[i] = koord;
                        }
                    }
                    if (d.ArLieciaDetalesApacia(myBoard.UzimtiLangeliai))
                    {
                        t.IsEnabled = false;
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            int indeksas = Convert.ToInt32(d.LangeliuKoord[i].X * 10 - (10 - d.LangeliuKoord[i].Y) - 1);
                            myBoard.UzimtiLangeliai.Add(myBoard.VisiLangeliai[indeksas]);
                        }
                        for (int i = 1; i <= 20; i++)
                        {
                            if (myBoard.ArUzpildytaEile(i))
                            {
                                myBoard.PanaikintiEile(i);
                                Taskai          += 100;
                                blockTaskai.Text = Taskai.ToString();
                            }
                        }
                        StartAnimation();
                    }
                    break;

                case Key.Right:
                    if (!d.ArLieciaDesineSiena(myBoard.UzimtiLangeliai) && !d.ArLieciaDetalesDesine(myBoard.UzimtiLangeliai))
                    {
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            Point koord = d.LangeliuKoord[i];
                            myBoard.NuspalvintLangeli(Convert.ToInt32(koord.X), Convert.ToInt32(koord.Y), Colors.Black);
                            koord.Y           += 1;
                            d.LangeliuKoord[i] = koord;
                        }
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            Point koord = d.LangeliuKoord[i];
                            myBoard.NuspalvintLangeli(Convert.ToInt32(koord.X), Convert.ToInt32(koord.Y), d.Spalva);
                            d.LangeliuKoord[i] = koord;
                        }
                    }
                    if (d.ArLieciaDetalesApacia(myBoard.UzimtiLangeliai))
                    {
                        t.IsEnabled = false;
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            int indeksas = Convert.ToInt32(d.LangeliuKoord[i].X * 10 - (10 - d.LangeliuKoord[i].Y) - 1);
                            myBoard.UzimtiLangeliai.Add(myBoard.VisiLangeliai[indeksas]);
                        }
                        ArUzpildytaEile();
                        StartAnimation();
                    }
                    break;

                case Key.Space:
                    for (int i = 0; i < d.LangeliuKoord.Count; i++)
                    {
                        Point Koord = d.LangeliuKoord[i];
                        myBoard.NuspalvintLangeli(Convert.ToInt32(Koord.X), Convert.ToInt32(Koord.Y), Colors.Black);
                    }
                    while (!d.ArLieciaApatineSiena(myBoard.UzimtiLangeliai) && !d.ArLieciaDetalesApacia(myBoard.UzimtiLangeliai))
                    {
                        for (int i = 0; i < d.LangeliuKoord.Count; i++)
                        {
                            Point koord = d.LangeliuKoord[i];
                            koord.X           += 1;
                            d.LangeliuKoord[i] = koord;
                        }
                    }
                    for (int i = 0; i < d.LangeliuKoord.Count; i++)
                    {
                        int   indeksas = Convert.ToInt32(d.LangeliuKoord[i].X * 10 - (10 - d.LangeliuKoord[i].Y) - 1);
                        Point Koord    = d.LangeliuKoord[i];
                        myBoard.UzimtiLangeliai.Add(myBoard.VisiLangeliai[indeksas]);
                        myBoard.NuspalvintLangeli(Convert.ToInt32(Koord.X), Convert.ToInt32(Koord.Y), d.Spalva);
                    }
                    t.IsEnabled = false;
                    ArUzpildytaEile();
                    StartAnimation();
                    break;

                default:
                    break;
                }
            }
        }