示例#1
0
 private void btnEndGame_Click(object sender, EventArgs e)
 {
     lstCBPlayer1.Clear();
     lstCBPlayer2.Clear();
     pnlChessBoard.Controls.Clear();
     pnllstCB1Remove.Controls.Clear();
     pnllstCB2Remove.Controls.Clear();
     MovesOfChessMan.Clear();
     OldChessMan           = null;
     pnlBackGround.Visible = false;
     btnStartGame.Visible  = true;
 }
示例#2
0
        private void DeleteChessMan(ChessMan QuanCo)
        {
            int Height;
            int Width;

            if (CurrentPlayer == TurnPlay.Player1)
            {
                if (lstCBPlayer2.Count % 2 == 0)
                {
                    Height = (((Cons.ChessBoardSize * 2) - lstCBPlayer2.Count) * (Cons.ChessBoardHeight - 20)) / 2;
                    Width  = 0;
                }
                else
                {
                    Height = ((((Cons.ChessBoardSize * 2) - lstCBPlayer2.Count) * (Cons.ChessBoardHeight - 20)) / 2) - 20;
                    Width  = 60;
                }
                Button ShowBtnRemove = new Button()
                {
                    Location  = new Point(Width, Height),
                    Size      = new Size(Cons.ChessBoardWidth - 20, Cons.ChessBoardHeight - 20),
                    Text      = QuanCo.btn.Text,
                    BackColor = Color.White
                };
                pnllstCB2Remove.Controls.Add(ShowBtnRemove);
                lstCBPlayer2.Remove(QuanCo);
            }
            else
            {
                if (lstCBPlayer1.Count % 2 == 0)
                {
                    Height = (((Cons.ChessBoardSize * 2) - lstCBPlayer1.Count) * (Cons.ChessBoardHeight - 20)) / 2;
                    Width  = 0;
                }
                else
                {
                    Height = ((((Cons.ChessBoardSize * 2) - lstCBPlayer1.Count) * (Cons.ChessBoardHeight - 20)) / 2) - 20;
                    Width  = 60;
                }
                Button ShowBtnRemove = new Button()
                {
                    Location  = new Point(Width, Height),
                    Size      = new Size(Cons.ChessBoardWidth - 20, Cons.ChessBoardHeight - 20),
                    Text      = QuanCo.btn.Text,
                    BackColor = Color.White
                };

                pnllstCB1Remove.Controls.Add(ShowBtnRemove);

                lstCBPlayer1.Remove(QuanCo);
            }
        }
示例#3
0
        private List <Point> Chot(ChessMan QuanCo)
        {
            Point GetLocation = GetLocationFromChessMan(QuanCo);

            if (CurrentPlayer == TurnPlay.Player1)
            {
                if (lstChessBoard[GetLocation.X + 1, GetLocation.Y].Text == "")
                {
                    MovesOfChessMan.Add(new Point(GetLocation.X + 1, GetLocation.Y));
                }
                if (GetLocation.X == 1)
                {
                    if (lstChessBoard[GetLocation.X + 2, GetLocation.Y].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X + 2, GetLocation.Y));
                    }
                }
                if (GetLocation.Y - 1 >= 0)
                {
                    HandleTheEnemy(GetLocation.X + 1, GetLocation.Y - 1);
                }
                if (GetLocation.Y + 1 < Cons.ChessBoardSize)
                {
                    HandleTheEnemy(GetLocation.X + 1, GetLocation.Y + 1);
                }
            }
            else
            {
                if (lstChessBoard[GetLocation.X - 1, GetLocation.Y].Text == "")
                {
                    MovesOfChessMan.Add(new Point(GetLocation.X - 1, GetLocation.Y));
                }
                if (GetLocation.X == Cons.ChessBoardSize - 2)
                {
                    if (lstChessBoard[GetLocation.X - 2, GetLocation.Y].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X - 2, GetLocation.Y));
                    }
                }

                if (GetLocation.Y - 1 >= 0)
                {
                    HandleTheEnemy(GetLocation.X - 1, GetLocation.Y - 1);
                }
                if (GetLocation.Y + 1 < Cons.ChessBoardSize)
                {
                    HandleTheEnemy(GetLocation.X - 1, GetLocation.Y + 1);
                }
            }
            return(MovesOfChessMan);
        }
示例#4
0
        private void HandleTheWayOfChessMan(ChessMan QuanCo, Color clr)
        {
            List <Point> CacDiemCoTheDi = GetTypeOfChessMan(QuanCo);

            if (clr == Color.Aquamarine)
            {
                foreach (Point point in CacDiemCoTheDi)
                {
                    lstChessBoard[point.X, point.Y].BackColor = clr;
                    lstChessBoard[point.X, point.Y].Click    += Move_Click;
                }
            }
            else
            {
                foreach (Point point in CacDiemCoTheDi)
                {
                    lstChessBoard[point.X, point.Y].BackColor = clr;
                    lstChessBoard[point.X, point.Y].Click    -= Move_Click;
                }
            }
        }
