Exemplo n.º 1
0
        private void ChessButton_MouseDown(object sender, MouseEventArgs e)  //Tahtadaki Karelerin MouseDown eventi ..
        {
            ChessButton castedbutton = (ChessButton)sender;

            this.txt_tahta_x.Text = castedbutton.X.ToString();
            this.txt_tahta_y.Text = castedbutton.Y.ToString();
            if (castedbutton.Tas != null)
            {
                castedbutton.Tas.MakeCangoList();
                Holded = castedbutton.Tas;

                foreach (Kordinat VARIABLE in castedbutton.Tas.KordinatsCanGo)
                {
                    Squares[VARIABLE.Y, VARIABLE.X].BackColor = Color.Blue;
                }

                tasima = true;
            }

            else if (tasima)
            {
                PaintBoard();
                Holded.Move(castedbutton.X, castedbutton.Y);
                tasima = false;
            }
        }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            int Top   = SquareWidth * 7;
            int Left  = 0;
            int index = 0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Squares[i, j]                       = new ChessButton();
                    Squares[i, j].Dolumu                = false;
                    Squares[i, j].X                     = j;
                    Squares[i, j].Y                     = i;
                    Squares[i, j].MouseDown            += new System.Windows.Forms.MouseEventHandler(this.ChessButton_MouseDown);
                    Squares[i, j].Width                 = SquareWidth;
                    Squares[i, j].Height                = SquareHeight;
                    Squares[i, j].Left                  = Left;
                    Squares[i, j].Top                   = Top;
                    Squares[i, j].BackgroundImageLayout = ImageLayout.Zoom;
                    Squares[i, j].BackColor             = index % 2 == 0 ? Color.Black : Color.White;
                    Controls.Add(Squares[i, j]);
                    Left += SquareWidth;
                    index++;
                }

                Top -= SquareWidth;
                Left = 0;
                index++;
            }
        }
Exemplo n.º 3
0
        public Board()
        {
            int Top   = SquareWidth * 7;
            int Left  = 0;
            int index = 0;

            for (int i = 0; i < 8; i++)
            {
                Player1 = null;
                Player2 = null;
                for (int j = 0; j < 8; j++)
                {
                    Squares[i, j]                       = new ChessButton();
                    Squares[i, j].Dolumu                = false;
                    Squares[i, j].ChessBoard            = this;
                    Squares[i, j].X                     = j;
                    Squares[i, j].Y                     = i;
                    Squares[i, j].AllowDrop             = true;
                    Squares[i, j].MouseDown            += new System.Windows.Forms.MouseEventHandler(this.ChessButton_MouseDown);
                    Squares[i, j].DragDrop             += new System.Windows.Forms.DragEventHandler(this.chessButton_DragDrop);
                    Squares[i, j].DragEnter            += new System.Windows.Forms.DragEventHandler(this.chessButton_DragEnter);
                    Squares[i, j].Width                 = SquareWidth;
                    Squares[i, j].Height                = SquareHeight;
                    Squares[i, j].Left                  = Left;
                    Squares[i, j].Top                   = Top;
                    Squares[i, j].BackgroundImageLayout = ImageLayout.Zoom;
                    Squares[i, j].BackColor             = index % 2 == 0 ? Color.Gray : Color.White;
                    Left += SquareWidth;
                    index++;
                }
                Top -= SquareWidth;
                Left = 0;
                index++;
            }
        }
Exemplo n.º 4
0
        private void chessButton_DragDrop(object sender, DragEventArgs e)
        {
            // dragDrop Bitiþi
            ChessButton asd = (ChessButton)e.Data.GetData(typeof(ChessButton));

            asd.Tas.Move((sender as ChessButton).X, (sender as ChessButton).Y);
            PaintBoard();
        }
