//A class to generate the next random number private void getNextNumber() { RNGType rand = new RNGType(); textBox_number_called.Text = Convert.ToString(rand.getNextUniqueRandomValue(1, BINGOCARDSIZE * RNGRange, used)); }
// Creates the Bingo Card for Play private void createCard() { char[] bingoLetters = { 'B', 'I', 'N', 'G', 'O' }; RNGType RNGObj = new RNGType(); Random random = new Random(); int randomIndex = random.Next(0, 5); // Dynamically Creates 25 buttons on a Bingo Board // Written by Bill Hall with Joe Jupin and FLF // This should be enough help for all of you to adapt this to your own needs // Create and Add the buttons to the form Size size = new Size(75, 75); // if (gameCount > 0) size = new Size(40,40); Point loc = new Point(0, 0); int topMargin = 60; int x; int y; // Draw Column indexes y = 0; DrawColumnLabels(); x = xcardUpperLeft; y = ycardUpperLeft; // Draw top line for card drawHorizBar(x, y, BINGOCARDSIZE); y = y + barWidth; // The board is treated like a 5x5 array drawVertBar(x, y); for (int row = 0; row < BINGOCARDSIZE; row++) { loc.Y = topMargin + row * (size.Height + padding); int extraLeftPadding = 50; for (int col = 0; col < BINGOCARDSIZE; col++) { newButton[row, col] = new Button(); newButton[row, col].Location = new Point(extraLeftPadding + col * (size.Width + padding) + barWidth, loc.Y); newButton[row, col].Size = size; newButton[row, col].Font = new Font("Arial", 24, FontStyle.Bold); if (row == BINGOCARDSIZE / 2 && col == BINGOCARDSIZE / 2) { newButton[row, col].Font = new Font("Arial", 10, FontStyle.Bold); newButton[row, col].Text = "Free \n Space"; newButton[row, col].Enabled = false; newButton[row, col].BackColor = System.Drawing.Color.Orange; } else { newButton[row, col].Font = new Font("Arial", 24, FontStyle.Bold); newButton[row, col].Text = RNGObj.getRandomValue(bingoLetters[col]).ToString(); } // end if newButton[row, col].Name = "btn" + row.ToString() + col.ToString(); // Associates the same event handler with each of the buttons generated newButton[row, col].Click += new EventHandler(Button_Click); // Add button to the form pnlCard.Controls.Add(newButton[row, col]); // Draw vertical delimiter x += cardCellWidth + padding; if (row == 0) { drawVertBar(x - 5, y); } } // end for col // One row now complete // Draw bottom square delimiter if square complete x = xcardUpperLeft - 20; y = y + cardCellHeight + padding; drawHorizBar(x + 25, y - 10, BINGOCARDSIZE - 10); } // end for row // Draw column indices at bottom of card y += barWidth - 1; DrawColumnLabels(); Globals.selectedNumbersListObj.reset(); newButton[2, 2].Enabled = false; } // end createBoard
/* * Professor Friedman's code that creates the GUI of the card * Speaks for itself, no? */ private void CreateCard() { int numOfPossibleNumbers = BINGOCARDSIZE * RNGRange; // Total width and height of a card cell int cardCellWidth = numOfPossibleNumbers; int cardCellHeight = numOfPossibleNumbers; int barWidth = 6; // Width or thickness of horizontal and vertical bars int xcardUpperLeft = numOfPossibleNumbers; int ycardUpperLeft = numOfPossibleNumbers; int padding = 10; //rng object for this method CalledNumbersList ButtonRNGused = new CalledNumbersList(RNGRange * BINGOCARDSIZE); int topMargin = 175; // An array of button references must be declared and created as a global // (class) attribute elsewhere in the main form code. // Among other things, in this code we will create each Bingo card button as // we need it and assign the reference to this button to the appropriate // button reference variable in the array Size size = new Size(numOfPossibleNumbers, numOfPossibleNumbers); Point loc = new Point(0, 0); int x, y; newButton = new Button[BINGOCARDSIZE + 1, BINGOCARDSIZE + 1]; // Draw Column indexes y = 0; x = xcardUpperLeft; y = ycardUpperLeft; RNGType RNGObj = new RNGType(); char[] bingoLetters = new char[BINGOCARDSIZE + 1]; bingoLetters[1] = 'B'; //bingo letters bingoLetters[2] = 'I'; bingoLetters[3] = 'N'; bingoLetters[4] = 'G'; bingoLetters[5] = 'O'; for (int xx = 1; xx <= BINGOCARDSIZE; xx++) { loc.Y = topMargin + xx * (size.Height + padding); int extraLeftPadding = 50; for (int yy = 1; yy <= BINGOCARDSIZE; yy++) { newButton[xx, yy] = new Button(); newButton[xx, yy].Location = new Point(extraLeftPadding + (yy - 1) * (size.Width + padding) + barWidth, loc.Y); newButton[xx, yy].Size = size; newButton[xx, yy].Font = new Font("Arial", 24, FontStyle.Bold); if (xx == BINGOCARDSIZE / 2 + 1 && yy == BINGOCARDSIZE / 2 + 1) { newButton[xx, yy].Font = new Font("Arial", 10, FontStyle.Bold); newButton[xx, yy].Text = "Free \n Space"; newButton[xx, yy].BackColor = System.Drawing.Color.Orange; newButton[xx, yy].Enabled = false; } else { newButton[xx, yy].Font = new Font("Arial", 24, FontStyle.Bold); newButton[xx, yy].Text = RNGObj.getRandomValue(bingoLetters[yy], ButtonRNGused).ToString(); newButton[xx, yy].Enabled = true; } newButton[xx, yy].Name = "btn" + xx.ToString() + yy.ToString(); // Associates the same event handler with each of the buttons generated newButton[xx, yy].Click += new EventHandler(Button_Click); // Add button to the form this.Controls.Add(newButton[xx, yy]); // Draw vertical delimiter x += cardCellWidth + padding; } // end for col // One row now complete // Draw bottom square delimiter if square complete x = xcardUpperLeft - 20; y = y + cardCellHeight + padding; Label blabel = new Label(); blabel.Location = new Point(extraLeftPadding + padding, 200); blabel.Font = new Font("Arial", 26); //blabel.BackColor = System.Drawing.Color.Black; blabel.Text = "B I N G O"; blabel.Size = new Size(1000, 35); this.Controls.Add(blabel); } // end for row } // end createBoard