示例#5
0
        void ChessMan_Click(object sender, EventArgs e)
        {
            ChessMan QuanCo = GetChessManByButton((Button)sender, CurrentPlayer);

            if (QuanCo.TrangThai == Statue.Hit)
            {
                HandleTheWayOfChessMan(QuanCo, Color.White);
                QuanCo.TrangThai = Statue.NotHit;
                OldChessMan      = null;
            }
            else
            {
                QuanCo.TrangThai = Statue.Hit;
                if (OldChessMan != null)
                {
                    HandleTheWayOfChessMan(OldChessMan, Color.White);
                    OldChessMan.TrangThai = Statue.NotHit;
                }
                OldChessMan = QuanCo;
                HandleTheWayOfChessMan(QuanCo, Color.Aquamarine);
            }
        }
示例#6
0
        void Move_Click(object sender, EventArgs e)
        {
            Button Move = sender as Button;

            HandleTheWayOfChessMan(OldChessMan, Color.White);
            if (Move.Text != "")
            {
                ChessMan Remove = GetChessManByButton((Button)sender, CurrentPlayer == TurnPlay.Player1 ? TurnPlay.Player2 : TurnPlay.Player1);
                DeleteChessMan(Remove);
                if (IsWin())
                {
                    MessageBox.Show(CurrentPlayer == TurnPlay.Player1 ? "Người chơi 1 thắng!" : "Người chơi 2 thắng");
                    pnlChessBoard.Enabled = false;
                    btnEndGame.Visible    = true;
                }
            }

            Move.Text = OldChessMan.Name;
            if (OldChessMan.btn.Text == "Chốt")
            {
                if (IsBecomeQueen(Int32.Parse(Move.Tag.ToString())))
                {
                    OldChessMan.Name = "Hậu";
                    Move.Text        = "Hậu";
                }
            }
            Move.ForeColor         = OldChessMan.clrText;
            OldChessMan.btn.Text   = "";
            OldChessMan.btn.Click -= ChessMan_Click;
            OldChessMan.TrangThai  = Statue.NotHit;
            OldChessMan.btn        = Move;
            OldChessMan.btn.Click += ChessMan_Click;
            DeleteEventFromChessMan(CurrentPlayer);
            CurrentPlayer = CurrentPlayer == TurnPlay.Player1 ? TurnPlay.Player2 : TurnPlay.Player1;
            CreateEventForChessMan(CurrentPlayer);
        }
示例#7
0
        private List <Point> Vua(ChessMan QuanCo)
        {
            Point GetLocation = GetLocationFromChessMan(QuanCo);

            if (GetLocation.X - 1 >= 0)
            {
                if (GetLocation.Y - 1 >= 0)
                {
                    if (lstChessBoard[GetLocation.X - 1, GetLocation.Y - 1].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X - 1, GetLocation.Y - 1));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X - 1, GetLocation.Y - 1);
                    }
                }

                if (GetLocation.Y + 1 < Cons.ChessBoardSize)
                {
                    if (lstChessBoard[GetLocation.X - 1, GetLocation.Y + 1].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X - 1, GetLocation.Y + 1));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X - 1, GetLocation.Y + 1);
                    }
                }

                if (lstChessBoard[GetLocation.X - 1, GetLocation.Y].Text == "")
                {
                    MovesOfChessMan.Add(new Point(GetLocation.X - 1, GetLocation.Y));
                }
                else
                {
                    HandleTheEnemy(GetLocation.X - 1, GetLocation.Y);
                }
            }

            if (GetLocation.X + 1 < Cons.ChessBoardSize)
            {
                if (GetLocation.Y - 1 >= 0)
                {
                    if (lstChessBoard[GetLocation.X + 1, GetLocation.Y - 1].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X + 1, GetLocation.Y - 1));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X + 1, GetLocation.Y - 1);
                    }
                }

                if (GetLocation.Y + 1 < Cons.ChessBoardSize)
                {
                    if (lstChessBoard[GetLocation.X + 1, GetLocation.Y + 1].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X + 1, GetLocation.Y + 1));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X + 1, GetLocation.Y + 1);
                    }
                }

                if (lstChessBoard[GetLocation.X + 1, GetLocation.Y].Text == "")
                {
                    MovesOfChessMan.Add(new Point(GetLocation.X + 1, GetLocation.Y));
                }
                else
                {
                    HandleTheEnemy(GetLocation.X + 1, GetLocation.Y);
                }
            }


            if (GetLocation.Y - 1 >= 0)
            {
                if (lstChessBoard[GetLocation.X, GetLocation.Y - 1].Text == "")
                {
                    MovesOfChessMan.Add(new Point(GetLocation.X, GetLocation.Y - 1));
                }
                else
                {
                    HandleTheEnemy(GetLocation.X, GetLocation.Y - 1);
                }
            }

            if (GetLocation.Y + 1 < Cons.ChessBoardSize)
            {
                if (lstChessBoard[GetLocation.X, GetLocation.Y + 1].Text == "")
                {
                    MovesOfChessMan.Add(new Point(GetLocation.X, GetLocation.Y + 1));
                }
                else
                {
                    HandleTheEnemy(GetLocation.X, GetLocation.Y + 1);
                }
            }
            return(MovesOfChessMan);
        }
