示例#1
0
 public void Reset()
 {
     thuTu = 0;
     GiaTri = new Node[10];
     for (int i = 0; i < 10; i++)
     {
         GiaTri[i] = new Node();
     }
 }
示例#2
0
 public cls5OWin()
 {
     GiaTri = new Node[10];
     for (int i = 0; i < 10; i++)
     {
         GiaTri[i] = new Node();
     }
     thuTu = 0;
 }
示例#3
0
        //Hàm lấy vị trí có giá trị cao nhất trên bàn cờ
        public Node GetMaxNode()
        {
            Node n = new Node();
            int maxValue = GiaTri[0, 0];
            Node[] arrMaxNodes = new Node[289];
            for (int i = 0; i < 289; i++)
            {
                arrMaxNodes[i] = new Node();
            }
            int count = 0;
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (GiaTri[i, j] > maxValue)
                    {
                        n.Row = i;
                        n.Column = j;
                        maxValue = GiaTri[i, j];
                    }
                }
            }

            //Với mục đích không lặp lại bước đi giống như lần trước
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (GiaTri[i, j] == maxValue)
                    {
                        n.Row = i;
                        n.Column = j;
                        arrMaxNodes[count] = n;
                        count++;
                    }
                }
            }
            //Đường đi sẽ là ngẫu nhiên

            Random r = new Random();
            int soNgauNhien = r.Next(count);
            return arrMaxNodes[soNgauNhien];
        }
示例#4
0
 public void Add(Node n)
 {
     GiaTri[thuTu] = n;
     thuTu++;
 }
示例#5
0
        private void OnWinOrLose() // Nếu thắng hay thua thì báo người thnawgs thua và đánh dấu
        {
            Node node = new Node();
            for (int i = 0; i < 5; i++)
            {
                node = OWin.GiaTri[i];
                Rectangle rec = new Rectangle();
                rec.Height = 50;
                rec.Width = 50;
                rec.Opacity = 100;
                rec.HorizontalAlignment = 0;
                rec.VerticalAlignment = 0;
                rec.Margin = new Thickness(node.Column * length - 10, node.Row * length - 10, 0, 0);
                cvBanCo.Children.Add(rec);
            }

            if(this._menu.whoPlayWith == Player.Human) // Nếu là đánh với người
            {
                if(end == Player.Human) // Nếu là người chơi thứ nhất thắng
                {
                    tbNamePlay.Text = "^_^ " + this._menu.playerA + " is the Winner!!! ^_^";
                    this._menu.playerAScore++;
                }
                else if(end == Player.Com) // Nếu là người chơi thứ 2 thắng
                {
                    tbNamePlay.Text = "^_^ " + this._menu.playerB + " is the Winner!!! ^_^";
                    this._menu.playerBScore++;
                }
            }

            else if (this._menu.whoPlayWith == Player.Com) // Nếu là đánh với máy
            {
                if (end == Player.Human) // Nếu là người chơi thắng
                {
                    tbNamePlay.Text = "^_^ You are the Winner!!! ^_^";
                    this._menu.playerAScore++;
                }
                else if (end == Player.Com) // Nếu là máy thắng
                {
                    tbNamePlay.Text = " :(  You are the Loser!!!! :(";
                    this._menu.playerBScore++;
                }
            }
        }
