Example #1
0
        public new void CanMove(List <List <Button> > Matrix, Point point)
        {
            for (int i = 1; i >= -1; i--)
            {
                for (int j = 1; j >= -1; j--)
                {
                    if (point.X + i <= 7 && point.Y + j <= 7 && point.X + i >= 0 && point.Y + j >= 0)
                    {
                        if (Matrix[point.X + i][point.Y + j].Name == "NULL")
                        {
                            InfoStack info = new InfoStack(Matrix[point.X + i][point.Y + j].BackColor,
                                                           Matrix[point.X + i][point.Y + j].Name, point.X + i, point.Y + j);
                            Manager.stackInfo.Push(info);

                            Matrix[point.X + i][point.Y + j].BackColor = Color.LightBlue;
                            Matrix[point.X + i][point.Y + j].Name      = "A";
                        }
                        else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X + i][point.Y + j].Name) == false)
                        {
                            InfoStack info = new InfoStack(Matrix[point.X + i][point.Y + j].BackColor,
                                                           Matrix[point.X + i][point.Y + j].Name, point.X + i, point.Y + j);
                            Manager.stackInfo.Push(info);

                            Matrix[point.X + i][point.Y + j].BackColor = Color.Red;
                            Matrix[point.X + i][point.Y + j].Name      = "K";
                        }
                    }
                }
            }
        }
Example #2
0
        private void button_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            if (button.Name.Substring(0, 1) == CurrentPlayer)
            {
                string btnName = button.Name;
                while (stackInfo.Count > 0)
                {
                    InfoStack info = stackInfo.Pop();

                    Matrix[info.X][info.Y].BackColor = info.Color;
                    Matrix[info.X][info.Y].Name      = info.Name;
                }

                MoveButton(button, btnName);
            }
            else if ((button.Name == "A") || (button.Name == "K"))
            {
                string btnName = button.Name;
                while (stackInfo.Count > 0)
                {
                    InfoStack info = stackInfo.Pop();

                    Matrix[info.X][info.Y].BackColor = info.Color;
                    Matrix[info.X][info.Y].Name      = info.Name;
                }

                MoveButton(button, btnName);

                ChangePlayer();
            }
        }
Example #3
0
        public new void CanMove(List <List <Button> > Matrix, Point point)
        {
            int[] A = { 2, 2, 1, 1, -1, -1, -2, -2 };
            int[] B = { -1, 1, -2, 2, -2, 2, -1, 1 };
            for (int i = 0; i < 8; i++)
            {
                if (point.X + A[i] >= 0 && point.X + A[i] <= 7 && point.Y + B[i] >= 0 && point.Y + B[i] <= 7)
                {
                    if (Matrix[point.X + A[i]][point.Y + B[i]].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X + A[i]][point.Y + B[i]].BackColor,
                                                       Matrix[point.X + A[i]][point.Y + B[i]].Name, point.X + A[i], point.Y + B[i]);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X + A[i]][point.Y + B[i]].BackColor = Color.LightBlue;
                        Matrix[point.X + A[i]][point.Y + B[i]].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X + A[i]][point.Y + B[i]].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X + A[i]][point.Y + B[i]].BackColor,
                                                       Matrix[point.X + A[i]][point.Y + B[i]].Name, point.X + A[i], point.Y + B[i]);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X + A[i]][point.Y + B[i]].BackColor = Color.Red;
                        Matrix[point.X + A[i]][point.Y + B[i]].Name      = "K";
                    }
                }
            }
        }
