private void btnReady_Click(object sender, EventArgs e) { tcpForPlayer.SendData("chiabai"); string result = tcpForPlayer.ReadData(); //Nếu người chơi nhận được lượt đánh thì enable btbDanh int players = Convert.ToInt32(result[result.Length - 2].ToString()); op = new int[players - 1]; int Myturn = Convert.ToInt16(result.Last().ToString()); op[0] = (Myturn + 1) % players; for (int i = 1; i < players - 1; i++) { op[i] = (op[i - 1] + 1) % players; } if (result.Contains("turn")) { result = result.Remove(result.Length - 6);//Xóa 6 kí tự cuối chuối(là string "turni") btnDanh.Enabled = true; } else { result = result.Remove(result.Length - 2); } ConvertToListDouble(BaiHienTai, result);//Convert từ string sang List<double> //Kiểm tra xem bài của người cho có tới trắng hay không if (XuLyBai.KiemTraToiTrang(BaiHienTai) == true) { tcpForPlayer.SendData(ConvertToString(BaiHienTai) + "wintrang"); } txbBai.Text = ConvertToString(BaiHienTai);//gọi hàm load hình LoadHinh(BaiHienTai) for (int i = 0; i < BaiHienTai.Count(); i++) { pictureBoxList1[i].Visible = true; pictureBoxList1[i].Image = Image.FromFile(path + BaiHienTai[i].ToString() + ".png"); pictureBoxList1[i].BackColor = Color.White; pictureBoxList1[i].BorderStyle = BorderStyle.FixedSingle; pictureBoxList1[i].Tag = BaiHienTai[i]; } btnReady.Enabled = false; }
private void btnLogin_Click(object sender, EventArgs e) { Connect(); tcpForPlayer.SendData("dangnhap"); string t = tcpForPlayer.ReadData(); MessageBox.Show(t); Client c = new Client(tcpForPlayer, tcpForOpponent); this.Hide(); c.ShowDialog(); this.Show(); }
private void btnSearchRoom_Click(object sender, EventArgs e) { tcpForPlayer.SendData("timphong"); //string t=f.tcpForPlayer.ReadData(); string t = tcpForPlayer.ReadData(); MessageBox.Show(t); DanhBai d = new DanhBai(tcpForPlayer, tcpForOpponent); this.Hide(); d.ShowDialog(); //tcpForPlayer.SendData(textBox1.Text); //textBox2.Text=tcpForOpponent.ReadData(); }
public void Receive() { while (true) { bool anycards = true; string s = tcpForPlayer.ReadData(); if (string.Equals(s, "new")) { New = true; } // else { New = false; } string a = s; if (string.Equals(s, "OK")) //check "ok" signal from room { button2.Enabled = true; button3.Enabled = true; button2.BackColor = Color.PeachPuff; button3.BackColor = Color.PeachPuff; MessageBox.Show("It's " + this.Text + " turn"); } if (!Loaded) { arrPBleft[0] = pictureBox40; arrPBmid[0] = pictureBox27; arrPBright[0] = pictureBox53; arrPBleft[1] = pictureBox41; arrPBmid[1] = pictureBox28; arrPBright[1] = pictureBox54; arrPBleft[2] = pictureBox42; arrPBmid[2] = pictureBox29; arrPBright[2] = pictureBox55; arrPBleft[3] = pictureBox43; arrPBmid[3] = pictureBox30; arrPBright[3] = pictureBox56; arrPBleft[4] = pictureBox44; arrPBmid[4] = pictureBox31; arrPBright[4] = pictureBox57; arrPBleft[5] = pictureBox45; arrPBmid[5] = pictureBox32; arrPBright[5] = pictureBox58; arrPBleft[6] = pictureBox46; arrPBmid[6] = pictureBox33; arrPBright[6] = pictureBox59; arrPBleft[7] = pictureBox47; arrPBmid[7] = pictureBox34; arrPBright[7] = pictureBox60; arrPBleft[8] = pictureBox48; arrPBmid[8] = pictureBox35; arrPBright[8] = pictureBox61; arrPBleft[9] = pictureBox49; arrPBmid[9] = pictureBox36; arrPBright[9] = pictureBox62; arrPBleft[10] = pictureBox50; arrPBmid[10] = pictureBox37; arrPBright[10] = pictureBox63; arrPBleft[11] = pictureBox51; arrPBmid[11] = pictureBox38; arrPBright[11] = pictureBox64; arrPBleft[12] = pictureBox52; arrPBmid[12] = pictureBox39; arrPBright[12] = pictureBox65; for (int i = 0; i < 13; i++) { string temp = @"PNG\" + "blue_back.png";//img link arrPBleft[i].Image = Image.FromFile(temp); arrPBleft[i].SizeMode = PictureBoxSizeMode.StretchImage; arrPBmid[i].Image = Image.FromFile(temp); arrPBmid[i].SizeMode = PictureBoxSizeMode.StretchImage; arrPBright[i].Image = Image.FromFile(temp); arrPBright[i].SizeMode = PictureBoxSizeMode.StretchImage; } //load opp cards deck = s.Split(';');//get cards from server and split for (int i = 0; i < 13; i++) { Sort(deck, 13); if (string.Equals(deck[i], "15.1") || string.Equals(deck[i], "15.2") || string.Equals(deck[i], "15.3") || string.Equals(deck[i], "15.4")) { dem_heo++; } string temp = @"PNG\" + deck[i].Replace('.', '_') + ".png";//img link arrPB[i].Image = Image.FromFile(temp); arrPB[i].SizeMode = PictureBoxSizeMode.StretchImage; } Loaded = true; } if (anycards)//opp cards { try { if (!string.Equals(a, "OK")) { if (a.Contains("l>")) { string[] tam = a.Split('>'); //MessageBox.Show(tam[1]); string[] demso = tam[1].Split('/'); for (int i = 0; i < demso.Count() - 1; i++) { arrPBleft[l].Visible = false; l++; } a = a.Remove(0, 2); //MessageBox.Show(a); } if (a.Contains("m>")) { string[] tam = a.Split('>'); //MessageBox.Show(tam[1]); string[] demso = tam[1].Split('/'); for (int i = 0; i < demso.Count() - 1; i++) { arrPBmid[m].Visible = false; m++; } a = a.Remove(0, 2); //MessageBox.Show(a); } if (a.Contains("r>")) { string[] tam = a.Split('>'); //MessageBox.Show(tam[1]); string[] demso = tam[1].Split('/'); for (int i = 0; i < demso.Count() - 1; i++) { arrPBright[r].Visible = false; r++; } a = a.Remove(0, 2); //MessageBox.Show(a); } handDeck = a.Split('/'); bool havecard = false; for (int i = 0; i < 13; i++) { if (arrPBhands[i].Image != null) { havecard = true; } } if (havecard && button2.Enabled == false) { for (int i = 0; i < 13; i++) { arrPBhands[i].Image = null; } } for (int i = 0; i < handDeck.Count() - 1; i++) { string temp = @"PNG\" + handDeck[i].Replace('.', '_') + ".png"; arrPBhands[i].Image = Image.FromFile(temp); arrPBhands[i].SizeMode = PictureBoxSizeMode.StretchImage; } } }catch { anycards = false; } } if (Loaded) { int cwin = 0, cwin1 = 0; for (int i = 0; i < 13; i++) { if (string.Equals(deck[i], "3.1") || string.Equals(deck[i], "3.2") || string.Equals(deck[i], "3.3") || string.Equals(deck[i], "3.4")) { cwin++; } if (string.Equals(deck[i], "15.1") || string.Equals(deck[i], "15.2") || string.Equals(deck[i], "15.3") || string.Equals(deck[i], "15.4")) { cwin1++; } } if (cwin == 4 || cwin1 == 4) { MessageBox.Show(this.Text + " win!"); tcpForPlayer.SendData("~" + this.Text + " win!"); button1.Enabled = true; done = true; } if (s.Contains('~')) { button1.Enabled = true; button2.Enabled = button3.Enabled = false; MessageBox.Show(s); //string[] win = s.Split('~'); //string temp = ""; //for (int i = 0; i < (win.Count() - 1); i++) //{ // temp = temp + win[i]; // button1.Enabled = true; //} //MessageBox.Show(temp); done = true; return; } // MessageBox.Show("win count: " + win_count.ToString()); } } }
private void CountDownTimer_Tick(object sender, EventArgs e) { if (PBCountDown.Maximum - 100 == PBCountDown.Value) { if (OPlayerCard.Count == 0) { CardChoose.Clear(); CardChoose.Add(MyCard.First()); tcpForPlayer.SendData("|" + MyCard.First().GetName()); MyCard.Remove(MyCard.First()); SeperateData(CardChoose, CardHavePlay); SeperateData(MyCard, CardButton); } else { tcpForPlayer.SendData("Skip"); } yourturn = false; label2.Text = ""; CountDownTimer.Stop(); PBCountDown.Value = 0; PBCountDown.Visible = false; } else { PBCountDown.PerformStep(); } }