示例#6
0
        public void BanCo_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            System.GC.Collect();//Thu gôm rác
            int cl, rw;
            Point toado = e.GetPosition(cvBanCo);//Lấy tọa độ chuột
            //Xử lý tọa độ
            cl = ((int)toado.X / length); // cột
            rw = ((int)toado.Y / length); // dòng

            #region Nếu đánh với người
            if (this._menu.whoPlayWith == Player.Human) // Nếu chơi với người
            {
                //Player.Com sẽ đóng vai trò người chơi thứ 2
                if (board[rw, cl] == Player.None)//Nếu ô bấm chưa có cờ
                {
                    if (this._menu.curPlay == Player.Human && end == Player.None)//Nếu lượt đi là người và trận đấu chưa kết thúc
                    {
                        tbNamePlay.Text = "Turns play of " + this._menu.playerB;
                        board[rw, cl] = this._menu.curPlay;//Lưu loại cờ vừa đánh vào mảng
                        DrawDataBoard(rw, cl);//Vẽ con cờ theo lượt chơi
                        end = CheckEnd(rw, cl);//Kiểm tra xem trận đấu kết thúc chưa
                        if (end == Player.Human)//Nếu người chơi 1 thắng
                        {
                            this._menu.curPlay = Player.Human; //Thiết lập lại lượt chơi
                            OnWin();//Khai báo sư kiện Win
                            OnWinOrLose();//Hiển thị 5 ô Win.
                        }
                        else
                        {
                            this._menu.curPlay = Player.Com;//Thiết lập lại lượt chơi
                            OnHumanDanhXong();// Khai báo sự kiện người chơi 1 đánh xong
                        }
                    }
                    else if (this._menu.curPlay == Player.Com && end == Player.None)
                    {
                        tbNamePlay.Text = "Turns play of " + this._menu.playerA;
                        board[rw, cl] = this._menu.curPlay;//Lưu loại cờ vừa đánh vào mảng
                        DrawDataBoard(rw, cl);//Vẽ con cờ theo lượt chơi
                        end = CheckEnd(rw, cl);//Kiểm tra xem trận đấu kết thúc chưa
                        if (end == Player.Com)//Nếu người chơi 2 thắng
                        {
                            OnWin();//Khai báo sư kiện Win
                            OnWinOrLose();//Hiển thị 5 ô Win.
                        }
                        else
                        {
                            this._menu.curPlay = Player.Human;//Thiết lập lại lượt chơi
                            OnComDanhXong();// Khai báo sự kiện người chơi 2 đánh xong
                        }
                    }
                }
            }
            #endregion
            #region Nếu đánh với máy
            else if (this._menu.whoPlayWith == Player.Com) // Nếu chọn đánh với máy
            {
                Node node = new Node();
                if (board[rw, cl] == Player.None) //Nếu ô bấm chưa có cờ
                {
                    if (this._menu.curPlay == Player.Human && end == Player.None)//Nếu lượt đi là người và trận đấu chưa kết thúc
                    {
                        tbNamePlay.Text = "Turns play of  Computer";
                        board[rw, cl] = this._menu.curPlay;//Lưu loại cờ vừa đánh vào mảng        
                        DrawDataBoard(rw, cl);//Vẽ con cờ theo lượt chơi
                        end = CheckEnd(rw, cl);//Kiểm tra xem trận đấu kết thúc chưa
                        if (end == Player.Human)//Nếu người thắng cuộc là người
                        {
                            OnWin();//Khai báo sự kiện Win
                            OnWinOrLose();//Hiển thị 5 ô Win.
                        }
                        else if (end == Player.None) //Nếu trận đấu chưa kết thúc
                        {
                            this._menu.curPlay = Player.Com;//Thiết lập lại lượt chơi
                            OnHumanDanhXong(); // Khai báo sự kiện người đánh xong
                        }
                    }
                    if (this._menu.curPlay == Player.Com && end == Player.None)//Nếu lượt đi là máy và trận đấu chưa kết thúc
                    {
                        //Tìm đường đi cho máy
                        tbNamePlay.Text = "Turns play of " + this._menu.yourName;
                        eBoard.ResetBoard();
                        LuongGia(Player.Com);//Lượng giá bàn cờ cho máy
                        node = eBoard.GetMaxNode();//lưu vị trí máy sẽ đánh
                        int r, c;
                        r = node.Row;
                        c = node.Column;
                        board[r, c] = this._menu.curPlay; //Lưu loại cờ vừa đánh vào mảng     
                        DrawDataBoard(r, c);//Vẽ con cờ theo lượt chơi
                        end = CheckEnd(r, c);//Kiểm tra xem trận đấu kết thúc chưa

                        if (end == Player.Com)//Nếu máy thắng
                        {
                            OnLose();//Khai báo sư kiện Lose
                            OnWinOrLose();//Hiển thị 5 ô Lose.
                        }
                        else if (end == Player.None)
                        {
                            this._menu.curPlay = Player.Human;//Thiết lập lại lượt chơi
                            OnComDanhXong();// Khai báo sự kiện người đánh xong
                        }
                    }
                }
            }
            #endregion
        }