Exemplo n.º 5
0
        private void ChessButton_MouseDown(object sender, MouseEventArgs e)  //Tahtadaki Karelerin MouseDown eventi ..
        {
            PaintBoard();
            ChessButton castedbutton = (ChessButton)sender;

            this.txt_tahta_x.Text = castedbutton.X.ToString();
            this.txt_tahta_y.Text = castedbutton.Y.ToString();


            if (castedbutton.Tas != null && !tasima)
            {
                Oldx = castedbutton.X;
                Oldy = castedbutton.Y;
                castedbutton.Tas.MakeCangoList();
                Holded = castedbutton.Tas;

                foreach (Kordinat VARIABLE in castedbutton.Tas.KordinatsCanGo)
                {
                    Squares[VARIABLE.Y, VARIABLE.X].BackColor = Color.Blue;
                }

                tasima = true;
            }

            else if (tasima)
            {
                if (castedbutton.X == Oldx && castedbutton.Y == Oldy)
                {
                    tasima = false;
                }

                else
                {
                    if ((!TurnOfBlack && Holded.İsBlack) || (TurnOfBlack && !Holded.İsBlack)) // oyun sırası siyahta ama oynanan tas beyazsa ve tersi durum için hata fırlatma kısmı
                    {
                        MessageBox.Show("Oynama Sırası Karşı Tarafın ..");
                        tasima = false;
                    }
                    else
                    {
                        Holded.Move(castedbutton.X, castedbutton.Y);
                        tasima      = false;
                        TurnOfBlack = !TurnOfBlack;
                        EndGameCheck();
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void ChessButton_MouseDown(object sender, MouseEventArgs e)  //Tahtadaki Karelerin MouseDown eventi ..
        {
            if (Form1.isblack != TurnOfBlack)
            {
                MessageBox.Show("Karşı Hamle Bekleniyor !!");
                return;
            }

            ChessButton castedbutton = (ChessButton)sender;

            if (castedbutton.Tas != null)
            {
                castedbutton.Tas.MakeCangoList();

                foreach (Kordinat VARIABLE in castedbutton.Tas.KordinatsCanGo)
                {
                    if (VARIABLE.KordinatType == KordinatType.Attack && castedbutton.Tas.TasTipi == TasTipi.Piyon)
                    {
                        Piyon asd = (Piyon)castedbutton.Tas;
                        if (Squares[VARIABLE.Y, VARIABLE.X].Tas == null)
                        {
                            continue;
                        }
                        if (Squares[VARIABLE.Y, VARIABLE.X].Tas.İsBlack != asd.İsBlack)
                        {
                            Squares[VARIABLE.Y, VARIABLE.X].BackColor = Color.Yellow;
                        }
                    }
                    Squares[VARIABLE.Y, VARIABLE.X].BackColor = Color.Yellow;
                }

                ChessButton Sender = (ChessButton)sender; // drag drop baslangıcı
                if (Sender.Tas.İsBlack == TurnOfBlack)
                {
                    Sender.DoDragDrop(Sender, DragDropEffects.Copy);
                }
                else
                {
                    PaintBoard();
                    MessageBox.Show("Sıra Karşı Tarafın ..");
                }
            }
        }
Exemplo n.º 7
0
        static public void CreateTas(ChessButton button, TasTipi tipi, bool renk) // Tahta Üzerinde Combobox dan seçilen taşı Oluşturur  !!
        {
            TasTipi tip = tipi;                                                   //(TasTipi)cmb_tastipi.SelectedItem


            switch (tip)
            {
            case TasTipi.Kale:
                Kale Kale = new Kale(renk)
                {
                    TasKordinat = new Kordinat {
                        X = Convert.ToInt32(button.X), Y = Convert.ToInt32(button.Y)
                    }
                };
                button.Tas    = Kale;
                button.Dolumu = true;
                MevcutTaslar.Add(Kale);
                break;

            case TasTipi.Sah:
                Sah sah = new Sah(renk)
                {
                    TasKordinat = new Kordinat {
                        X = Convert.ToInt32(button.X), Y = Convert.ToInt32(button.Y)
                    }
                };
                button.Tas = sah;
                MevcutTaslar.Add(sah);
                button.Dolumu = true;
                break;

            case TasTipi.Piyon:
                Piyon piyon = new Piyon(renk)
                {
                    TasKordinat = new Kordinat {
                        X = Convert.ToInt32(button.X), Y = Convert.ToInt32(button.Y)
                    }
                };
                button.Tas = piyon;
                MevcutTaslar.Add(piyon);
                button.Dolumu = true;
                break;

            case TasTipi.Fil:
                Fil fil = new Fil(renk)
                {
                    TasKordinat = new Kordinat {
                        X = Convert.ToInt32(button.X), Y = Convert.ToInt32(button.Y)
                    }
                };
                button.Tas = fil;
                MevcutTaslar.Add(fil);
                button.Dolumu = true;
                break;

            case TasTipi.At:
                At at = new At(renk)
                {
                    TasKordinat = new Kordinat {
                        X = Convert.ToInt32(button.X), Y = Convert.ToInt32(button.Y)
                    }
                };
                button.Tas = at;
                MevcutTaslar.Add(at);
                button.Dolumu = true;
                break;

            case TasTipi.Vezir:
                Vezir vezir = new Vezir(renk)
                {
                    TasKordinat = new Kordinat {
                        X = Convert.ToInt32(button.X), Y = Convert.ToInt32(button.Y)
                    }
                };
                button.Tas = vezir;
                MevcutTaslar.Add(vezir);
                button.Dolumu = true;
                break;
            }



            button.GetBackgroundİmage();
        }
Exemplo n.º 8
0
        private void chessButton_DragDrop(object sender, DragEventArgs e)
        {
            ChessButton TB = (sender as ChessButton);                          // TB = Target Button
            ChessButton DB = (ChessButton)e.Data.GetData(typeof(ChessButton)); // DB = Dragged Button

            #region Rook'ları Kontrol Eden İf blokları

            if (TB.Dolumu && DB.Tas.Tasid == Tasİd.SiyahSah && TB.Tas.Tasid == Tasİd.SiyahKisaKale && (DB.Tas as Sah).isShortRookPossible())
            {
                (DB.Tas as Sah).LetsShortRook();
                PaintBoard();
                return;
            }
            else if (TB.Dolumu && DB.Tas.Tasid == Tasİd.SiyahSah && TB.Tas.Tasid == Tasİd.SiyahUzunKale && (DB.Tas as Sah).isLongRookPossible())
            {
                (DB.Tas as Sah).LetsLongRook();
                PaintBoard();
                return;
            }
            else if (TB.Dolumu && DB.Tas.Tasid == Tasİd.BeyazSah && TB.Tas.Tasid == Tasİd.BeyazKisaKale && (DB.Tas as Sah).isShortRookPossible())
            {
                (DB.Tas as Sah).LetsShortRook();
                PaintBoard();
                return;
            }
            else if (TB.Dolumu && DB.Tas.Tasid == Tasİd.BeyazSah && TB.Tas.Tasid == Tasİd.BeyazUzunKale && (DB.Tas as Sah).isLongRookPossible())
            {
                (DB.Tas as Sah).LetsLongRook();
                PaintBoard();
                return;
            }

            #endregion

            #region Enpas'Ları Kontrol Eden İf Blokları

            else if (DB.Tas.TasTipi == TasTipi.Piyon && (DB.Tas as Piyon).isRightEnpassPossible() && ((TB.X == DB.X + 1 && TB.Y == DB.Y + 1) || (TB.X == DB.X - 1 && TB.Y == DB.Y - 1)))
            {
                (DB.Tas as Piyon).LetsRightEnpass();
                PaintBoard();
                return;
            }
            else if (DB.Tas.TasTipi == TasTipi.Piyon && (DB.Tas as Piyon).isLeftEnpastPossible() && ((TB.X == DB.X - 1 && TB.Y == DB.Y + 1) || (TB.X == DB.X + 1 && TB.Y == DB.Y - 1)))
            {
                (DB.Tas as Piyon).LetsLeftEnpass();
                PaintBoard();
                return;
            }

            bool WillEnpassEnable = false;

            if (DB.Tas.TasTipi == TasTipi.Piyon && ((TB.X == DB.X && TB.Y == DB.Y + 2) || (TB.X == DB.X && TB.Y == DB.Y - 2)))
            {
                WillEnpassEnable = true;
            }
            Piyon asd = DB.Tas as Piyon;

            #endregion

            DB.Tas.Move(TB.X, TB.Y);
            PaintBoard();

            if (WillEnpassEnable)
            {
                asd.isEnpassEnable = true;
            }
        }
Exemplo n.º 9
0
        public Board(bool server, Form asd)
        {
            if (server)
            {
                Server = (Server)asd;

                int Top   = SquareWidth * 7;
                int Left  = 0;
                int index = 0;
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        Squares[i, j]                       = new ChessButton();
                        Squares[i, j].Dolumu                = false;
                        Squares[i, j].ChessBoard            = this;
                        Squares[i, j].X                     = j;
                        Squares[i, j].Y                     = i;
                        Squares[i, j].AllowDrop             = true;
                        Squares[i, j].MouseDown            += new System.Windows.Forms.MouseEventHandler(this.ChessButton_MouseDown);
                        Squares[i, j].DragDrop             += new System.Windows.Forms.DragEventHandler(this.chessButton_DragDrop);
                        Squares[i, j].DragEnter            += new System.Windows.Forms.DragEventHandler(this.chessButton_DragEnter);
                        Squares[i, j].Width                 = SquareWidth;
                        Squares[i, j].Height                = SquareHeight;
                        Squares[i, j].Left                  = Left;
                        Squares[i, j].Top                   = Top;
                        Squares[i, j].BackgroundImageLayout = ImageLayout.Zoom;
                        Squares[i, j].BackColor             = index % 2 == 0 ? Color.Gray : Color.White;
                        Left += SquareWidth;
                        index++;
                    }
                    Top -= SquareWidth;
                    Left = 0;
                    index++;
                }
            }

            if (!server)
            {
                Client = (Client)asd;

                int Top   = SquareWidth * 7;
                int Left  = 0;
                int index = 0;
                for (int i = 8 - 1; i >= 0; i--)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        Squares[i, j]                       = new ChessButton();
                        Squares[i, j].Dolumu                = false;
                        Squares[i, j].ChessBoard            = this;
                        Squares[i, j].X                     = j;
                        Squares[i, j].Y                     = i;
                        Squares[i, j].AllowDrop             = true;
                        Squares[i, j].MouseDown            += new System.Windows.Forms.MouseEventHandler(this.ChessButton_MouseDown);
                        Squares[i, j].DragDrop             += new System.Windows.Forms.DragEventHandler(this.chessButton_DragDrop);
                        Squares[i, j].DragEnter            += new System.Windows.Forms.DragEventHandler(this.chessButton_DragEnter);
                        Squares[i, j].Width                 = SquareWidth;
                        Squares[i, j].Height                = SquareHeight;
                        Squares[i, j].Left                  = Left;
                        Squares[i, j].Top                   = Top;
                        Squares[i, j].BackgroundImageLayout = ImageLayout.Zoom;
                        Squares[i, j].BackColor             = index % 2 == 0 ? Color.Gray : Color.White;
                        Left += SquareWidth;
                        index++;
                    }
                    Top -= SquareWidth;
                    Left = 0;
                    index++;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Tcp Listenerla karşıdan gelen hamleyi karşılayan fonksiyon .
        /// </summary>
        /// <param name="GelenHamle"></param>
        public void DragDrop(Command GelenHamle)
        {
            ChessButton TB = Squares[GelenHamle.To.Y, GelenHamle.To.X];     // TB = Target Button
            ChessButton DB = Squares[GelenHamle.From.Y, GelenHamle.From.X]; // DB = Dragged Button

            #region Rook'ları Kontrol Eden İf blokları

            if (TB.Dolumu && DB.Tas.Tasid == Tasİd.SiyahSah && TB.Tas.Tasid == Tasİd.SiyahKisaKale && (DB.Tas as Sah).isShortRookPossible())
            {
                (DB.Tas as Sah).LetsShortRook();
                PaintBoard();


                return;
            }
            else if (TB.Dolumu && DB.Tas.Tasid == Tasİd.SiyahSah && TB.Tas.Tasid == Tasİd.SiyahUzunKale && (DB.Tas as Sah).isLongRookPossible())
            {
                (DB.Tas as Sah).LetsLongRook();
                PaintBoard();

                return;
            }
            else if (TB.Dolumu && DB.Tas.Tasid == Tasİd.BeyazSah && TB.Tas.Tasid == Tasİd.BeyazKisaKale && (DB.Tas as Sah).isShortRookPossible())
            {
                (DB.Tas as Sah).LetsShortRook();
                PaintBoard();

                return;
            }
            else if (TB.Dolumu && DB.Tas.Tasid == Tasİd.BeyazSah && TB.Tas.Tasid == Tasİd.BeyazUzunKale && (DB.Tas as Sah).isLongRookPossible())
            {
                (DB.Tas as Sah).LetsLongRook();
                PaintBoard();

                return;
            }

            #endregion

            #region Enpas'Ları Kontrol Eden İf Blokları

            else if (DB.Tas.TasTipi == TasTipi.Piyon && (DB.Tas as Piyon).isRightEnpassPossible() && ((TB.X == DB.X + 1 && TB.Y == DB.Y + 1) || (TB.X == DB.X - 1 && TB.Y == DB.Y - 1)))
            {
                (DB.Tas as Piyon).LetsRightEnpass();
                PaintBoard();

                return;
            }
            else if (DB.Tas.TasTipi == TasTipi.Piyon && (DB.Tas as Piyon).isLeftEnpastPossible() && ((TB.X == DB.X - 1 && TB.Y == DB.Y + 1) || (TB.X == DB.X + 1 && TB.Y == DB.Y - 1)))
            {
                (DB.Tas as Piyon).LetsLeftEnpass();
                PaintBoard();

                return;
            }

            bool WillEnpassEnable = false;

            if (DB.Tas.TasTipi == TasTipi.Piyon && ((TB.X == DB.X && TB.Y == DB.Y + 2) || (TB.X == DB.X && TB.Y == DB.Y - 2)))
            {
                WillEnpassEnable = true;
            }
            Piyon asd = DB.Tas as Piyon;

            #endregion

            DB.Tas.Move(TB.X, TB.Y);
            PaintBoard();


            if (WillEnpassEnable)
            {
                asd.isEnpassEnable = true;
            }
        }
Exemplo n.º 11
0
        private void ChessButton_MouseDown(object sender, MouseEventArgs e)  //Tahtadaki Karelerin MouseDown eventi ..
        {
            PaintBoard();
            ChessButton castedbutton = (ChessButton)sender;


            this.txt_tahta_x.Text = castedbutton.X.ToString();
            this.txt_tahta_y.Text = castedbutton.Y.ToString();


            if (castedbutton.Tas != null && !tasima)
            {
                Oldx = castedbutton.X;
                Oldy = castedbutton.Y;
                castedbutton.Tas.MakeCangoList();
                Holded = castedbutton.Tas;


                foreach (Kordinat VARIABLE in castedbutton.Tas.KordinatsCanGo)
                {
                    if (VARIABLE.KordinatType == KordinatType.Attack && castedbutton.Tas.TasTipi == TasTipi.Piyon)
                    {
                        Piyon asd = (Piyon)castedbutton.Tas;
                        if (Squares[VARIABLE.Y, VARIABLE.X].Tas == null)
                        {
                            continue;
                        }
                        if (Squares[VARIABLE.Y, VARIABLE.X].Tas.ÝsBlack != asd.ÝsBlack)
                        {
                            Squares[VARIABLE.Y, VARIABLE.X].BackColor = Color.Yellow;
                        }
                    }
                    Squares[VARIABLE.Y, VARIABLE.X].BackColor = Color.Yellow;
                }

                //tasima = true;
                ChessButton asdf = (ChessButton)sender;
                asdf.DoDragDrop(asdf, DragDropEffects.Copy); // drag drop baþlangýcý
            }

            //else if (tasima)
            //{
            //    if (castedbutton.X == Oldx && castedbutton.Y == Oldy)
            //    {
            //        tasima = false;
            //    }

            //    else
            //    {
            //        if ((!TurnOfBlack && Holded.ÝsBlack) || (TurnOfBlack && !Holded.ÝsBlack)) // oyun sýrasý siyahta ama oynanan tas beyazsa ve tersi durum için hata fýrlatma kýsmý
            //        {
            //            MessageBox.Show("Oynama Sýrasý Karþý Tarafýn ..");
            //            tasima = false;
            //        }
            //        else
            //        {
            //            Holded.Move(castedbutton.X, castedbutton.Y);
            //            tasima = false;

            //        }

            //    }

            //}
        }