/// <summary> /// Clones the dealer. /// </summary> /// <returns> newDealer </returns> public object Clone() { CardDealer newDealer = new CardDealer(MyDeck.Clone() as StandardDeck); return(newDealer); }
/// <summary> /// Game constructor that can take a deck size and a windows form /// </summary> /// <param name="deckSize">Default = 36</param> /// <param name="form">Default = null</param> /// <param name="playerName">Default = "Player 1"</param> public Game(int deckSize = 36, Form form = null, string playerName = "Player 1") { myForm = form; //set myForm to entered form myDeck = new StandardDeck(deckSize); // Create a deck based on the deck size arugment and assign to myDeck. myDealer = new CardDealer(myDeck, form); // Create a new dealer with myDeck and assign to myDealer. myPlayers.Add(new Human(newName: playerName, newForm: form)); //add new real player to players list myPlayers.Add(new Computer("Computer 1", newForm: form)); //add new computer player to players list foreach (Player player in myPlayers) //deal out 6 cards for each player { if (form != null) //check if form is not null { myDealer.DealHand(player, 6, form); //deal out 6 card for player passing along entered form } else //form is null { myDealer.DealHand(player, 6); //deal out 6 card for player passing along entered form } } trumpCard = new CardBox(myDealer.SelectTrumpCard()); //select trump card trump = trumpCard.Suit; //set trump PlayingCard.UseTrumps = true; PlayingCard.IsAceHigh = true; PlayingCard.Trump = trumpCard.Suit; if (form != null) //check if form is null { trumpCard.MyOrientation = Orientation.Horizontal; //chang trumpCard orientation to horizontal trumpCard.Location = new Point((form.Width - (trumpCard.Width + 40)), ((form.Height / 2) - (trumpCard.Height / 2))); //set trumpCard location form.Invoke((MethodInvoker) delegate //use the Invoke method to safely alter a control of the ui thread { form.Controls.Add(trumpCard); //add trumpCard control to form }); Label lblPlayerName = new Label(); //create a label for showing player name lblPlayerName.Location = new Point(70, (form.Height - 80)); //set label location lblPlayerName.Text = myPlayers[0].MyName; //set text of label to players name form.Invoke((MethodInvoker) delegate //use the Invoke method to safely alter a control of the ui thread { form.Controls.Add(lblPlayerName); //add label to form }); Label lblComputerName = new Label(); //create a label for showing player name lblComputerName.Location = new Point(70, 20); //set label location lblComputerName.Text = myPlayers[1].MyName; //set text of label to players name form.Invoke((MethodInvoker) delegate //use the Invoke method to safely alter a control of the ui thread { form.Controls.Add(lblComputerName); //add label to form }); Button btnPass = new Button(); btnPass.Size = new Size(100, 40); btnPass.Location = new Point(900, 500); btnPass.Enabled = false; btnPass.Text = "Pass"; passButton = btnPass; form.Invoke((MethodInvoker) delegate //use the Invoke method to safely alter a control of the ui thread { form.Controls.Add(passButton); }); passButton.Click += new EventHandler(Pass_Click); Label lblGamePrompt = new Label(); lblGamePrompt.Width = 200; lblGamePrompt.Text = "Game starting..."; lblGamePrompt.Location = new Point(50, 300); promptLabel = lblGamePrompt; form.Invoke((MethodInvoker) delegate //use the Invoke method to safely alter a control of the ui thread { form.Controls.Add(promptLabel); }); } // Disable all cards. // Add click event handler for each card. foreach (Player player in myPlayers) { foreach (CardBox cardBox in player.myCardBoxes) { cardBox.Click += new EventHandler(Card_Click); form.Invoke((MethodInvoker) delegate //use the Invoke method to safely alter a control of the ui thread { cardBox.Enabled = false; }); } } }