示例#8
0
 private List <Point> Hau(ChessMan QuanCo)
 {
     MovesOfChessMan = Xe(QuanCo);
     MovesOfChessMan = Tuong(QuanCo);
     return(MovesOfChessMan);
 }
示例#9
0
        private List <Point> Tuong(ChessMan QuanCo)
        {
            Point GetLocation = GetLocationFromChessMan(QuanCo);

            //Duyệt chéo chính trên
            if (GetLocation.X != 0 && GetLocation.Y != 0)
            {
                for (int i = 1; GetLocation.X - i >= 0 && GetLocation.Y - i >= 0; i++)
                {
                    if (lstChessBoard[GetLocation.X - i, GetLocation.Y - i].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X - i, GetLocation.Y - i));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X - i, GetLocation.Y - i);
                        break;
                    }
                }
            }

            //Duyệt chéo chính dưới
            if (GetLocation.X < Cons.ChessBoardSize - 1 && GetLocation.Y < Cons.ChessBoardSize - 1)
            {
                for (int i = 1; GetLocation.Y + i < Cons.ChessBoardSize && GetLocation.X + i < Cons.ChessBoardSize; i++)
                {
                    if (lstChessBoard[GetLocation.X + i, GetLocation.Y + i].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X + i, GetLocation.Y + i));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X + i, GetLocation.Y + i);
                        break;
                    }
                }
            }

            //Duyệt chéo phụ trên
            if (GetLocation.X != 0 && GetLocation.Y < Cons.ChessBoardSize - 1)
            {
                for (int i = 1; GetLocation.X - i >= 0 && GetLocation.Y + i < Cons.ChessBoardSize; i++)
                {
                    if (lstChessBoard[GetLocation.X - i, GetLocation.Y + i].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X - i, GetLocation.Y + i));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X - i, GetLocation.Y + i);
                        break;
                    }
                }
            }
            //Duyệt chéo phụ dưới
            if (GetLocation.Y != 0 && GetLocation.X < Cons.ChessBoardSize - 1)
            {
                for (int i = 1; GetLocation.X + i < Cons.ChessBoardSize && GetLocation.Y - i >= 0; i++)
                {
                    if (lstChessBoard[GetLocation.X + i, GetLocation.Y - i].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X + i, GetLocation.Y - i));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X + i, GetLocation.Y - i);
                        break;
                    }
                }
            }
            return(MovesOfChessMan);
        }
示例#10
0
        private List <Point> Xe(ChessMan QuanCo)
        {
            Point GetLocation = GetLocationFromChessMan(QuanCo);

            //Duyệt bên trái
            if (GetLocation.Y != 0)
            {
                for (int i = GetLocation.Y - 1; i >= 0; i--)
                {
                    if (lstChessBoard[GetLocation.X, i].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X, i));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X, i);
                        break;
                    }
                }
            }

            //Duyệt bên phải
            if (GetLocation.Y != Cons.ChessBoardSize - 1)
            {
                for (int i = GetLocation.Y + 1; i < Cons.ChessBoardSize; i++)
                {
                    if (lstChessBoard[GetLocation.X, i].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(GetLocation.X, i));
                    }
                    else
                    {
                        HandleTheEnemy(GetLocation.X, i);
                        break;
                    }
                }
            }

            //Duyệt bên trên
            if (GetLocation.X != 0)
            {
                for (int i = GetLocation.X - 1; i >= 0; i--)
                {
                    if (lstChessBoard[i, GetLocation.Y].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(i, GetLocation.Y));
                    }
                    else
                    {
                        HandleTheEnemy(i, GetLocation.Y);
                        break;
                    }
                }
            }

            //Duyệt bên dưới
            if (GetLocation.X != Cons.ChessBoardSize - 1)
            {
                for (int i = GetLocation.X + 1; i < Cons.ChessBoardSize; i++)
                {
                    if (lstChessBoard[i, GetLocation.Y].Text == "")
                    {
                        MovesOfChessMan.Add(new Point(i, GetLocation.Y));
                    }
                    else
                    {
                        HandleTheEnemy(i, GetLocation.Y);
                        break;
                    }
                }
            }
            return(MovesOfChessMan);
        }