//别人已出,自己应该出的牌 internal static ArrayList MustSendedCards(MainForm mainForm, int whoseOrder, CurrentPoker[] currentPokers, ArrayList[] currentSendCard, int suit, int rank, int count) { if (mainForm.UserAlgorithms[whoseOrder - 1] != null) { //组装牌 string pokers = currentPokers[whoseOrder - 1].getAllCards(); string[] allSendCards = { "", "", "", "" }; allSendCards[0] = mainForm.currentAllSendPokers[0].getAllCards(); allSendCards[1] = mainForm.currentAllSendPokers[1].getAllCards(); allSendCards[2] = mainForm.currentAllSendPokers[2].getAllCards(); allSendCards[3] = mainForm.currentAllSendPokers[3].getAllCards(); // IUserAlgorithm ua = (IUserAlgorithm)mainForm.UserAlgorithms[whoseOrder - 1]; ArrayList result = ua.MustSendCards(whoseOrder, suit, rank, mainForm.currentState.Master, mainForm.firstSend, allSendCards, currentSendCard, pokers); //判断合法性 bool b1 = TractorRules.IsInvalid(mainForm, currentSendCard, result, whoseOrder); bool b2 = TractorRules.CheckSendCards(mainForm, result, new ArrayList(), whoseOrder); if (b1 && b2) { int k = result.Count; for (int i = 0; i < k; i++) { CommonMethods.SendCards(currentSendCard[whoseOrder - 1], currentPokers[whoseOrder - 1], mainForm.pokerList[whoseOrder - 1], (int)result[i]); } } else { mainForm.UserAlgorithms[whoseOrder - 1] = null; MustSendCardsAlgorithm.MustSendCards(mainForm, currentPokers, whoseOrder, currentSendCard[whoseOrder - 1], count); } } else { MustSendCardsAlgorithm.MustSendCards(mainForm, currentPokers, whoseOrder, currentSendCard[whoseOrder - 1], count); } for (int i = 0; i < currentSendCard[whoseOrder - 1].Count; i++) { mainForm.currentAllSendPokers[whoseOrder - 1].AddCard((int)currentSendCard[whoseOrder - 1][i]); } return(currentSendCard[whoseOrder - 1]); }
private void MainForm_MouseDoubleClick(object sender, MouseEventArgs e) { //if (e.Button == MouseButtons.Right) // return; //如果当前没有牌可出 if (currentPokers[0].Count == 0) { return; } bool b = calculateRegionHelper.CalculateDoubleClickedRegion(e); if (!b) { return; } currentSendCards[0] = new ArrayList(); //出牌,所以擦去小猪 Rectangle pigRect = new Rectangle(296, 300, 53, 46); Graphics g = Graphics.FromImage(bmp); g.DrawImage(image, pigRect, pigRect, GraphicsUnit.Pixel); //扣牌还是出牌 if ((currentState.CurrentCardCommands == CardCommands.WaitingForSending8Cards) && (whoseOrder == 1)) //如果等我扣牌 { ArrayList readyCards = new ArrayList(); for (int i = 0; i < myCardIsReady.Count; i++) { if ((bool)myCardIsReady[i]) { readyCards.Add((int)myCardsNumber[i]); } } if (readyCards.Count == 8) { send8Cards = new ArrayList(); for (int i = 0; i < 8; i++) { CommonMethods.SendCards(send8Cards, currentPokers[0], pokerList[0], (int)readyCards[i]); } initSendedCards(); currentState.CurrentCardCommands = CardCommands.DrawMySortedCards; } } else if (currentState.CurrentCardCommands == CardCommands.WaitingForMySending) //如果等我发牌 { if (TractorRules.IsInvalid(this, currentSendCards, 1)) { if (firstSend == 1) { whoIsBigger = 1; ArrayList minCards = new ArrayList(); if (TractorRules.CheckSendCards(this, minCards, 0)) { currentSendCards[0] = new ArrayList(); for (int i = 0; i < myCardIsReady.Count; i++) { if ((bool)myCardIsReady[i]) { CommonMethods.SendCards(currentSendCards[0], currentPokers[0], pokerList[0], (int)myCardsNumber[i]); } } } else { for (int i = 0; i < minCards.Count; i++) { CommonMethods.SendCards(currentSendCards[0], currentPokers[0], pokerList[0], (int)minCards[i]); } } } else { currentSendCards[0] = new ArrayList(); for (int i = 0; i < myCardIsReady.Count; i++) { if ((bool)myCardIsReady[i]) { CommonMethods.SendCards(currentSendCards[0], currentPokers[0], pokerList[0], (int)myCardsNumber[i]); } } } drawingFormHelper.DrawMyFinishSendedCards(); } } }
private void MainForm_MouseClick(object sender, MouseEventArgs e) { //this.Text = "X=" + e.X + ",Y=" + e.Y + ";" + e.Clicks; //左键 //只有发牌时和该我出牌时才能相应鼠标事件 if (((currentState.CurrentCardCommands == CardCommands.WaitingForMySending) || (currentState.CurrentCardCommands == CardCommands.WaitingForSending8Cards)) && (whoseOrder == 1)) { if (e.Button == MouseButtons.Left) { if ((e.X >= (int)myCardsLocation[0] && e.X <= ((int)myCardsLocation[myCardsLocation.Count - 1] + 71)) && (e.Y >= 355 && e.Y < 472)) { if (calculateRegionHelper.CalculateClickedRegion(e, 1)) { drawingFormHelper.DrawMyPlayingCards(currentPokers[0]); Refresh(); } } } else if (e.Button == MouseButtons.Right) //右键 { int i = calculateRegionHelper.CalculateRightClickedRegion(e); if (i > -1 && i < myCardIsReady.Count) { bool b = (bool)myCardIsReady[i]; int x = (int)myCardsLocation[i]; for (int j = 1; j <= i; j++) { if ((int)myCardsLocation[i - j] == (x - 13)) { myCardIsReady[i - j] = b; x = x - 13; } else { break; } } drawingFormHelper.DrawMyPlayingCards(currentPokers[0]); Refresh(); } } //判断是否点击了小猪*********和以上的点击不同 Rectangle pigRect = new Rectangle(296, 300, 53, 46); Region region = new Region(pigRect); if (region.IsVisible(e.X, e.Y)) { //判断是否处在扣牌阶段 if ((currentState.CurrentCardCommands == CardCommands.WaitingForSending8Cards)) //如果等我扣牌 { //扣牌,所以擦去小猪 Graphics g = Graphics.FromImage(bmp); g.DrawImage(image, pigRect, pigRect, GraphicsUnit.Pixel); g.Dispose(); ArrayList readyCards = new ArrayList(); for (int i = 0; i < myCardIsReady.Count; i++) { if ((bool)myCardIsReady[i]) { readyCards.Add((int)myCardsNumber[i]); } } if (readyCards.Count == 8) { send8Cards = new ArrayList(); for (int i = 0; i < 8; i++) { CommonMethods.SendCards(send8Cards, currentPokers[0], pokerList[0], (int)readyCards[i]); } initSendedCards(); currentState.CurrentCardCommands = CardCommands.DrawMySortedCards; } } else if (currentState.CurrentCardCommands == CardCommands.WaitingForMySending) //如果等我发牌 { //如果我准备出的牌合法 if (TractorRules.IsInvalid(this, currentSendCards, 1)) { //出牌,所以擦去小猪 Graphics g = Graphics.FromImage(bmp); g.DrawImage(image, pigRect, pigRect, GraphicsUnit.Pixel); g.Dispose(); //在这里检查甩牌的检查 if (firstSend == 1) { whoIsBigger = 1; ArrayList minCards = new ArrayList(); if (TractorRules.CheckSendCards(this, minCards, 0)) { currentSendCards[0] = new ArrayList(); for (int i = 0; i < myCardIsReady.Count; i++) { if ((bool)myCardIsReady[i]) { CommonMethods.SendCards(currentSendCards[0], currentPokers[0], pokerList[0], (int)myCardsNumber[i]); } } } else { for (int i = 0; i < minCards.Count; i++) { CommonMethods.SendCards(currentSendCards[0], currentPokers[0], pokerList[0], (int)minCards[i]); } } } else { currentSendCards[0] = new ArrayList(); for (int i = 0; i < myCardIsReady.Count; i++) { if ((bool)myCardIsReady[i]) { CommonMethods.SendCards(currentSendCards[0], currentPokers[0], pokerList[0], (int)myCardsNumber[i]); } } } drawingFormHelper.DrawMyFinishSendedCards(); } } } } else if (currentState.CurrentCardCommands == CardCommands.ReadyCards) { drawingFormHelper.IsClickedRanked(e); } }