using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using Gin_Rummy_Game; namespace Gin_Rummy_GUI { public partial class GinRummyForm : Form { private static string CardImagesFolder = "C:\\Documents and Settings\\spannm\\Desktop\\Personal Stuff\\C#\\C# Projects VS2008\\Gin Rummy\\Gin Rummy Game\\Card Images\\"; private int numberOfPlayers, currentPlayer; private Player[] players; private String interactivePlayerName=null; private PictureBox[] selectedSwapPictureBoxes; private DeckOfCards drawDeck, discardDeck; private String faceDownCardFile = "b1fv.gif"; private int numberOfSwapPictureBoxes; public GinRummyForm() { numberOfPlayers = 4; selectedSwapPictureBoxes = new PictureBox[2]; InitializeComponent(); } private void displayHand(GroupBox gb, List hand, Boolean faceDown) { String cardFile = CardImagesFolder + faceDownCardFile; if (hand == null) return; hand.Sort(); int handSize = hand.Count; for (int cardNo = 0; cardNo < handSize; cardNo++) { Control c = gb.Controls[handSize-cardNo-1]; Type controlType = c.GetType(); if (!controlType.ToString().Equals("System.Windows.Forms.PictureBox")) return; PictureBox pb = (PictureBox)c; if (faceDown) pb.Image = Image.FromFile(cardFile); else { PlayingCard card = hand[cardNo]; pb.Image = card.getImage(); } } } private void updateDeckPanel() { if (drawDeck.Size == 0) { // Reshuffle the discard deck which becomes the draw deck do { PlayingCard card1 = discardDeck.drawCard(); drawDeck.addCard(card1); } while (discardDeck.Size > 0); drawDeck.shuffleDeck(); PlayingCard card = drawDeck.drawCard(); discardDeck.addCard(card); } String cardFile = CardImagesFolder + faceDownCardFile; deckPanel.Visible = true; PlayingCard card2 = discardDeck.TopCard; discardDeckPictureBox.Image = card2.getImage(); drawDeckPictureBox.Image = Image.FromFile(cardFile); // PlayingCard c1 = drawDeck.TopCard; // drawDeckPictureBox.Image = c1.getImage(); updateCountLabels(); } private void updateCountLabels() { drawDeckCountLabel.Text = drawDeck.Size + " cards"; discardDeckCountLabel.Text = discardDeck.Size+ " cards"; } private int getControlOfType(Panel p) { int controlIndex = 0; bool controlFound = false; do { if (p.Controls[controlIndex] is T) controlFound = true; else controlIndex++; } while ((!controlFound) && (controlIndex < p.Controls.Count)); return controlIndex; } private void showWinMessage(int winningPlayer) { // Display the hand if (winningPlayer > 0) // Autonomous player { Panel p = (Panel)computerPlayerPanels.Controls[winningPlayer - 1]; int controlIndex = getControlOfType(p); GroupBox gb = (GroupBox)(p.Controls[controlIndex]); // Should be GroupBox displayHand(gb, players[winningPlayer].Hand, false); } MessageBox.Show(players[winningPlayer].Name + " wins!"); // Disable all buttons and prompt for a new game gameTextBox.Text = "Click 'New Game' button to start"; for (int player = 0; player < numberOfPlayers; player++) { if (player > 0) { Panel p = (Panel)computerPlayerPanels.Controls[player - 1]; int controlIndex = getControlOfType