Example #4
0
        public override void CanMove(List <List <Button> > Matrix, Point point)
        {
            if ((point.X == 6 && Matrix[point.X][point.Y].Name == "W_T") || (point.X == 1 && Matrix[point.X][point.Y].Name == "B_T"))
            {
                isFirstMove = 2;
            }
            else
            {
                isFirstMove = 1;
            }

            if (Matrix[point.X][point.Y].Name == "W_T")
            {
                for (int i = point.X - 1; i >= point.X - isFirstMove; i--)
                {
                    if (Matrix[i][point.Y].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[i][point.Y].BackColor, Matrix[i][point.Y].Name, i, point.Y);

                        Manager.stackInfo.Push(info);

                        Matrix[i][point.Y].BackColor = Color.LightBlue;
                        Matrix[i][point.Y].Name      = "A";
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (Matrix[point.X][point.Y].Name == "B_T")
            {
                for (int i = point.X + 1; i <= point.X + isFirstMove; i++)
                {
                    if (Matrix[i][point.Y].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[i][point.Y].BackColor, Matrix[i][point.Y].Name, i, point.Y);

                        Manager.stackInfo.Push(info);

                        Matrix[i][point.Y].BackColor = Color.LightBlue;
                        Matrix[i][point.Y].Name      = "A";
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Example #5
0
        public override void CanMove(List <List <Button> > Matrix, Point point)
        {
            int i;

            if (point.X - 1 >= 0)
            {
                for (i = point.X - 1; i >= 0; i--)//R_W di len
                {
                    if (Matrix[i][point.Y].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[i][point.Y].BackColor, Matrix[i][point.Y].Name, i, point.Y);

                        Manager.stackInfo.Push(info);

                        Matrix[i][point.Y].BackColor = Color.LightBlue;
                        Matrix[i][point.Y].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[i][point.Y].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[i][point.Y].BackColor, Matrix[i][point.Y].Name, i, point.Y);

                        Manager.stackInfo.Push(info);

                        Matrix[i][point.Y].BackColor = Color.Red;
                        Matrix[i][point.Y].Name      = "K";

                        i = -1;
                    }
                    else
                    {
                        i = -1;
                    }
                }
            }
            if (point.X + 1 <= 7)
            {
                for (i = point.X + 1; i <= 7; i++)//R_W di lui
                {
                    if (Matrix[i][point.Y].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[i][point.Y].BackColor, Matrix[i][point.Y].Name, i, point.Y);

                        Manager.stackInfo.Push(info);

                        Matrix[i][point.Y].BackColor = Color.LightBlue;
                        Matrix[i][point.Y].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[i][point.Y].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[i][point.Y].BackColor, Matrix[i][point.Y].Name, i, point.Y);

                        Manager.stackInfo.Push(info);

                        Matrix[i][point.Y].BackColor = Color.Red;
                        Matrix[i][point.Y].Name      = "K";

                        i = 8;
                    }
                    else
                    {
                        i = 8;
                    }
                }
            }
            if (point.Y - 1 >= 0)
            {
                for (i = point.Y - 1; i >= 0; i--)//R_W di sang trai
                {
                    if (Matrix[point.X][i].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X][i].BackColor, Matrix[point.X][i].Name, point.X, i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X][i].BackColor = Color.LightBlue;
                        Matrix[point.X][i].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X][i].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X][i].BackColor, Matrix[point.X][i].Name, point.X, i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X][i].BackColor = Color.Red;
                        Matrix[point.X][i].Name      = "K";

                        i = -1;
                    }
                    else
                    {
                        i = -1;
                    }
                }
            }
            if (point.Y + 1 <= 7)
            {
                for (i = point.Y + 1; i <= 7; i++)//R_W di sang phai
                {
                    if (Matrix[point.X][i].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X][i].BackColor, Matrix[point.X][i].Name, point.X, i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X][i].BackColor = Color.LightBlue;
                        Matrix[point.X][i].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X][i].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X][i].BackColor, Matrix[point.X][i].Name, point.X, i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X][i].BackColor = Color.Red;
                        Matrix[point.X][i].Name      = "K";

                        i = 8;
                    }
                    else
                    {
                        i = 8;
                    }
                }
            }

            i = 1;
            for (i = 1; i <= 7; i++)//len phai
            {
                if (point.X - i >= 0 && point.Y + i <= 7)
                {
                    if (Matrix[point.X - i][point.Y + i].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X - i][point.Y + i].BackColor, Matrix[point.X - i][point.Y + i].Name, point.X - i, point.Y + i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X - i][point.Y + i].BackColor = Color.LightBlue;
                        Matrix[point.X - i][point.Y + i].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X - i][point.Y + i].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X - i][point.Y + i].BackColor, Matrix[point.X - i][point.Y + i].Name, point.X - i, point.Y + i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X - i][point.Y + i].BackColor = Color.Red;
                        Matrix[point.X - i][point.Y + i].Name      = "K";

                        i = 8;
                    }
                    else
                    {
                        i = 8;
                    }
                }
                else
                {
                    break;
                }
            }
            for (i = 1; i <= 7; i++)// xuong phai
            {
                if (point.X + i <= 7 && point.Y + i <= 7)
                {
                    if (Matrix[point.X + i][point.Y + i].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X + i][point.Y + i].BackColor, Matrix[point.X + i][point.Y + i].Name, point.X + i, point.Y + i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X + i][point.Y + i].BackColor = Color.LightBlue;
                        Matrix[point.X + i][point.Y + i].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X + i][point.Y + i].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X + i][point.Y + i].BackColor, Matrix[point.X + i][point.Y + i].Name, point.X + i, point.Y + i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X + i][point.Y + i].BackColor = Color.Red;
                        Matrix[point.X + i][point.Y + i].Name      = "K";

                        i = 8;
                    }
                    else
                    {
                        i = 8;
                    }
                }
                else
                {
                    break;
                }
            }
            for (i = 1; i <= 7; i++)//Xuong Trai
            {
                if (point.X + i <= 7 && point.Y - i >= 0)
                {
                    if (Matrix[point.X + i][point.Y - i].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X + i][point.Y - i].BackColor, Matrix[point.X + i][point.Y - i].Name, point.X + i, point.Y - i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X + i][point.Y - i].BackColor = Color.LightBlue;
                        Matrix[point.X + i][point.Y - i].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X + i][point.Y - i].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X + i][point.Y - i].BackColor, Matrix[point.X + i][point.Y - i].Name, point.X + i, point.Y - i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X + i][point.Y - i].BackColor = Color.Red;
                        Matrix[point.X + i][point.Y - i].Name      = "K";

                        i = 8;
                    }
                    else
                    {
                        i = 8;
                    }
                }
                else
                {
                    break;
                }
            }
            for (i = 1; i <= 7; i++)// Len trai
            {
                if (point.X - i >= 0 && point.Y - i >= 0)
                {
                    if (Matrix[point.X - i][point.Y - i].Name == "NULL")
                    {
                        InfoStack info = new InfoStack(Matrix[point.X - i][point.Y - i].BackColor, Matrix[point.X - i][point.Y - i].Name, point.X - i, point.Y - i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X - i][point.Y - i].BackColor = Color.LightBlue;
                        Matrix[point.X - i][point.Y - i].Name      = "A";
                    }
                    else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X - i][point.Y - i].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[point.X - i][point.Y - i].BackColor, Matrix[point.X - i][point.Y - i].Name, point.X - i, point.Y - i);

                        Manager.stackInfo.Push(info);

                        Matrix[point.X - i][point.Y - i].BackColor = Color.Red;
                        Matrix[point.X - i][point.Y - i].Name      = "K";

                        i = 8;
                    }
                    else
                    {
                        i = 8;
                    }
                }
                else
                {
                    break;
                }
            }
        }
