private void Message_SelectionChanged(object sender, RoutedEventArgs e) { if (MainWindow.name != null) { ChatMessage chatMessage = new ChatMessage(MainWindow.name, DateTime.Now.ToString("hh:mm:ss tt"), message); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); } else { ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), message); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); } }
private void btnStartMay_Click(object sender, RoutedEventArgs e) { UI = 1; if (dem1 == 0) { socket = IO.Socket(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString); btnStartMay.Content = "Change"; clsBanCo.Option.GamePlay = LuatChoi.International; clsBanCo.Option.WhoPlayWith = Player.MayOnline; clsBanCo.currPlayer = Player.Human; connect.connected(socket, txtYourName.Text.ToString()); dem1++; } else { connect.changname(socket, txtYourName.Text); } if( newgame == true) { ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), "Ván đáu mới, form mới tiếp tiếp tục nhé"); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); MessageBox.Show("Form mới chơi tốt nha bạn hehe !!!", "Thông báo"); banco.PlayAgain(); socket = IO.Socket(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString); btnStartMay.Content = "Change"; clsBanCo.Option.GamePlay = LuatChoi.International; clsBanCo.Option.WhoPlayWith = Player.MayOnline; clsBanCo.currPlayer = Player.Human; connect.connected(socket, txtYourName.Text.ToString()); connect.rw1 = -1; connect.cl1 = -1; newgame = false; } }
private void banco_WinEvent() { if (banco.End == Player.Human && BanCo.Option.WhoPlayWith == Player.Online) { string temp2 = txtYourName.Text + " won the game"; ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), temp2); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); dem = 1; dem1 = 1; UI = 0; } if (banco.End == Player.Online && BanCo.Option.WhoPlayWith == Player.Online) { string temp2 = MainWindow.name +" won the game" ; ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), temp2); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); dem = 1; dem1 = 1; UI = 0; } if (banco.End == Player.Human && BanCo.Option.WhoPlayWith == Player.MayOnline) { string temp2 = MainWindow.name + " won the game"; ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), temp2); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); dem = 1; dem1 = 1; UI = 0; } newgame = true; newgame1 = true; }
private void btnSend_Click(object sender, RoutedEventArgs e) { if (UI == 0) { ChatMessage chatMessage = new ChatMessage("Offline", DateTime.Now.ToString("hh:mm:ss tt"), txtMessage.Text); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); } else { connect.sendmessage(socket, txtYourName.Text, txtMessage.Text); } }
private void btnPlayerAgain_Click(object sender, RoutedEventArgs e) { ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), "Ván đáu mới, form mới tiếp tiếp tục nhé"); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); MessageBox.Show("Form mới chơi tốt nha bạn hehe !!!","Thông báo"); banco.PlayAgain(); }
private void btnPlay_Click(object sender, RoutedEventArgs e) { if (rdbhuman.IsChecked == false && rdbcomputer.IsChecked == false) { MessageBox.Show("Chọn chế độ chơi", "Thông báo"); } else { if (test == 0 && txtname2.Text == "Máy" && txtname1.Text != "") { clsBanCo.Option.PlayerAName = txtname1.Text; clsBanCo.Option.PlayerBName = txtname2.Text; ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), "Trò chơi bắt đầu"); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); banco.NewGame(); } else if (txtname1.Text != "" && txtname2.Text != "" && test == 1) { clsBanCo.Option.PlayerAName = txtname1.Text; clsBanCo.Option.PlayerBName = txtname2.Text; ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), "Trò chơi bắt đầu"); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); banco.NewGame(); } else { MessageBox.Show(" Chưa nhập tên người chơi", "Thông báo"); } } }
private void banco_LoseEvent() { if (clsBanCo.Option.WhoPlayWith == Player.Com && banco.End==Player.Com) { ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), "Cố lên nhé"); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); } if (banco.End == Player.Com && clsBanCo.Option.WhoPlayWith == Player.MayOnline) { string temp2 = txtYourName.Text + " won the game"; UI = 0; ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), temp2); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); dem = 1; dem1 = 1; } newgame = true; newgame1 = true; }
private void txt_change(object sender, TextChangedEventArgs e) { if(clsBanCo.currPlayer==Player.Online && clsBanCo.end==Player.None) { clsBanCo.board[clsBanCo.rows, clsBanCo.columns] = clsBanCo.currPlayer;//Lưu loại cờ vừa đánh vào mảng clsBanCo.DrawDataBoard(clsBanCo.rows, clsBanCo.columns, true, true); clsBanCo.end = clsBanCo.CheckEnd(clsBanCo.rows, clsBanCo.columns);//Kiểm tra xem trận đấu kết thúc chưa if (clsBanCo.end == Player.Online)//Nếu người chơi 2 thắng { clsBanCo.OnWin();//Khai báo sư kiện Win clsBanCo.OnWinOrLose();//Hiển thị 5 ô Win. ChatMessage chatMessage = new ChatMessage("Server", DateTime.Now.ToString("hh:mm:ss tt"), name+ " là người thắng"); chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top; chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; chatBox.Items.Add(chatMessage); btnstart.Content = "New game"; newgame1 = true; } else { clsBanCo.currPlayer = Player.Human;//Thiết lập lại lượt chơi clsBanCo.OnComDanhXong();// Khai báo sự kiện người chơi 2 đánh xong } } }