/// <summary>method:cardInUndeal_Click /// event handler for card click in undeal panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void cardInUndeal_Click(object sender, EventArgs e) { if (pnlTmp.Parent != null) { for (int i = (pnlTmp.Controls.Count - 1); i >= 0; i--) { Card card = pnlTmp.Controls[i] as Card; card.Location = card.Position; card.Parent = pnlTmp.Parent; card.BringToFront(); } pnlTmp.Parent = null; } Card self = sender as Card; self.CardDraw("unuse", form.unuse.Controls.Count * 2, form.unuse.Controls.Count * 2, 1); self.Parent = form.unuse; self.BringToFront(); // record move Card[] cardsArray = new Card[1]; cardsArray[0] = self; cardsArray[0].Position = cardsArray[0].Location; cardsArray[0].Click -= cardInUndeal_Click; cardsArray[0].Area = "unuse"; cardsArray[0].Name = cardsArray[0].Name.Substring(0, cardsArray[0].Name.Length - 1) + "1"; //cardsArray[0].Text = cardsArray[0].Name + "-"+cardsArray[0].Parent.Name; if (!AutoReplay.isAutoReplaying) { cms = RecordMove.RecordOneMove(cardsArray, form.undeal, form.unuse, form); lblCurrentStep.Text = cms.moves.Count.ToString(); } }
/// <summary>method:undoScreenShot /// redisplay the cards on tha table according to the infomation stored in the steplist /// </summary> /// <param name="form"></param> /// <param name="undoList"></param> public static void undoScreenShot(MainForm form, List <List <Card> > undoList) { cleanTable(form); for (int i = undoList.Count - 1; i >= 0; i--) { for (int j = undoList[i].Count - 1; j >= 0; j--) { Card card = undoList[i][j]; int y; if ("undeal".Equals(card.Area)) { y = undoList[i].Count - 1 - j; } else if ("set".Equals(card.Area.Substring(0, 3))) { y = 8 * (undoList[i].Count - 1 - j); } else { y = 30 * (undoList[i].Count - 1 - j); } card.CardDraw(card.Area, 0, y, (int)card.Side); AddComponentToContainer(form.Controls.Find(card.Area, true)[0] as Panel, card); } } }
/// <summary>method:resetUndealFromUnuse_Click /// event handler for clicking reset icon in undeal panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void resetUndealFromUnuse_Click(object sender, EventArgs e) { if (form.undeal.Controls.Count == 0) { if (pnlTmp.Parent != null) { for (int i = (pnlTmp.Controls.Count - 1); i >= 0; i--) { Card card = pnlTmp.Controls[i] as Card; card.Location = card.Position; card.Parent = pnlTmp.Parent; card.BringToFront(); } pnlTmp.Parent = null; } //MessageBox.Show("refreshed."); Card[] cardsArray = new Card[form.unuse.Controls.Count]; int count = form.unuse.Controls.Count - 1; for (int i = count; i >= 0; i--) { Card card = form.unuse.Controls[i] as Card; card.Area = "undeal"; card.Name = card.Name.Substring(0, card.Name.Length - 1) + "0"; //card.Text = card.Name + "-" + card.Area; card.Parent = form.undeal; card.Side = BackEnum.Back; card.Position = new Point(0, 0); card.CardDraw("undeal", 0, 0, -1); card.Click += cardInUndeal_Click; undealCards.Push(card); cardsArray[count - i] = card; } // record move if (!AutoReplay.isAutoReplaying) { cms = RecordMove.RecordOneMove(cardsArray, form.unuse, form.undeal, form); lblCurrentStep.Text = cms.moves.Count.ToString(); } } }
/// <summary>method:slot_DragDrop /// event handeling for drag and drop to slot(table) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void slot_DragDrop(object sender, DragEventArgs e) { if (pnlTmp.Controls.Count == 0) { return; } pnlTmp = ((Panel)e.Data.GetData(typeof(Panel))); pnlTmp.Name = "pnlTmp"; Card topCard = ((Card)pnlTmp.Controls[pnlTmp.Controls.Count - 1]);//-1 Panel targetPnl = (Panel)sender; string sourcePnlName = topCard.Area; if (topCard.Area.ToString() == targetPnl.Name.ToString()) { if (pnlTmp.Parent != null) { for (int i = (pnlTmp.Controls.Count - 1); i >= 0; i--) { Card card = pnlTmp.Controls[i] as Card; card.Location = card.Position; card.Parent = pnlTmp.Parent; card.BringToFront(); } pnlTmp.Parent = null; } return; } ; //rules: When the slot is empty, then it is only allowed to put in the cards which the ACE as the top card. if (!IsCanMovedTo(topCard, targetPnl, "SlotEmpty")) { return; } //rules:When the card's number is continuous and the colours are alternated, then they can be dropped. if (!IsCanMovedTo(topCard, targetPnl, "ContinuousAndColoursAlternated")) { return; } int movedCardsAmount = pnlTmp.Controls.Count; Card[] cardsArray = new Card[movedCardsAmount]; for (int i = 0; i < movedCardsAmount; i++) { cardsArray[i] = (Card)pnlTmp.Controls[i]; } int count = targetPnl.Controls.Count; for (int i = cardsArray.Length - 1; i >= 0; i--) { cardsArray[i].Location = new Point(0, (count) * 30); cardsArray[i].Position = cardsArray[i].Location; cardsArray[i].Click -= cardInUndeal_Click; cardsArray[i].Parent = targetPnl; cardsArray[i].Area = targetPnl.Name; //cardsArray[i].Text = cardsArray[i].Name + "-" + cardsArray[i].Area; cardsArray[i].BringToFront(); count++; } pnlTmp.Size = new Size(0, 0); pnlTmp.Parent = null; pnlTmp.SendToBack(); //source movement Panel sourcePnl = (Panel)form.Controls.Find(sourcePnlName, true)[0]; if (sourcePnl.Controls.Count >= 1) { Card lastCardInPanelAfterMove = (Card)(sourcePnl.Controls[0]); lastCardInPanelAfterMove.CardDraw(1); lastCardInPanelAfterMove.Name = lastCardInPanelAfterMove.Name.Substring(0, lastCardInPanelAfterMove.Name.Length - 1) + "1"; //lastCardInPanelAfterMove.Text = lastCardInPanelAfterMove.Name + "-"+lastCardInPanelAfterMove.Parent.Name; } // record move if (!AutoReplay.isAutoReplaying) { cms = RecordMove.RecordOneMove(cardsArray, sourcePnl, targetPnl, form); lblCurrentStep.Text = cms.moves.Count.ToString(); } //Discriminate failure: if (IsFailure(form)) { if (MessageBox.Show("You have been unable to successfully complete the game.") == DialogResult.OK) { return; } } }
/// <summary>method:set_DragDrop /// event handeling for drag and drop to sets /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void set_DragDrop(object sender, DragEventArgs e) { pnlTmp = ((Panel)e.Data.GetData(typeof(Panel))); if (pnlTmp.Controls.Count == 0) { return; } pnlTmp.Name = "pnlTmp"; Card topCard = ((Card)pnlTmp.Controls[pnlTmp.Controls.Count - 1]); string sourcePnlName = topCard.Area; Panel targetPnl = (Panel)sender; if (topCard.Area.ToString() == targetPnl.Name.ToString()) { if (pnlTmp.Parent != null) { for (int i = (pnlTmp.Controls.Count - 1); i >= 0; i--) { Card card = pnlTmp.Controls[i] as Card; card.Location = card.Position; card.Parent = pnlTmp.Parent; card.BringToFront(); } pnlTmp.Parent = null; } return; } ; //Rules:It is only allowed to put on "A" when the current set is empty if (!IsCanMovedToSet(new Card[1] { topCard }, targetPnl, "SetEmpty")) { return; } //Rules: It is only allowed to put on the card which is with the same suit and with 1 bigger digit than the one existing in the current set when the set is setting with certain digit if (!IsCanMovedToSet(pnlTmp.Controls.Cast <Control>().ToArray(), targetPnl, "SetNotEmpty")) { return; } int movedCardsAmount = pnlTmp.Controls.Count; Card[] cardsArray = new Card[movedCardsAmount]; for (int i = 0; i < movedCardsAmount; i++) { cardsArray[i] = (Card)pnlTmp.Controls[i]; } int count = targetPnl.Controls.Count; for (int i = cardsArray.Length - 1; i >= 0; i--) { cardsArray[i].Location = new Point(0, count * 8); cardsArray[i].Position = cardsArray[i].Location;////////////////// cardsArray[i].Click -= cardInUndeal_Click; cardsArray[i].Parent = targetPnl; cardsArray[i].Area = targetPnl.Name; //cardsArray[i].Text = cardsArray[i].Name + "-" + cardsArray[i].Area; cardsArray[i].BringToFront(); count++; } pnlTmp.Size = new Size(0, 0); pnlTmp.Parent = null; pnlTmp.SendToBack(); //source movement Panel sourcePnl = (Panel)form.Controls.Find(sourcePnlName, true)[0]; if (sourcePnl.Controls.Count >= 1) { Card lastCardInPanelAfterMove = (Card)(sourcePnl.Controls[0]); lastCardInPanelAfterMove.CardDraw(1); lastCardInPanelAfterMove.Name = lastCardInPanelAfterMove.Name.Substring(0, lastCardInPanelAfterMove.Name.Length - 1) + "1"; //lastCardInPanelAfterMove.Text = lastCardInPanelAfterMove.Name + "-"+lastCardInPanelAfterMove.Parent.Name; } // record move if (!AutoReplay.isAutoReplaying) { cms = RecordMove.RecordOneMove(cardsArray, sourcePnl, targetPnl, form); lblCurrentStep.Text = cms.moves.Count.ToString(); } //Identification completed successfully:All the cards in each one of the 4 sets are startted from A and then listed orderly from 6 to K and being with the same suit. if (IsCompletedSuccessfully(form, "Sets")) { if (MessageBox.Show("You have successfully completed the game") == DialogResult.OK) { Button btnReplay = form.Controls.Find("btnReplay", true)[0] as Button; form.customedTimer1.Stop(); //btnReplay.Enabled = true; return; } } }
/// <summary>method:FirstDeal /// Allocating playing cards /// </summary> /// <param name="form"></param> /// <param name="undealCardsTempParam"></param> /// <param name="undealCardsParam"></param> private static void FirstDeal(MainForm form, ref List <Card> undealCardsTempParam, out Stack <Card> undealCardsParam) { Stack <Card> innerStack = new Stack <Card>(); foreach (var card in undealCardsTempParam) { card.Click -= cardInUndeal_Click; innerStack.Push(card); } // deal out 28 cards to slot1~slot7 as initial display for (int i = 0; i < 28; i++) { Card card = innerStack.Pop() as Card; switch (i) { case 0: card.CardDraw("slot1", 0, 0, 1); AddComponentToContainer(slot1Pnl, card); break; case 1: card.CardDraw("slot2", 0, 0, -1); AddComponentToContainer(slot2Pnl, card); break; case 7: card.CardDraw("slot2", 0, 30, 1); AddComponentToContainer(slot2Pnl, card); break; case 2: card.CardDraw("slot3", 0, 0, -1); AddComponentToContainer(slot3Pnl, card); break; case 8: card.CardDraw("slot3", 0, 30, -1); AddComponentToContainer(slot3Pnl, card); break; case 13: card.CardDraw("slot3", 0, 60, 1); AddComponentToContainer(slot3Pnl, card); break; case 3: card.CardDraw("slot4", 0, 0, -1); AddComponentToContainer(slot4Pnl, card); break; case 9: card.CardDraw("slot4", 0, 30, -1); AddComponentToContainer(slot4Pnl, card); break; case 14: card.CardDraw("slot4", 0, 60, -1); AddComponentToContainer(slot4Pnl, card); break; case 18: card.CardDraw("slot4", 0, 90, 1); AddComponentToContainer(slot4Pnl, card); break; case 4: card.CardDraw("slot5", 0, 0, -1); AddComponentToContainer(slot5Pnl, card); break; case 10: card.CardDraw("slot5", 0, 30, -1); AddComponentToContainer(slot5Pnl, card); break; case 15: card.CardDraw("slot5", 0, 60, -1); AddComponentToContainer(slot5Pnl, card); break; case 19: card.CardDraw("slot5", 0, 90, -1); AddComponentToContainer(slot5Pnl, card); break; case 22: card.CardDraw("slot5", 0, 120, 1); AddComponentToContainer(slot5Pnl, card); break; case 5: card.CardDraw("slot6", 0, 0, -1); AddComponentToContainer(slot6Pnl, card); break; case 11: card.CardDraw("slot6", 0, 30, -1); AddComponentToContainer(slot6Pnl, card); break; case 16: card.CardDraw("slot6", 0, 60, -1); AddComponentToContainer(slot6Pnl, card); break; case 20: card.CardDraw("slot6", 0, 90, -1); AddComponentToContainer(slot6Pnl, card); break; case 23: card.CardDraw("slot6", 0, 120, -1); AddComponentToContainer(slot6Pnl, card); break; case 25: card.CardDraw("slot6", 0, 150, 1); AddComponentToContainer(slot6Pnl, card); break; case 6: card.CardDraw("slot7", 0, 0, -1); AddComponentToContainer(slot7Pnl, card); break; case 12: card.CardDraw("slot7", 0, 30, -1); AddComponentToContainer(slot7Pnl, card); break; case 17: card.CardDraw("slot7", 0, 60, -1); AddComponentToContainer(slot7Pnl, card); break; case 21: card.CardDraw("slot7", 0, 90, -1); AddComponentToContainer(slot7Pnl, card); break; case 24: card.CardDraw("slot7", 0, 120, -1); AddComponentToContainer(slot7Pnl, card); break; case 26: card.CardDraw("slot7", 0, 150, -1); AddComponentToContainer(slot7Pnl, card); break; case 27: card.CardDraw("slot7", 0, 180, 1); AddComponentToContainer(slot7Pnl, card); break; } } int iForInnerStack = 0; foreach (var card in innerStack) { card.CardDraw("undeal", iForInnerStack, iForInnerStack, -1); AddComponentToContainer(undealPnl, card); iForInnerStack += 2; } undealCardsParam = innerStack; }