Example #6
0
        public void CanKill(List <List <Button> > Matrix, Point pointSource)
        {
            if (Matrix[pointSource.X][pointSource.Y].Name == "W_T")
            {
                if (pointSource.Y - 1 >= 0)
                {
                    if (Matrix[pointSource.X - 1][pointSource.Y - 1].BackgroundImage != null)
                    {
                        if (IsTeamMate(Matrix[pointSource.X][pointSource.Y].Name, Matrix[pointSource.X - 1][pointSource.Y - 1].Name) == false)
                        {
                            InfoStack info = new InfoStack(Matrix[pointSource.X - 1][pointSource.Y - 1].BackColor,
                                                           Matrix[pointSource.X - 1][pointSource.Y - 1].Name, pointSource.X - 1, pointSource.Y - 1);

                            Manager.stackInfo.Push(info);

                            Matrix[pointSource.X - 1][pointSource.Y - 1].BackColor = Color.Red;
                            Matrix[pointSource.X - 1][pointSource.Y - 1].Name      = "K";
                        }
                    }
                }
                if (Matrix[pointSource.X - 1][pointSource.Y + 1].BackgroundImage != null)
                {
                    if (IsTeamMate(Matrix[pointSource.X][pointSource.Y].Name, Matrix[pointSource.X - 1][pointSource.Y + 1].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[pointSource.X - 1][pointSource.Y + 1].BackColor,
                                                       Matrix[pointSource.X - 1][pointSource.Y + 1].Name, pointSource.X - 1, pointSource.Y + 1);

                        Manager.stackInfo.Push(info);

                        Matrix[pointSource.X - 1][pointSource.Y + 1].BackColor = Color.Red;
                        Matrix[pointSource.X - 1][pointSource.Y + 1].Name      = "K";
                    }
                }
            }
            if (Matrix[pointSource.X][pointSource.Y].Name == "B_T")
            {
                if (pointSource.Y - 1 >= 0)
                {
                    if (Matrix[pointSource.X + 1][pointSource.Y - 1].BackgroundImage != null)
                    {
                        if (IsTeamMate(Matrix[pointSource.X][pointSource.Y].Name, Matrix[pointSource.X + 1][pointSource.Y - 1].Name) == false)
                        {
                            InfoStack info = new InfoStack(Matrix[pointSource.X + 1][pointSource.Y - 1].BackColor,
                                                           Matrix[pointSource.X + 1][pointSource.Y - 1].Name, pointSource.X + 1, pointSource.Y - 1);

                            Manager.stackInfo.Push(info);

                            Matrix[pointSource.X + 1][pointSource.Y - 1].BackColor = Color.Red;
                            Matrix[pointSource.X + 1][pointSource.Y - 1].Name      = "K";
                        }
                    }
                }
                if (Matrix[pointSource.X + 1][pointSource.Y + 1].BackgroundImage != null)
                {
                    if (IsTeamMate(Matrix[pointSource.X][pointSource.Y].Name, Matrix[pointSource.X + 1][pointSource.Y + 1].Name) == false)
                    {
                        InfoStack info = new InfoStack(Matrix[pointSource.X + 1][pointSource.Y + 1].BackColor,
                                                       Matrix[pointSource.X + 1][pointSource.Y + 1].Name, pointSource.X + 1, pointSource.Y + 1);

                        Manager.stackInfo.Push(info);

                        Matrix[pointSource.X + 1][pointSource.Y + 1].BackColor = Color.Red;
                        Matrix[pointSource.X + 1][pointSource.Y + 1].Name      = "K";
                    }
                }
            }
        }
Example #7
0
        public override void CanMove(List <List <Button> > Matrix, Point point)
        {
            int dem = 0;

            int[] A = { -1, -2, -3, 1, 2 };
            for (int i = 1; i >= -1; i--)
            {
                for (int j = 1; j >= -1; j--)
                {
                    if (point.X + i <= 7 && point.Y + j <= 7 && point.X + i >= 0 && point.Y + j >= 0)
                    {
                        if (Matrix[point.X + i][point.Y + j].Name == "NULL")
                        {
                            if (point.X == 7 || point.X == 0)//nhap thanh
                            {
                                for (int go = 0; go <= 4; go++)
                                {
                                    InfoStack innt = new InfoStack(Matrix[point.X][point.Y + A[go]].BackColor,
                                                                   Matrix[point.X][point.Y + A[go]].Name, point.X, point.Y + A[go]);
                                    Manager.stackInfo.Push(innt);
                                    if (point.Y + A[go] < 4 && Matrix[point.X][point.Y + A[go]].Name == "NULL")// nhap thanh xa trai
                                    {
                                        dem++;
                                        if (dem == 3 && Matrix[point.X][point.Y - 4].Name == "W_R")
                                        {
                                            Matrix[point.X][point.Y - 2].BackColor = Color.LightBlue;
                                            Matrix[point.X][point.Y - 2].Name      = "A";
                                        }
                                        else if (dem == 3 && Matrix[point.X][point.Y - 4].Name == "B_R")
                                        {
                                            Matrix[point.X][point.Y - 2].BackColor = Color.LightBlue;
                                            Matrix[point.X][point.Y - 2].Name      = "A";
                                        }
                                    }
                                    else if (point.Y + A[go] > 4 && Matrix[point.X][point.Y + A[go]].Name == "NULL")// nhap thanh gan
                                    {
                                        dem++;
                                        if (dem == 2 && Matrix[point.X][point.Y + 3].Name == "W_R")
                                        {
                                            Matrix[point.X][point.Y + 2].BackColor = Color.LightBlue;
                                            Matrix[point.X][point.Y + 2].Name      = "A";
                                        }
                                        else if (dem == 2 && Matrix[point.X][point.Y + 3].Name == "B_R")
                                        {
                                            Matrix[point.X][point.Y + 2].BackColor = Color.LightBlue;
                                            Matrix[point.X][point.Y + 2].Name      = "A";
                                        }
                                    }
                                }
                            }
                            InfoStack info = new InfoStack(Matrix[point.X + i][point.Y + j].BackColor,
                                                           Matrix[point.X + i][point.Y + j].Name, point.X + i, point.Y + j);
                            Manager.stackInfo.Push(info);

                            Matrix[point.X + i][point.Y + j].BackColor = Color.LightBlue;
                            Matrix[point.X + i][point.Y + j].Name      = "A";
                        }
                        else if (IsTeamMate(Matrix[point.X][point.Y].Name, Matrix[point.X + i][point.Y + j].Name) == false)    //kill
                        {
                            InfoStack info = new InfoStack(Matrix[point.X + i][point.Y + j].BackColor,
                                                           Matrix[point.X + i][point.Y + j].Name, point.X + i, point.Y + j);
                            Manager.stackInfo.Push(info);

                            Matrix[point.X + i][point.Y + j].BackColor = Color.Red;
                            Matrix[point.X + i][point.Y + j].Name      = "K";
                        }
                    }
                }
            }
        }