Question
Bingo is a game of chance. Each player takes a Bingo card. Each card has 25 spaces organized into 5 columns and 5 rows under
Bingo is a game of chance. Each player takes a Bingo card. Each card has 25 spaces organized into 5 columns and 5 rows under the "BINGO" header, as follows: Each space has a value between 1 and 75 selected at random, except no two spaces on a card can have the same value. The allowed range of values in each column is as follows: B: 1-15, I: 16-30, N: 31-45, G: 46-60, and O: 61-75 Then during game play, values between 1 and 75 are selected at random, traditionally by placing numbered balls in a basket and drawing them out one at a time. Once a number is selected, it must not be selected again in the same game. If a number on a card is selected, the player covers the corresponding space on the card. In addition, the center space (the third space down in the N column) is called FREE and is always covered. A player wins the game by covering any of the following: All the spaces in any row. All the spaces in any column. All the spaces on either diagonal. The four corner spaces. For this program you will write a Java FX GUI application that plays a simulation of an electronic Bingo game. Two players will play the game. Use a label text field for each player and a Play button. Generate and store two legal bingo cards. The middle square, the free square, is marked with an X. The two cards are generated at start-up, but play does not start until the user clicks Play. Begin to generate bingo numbers at random (i.e. B2, O63, etc.). Text fields, initially empty, are updated to display the Bingo numbers called for each card. For both cards check if the bingo number is on the card, and in that case mark the cell with an X, and check for a winning pattern. Continue playing until at least 1 player wins. When the game ends, a message dialog box pops up to announce the winner. A Reset button allows the user to start a new game at any time. Set the title to Bingo, and center the stage on the screen. Place all classes into one file. Output should be user friendly.
window.onload = initAll; var NumOfSquares = 24; var MaxNumber = 75; function initAll() { if (document.getElementById) { document.getElementById("reload").onclick = anotherCard; newCard(); } else { alert("Sorry, your browser doesn't support this script"); } } function newCard() { for (var i = 0; i < NumOfSquares; i++) { setSquare(i); } } function setSquare(thisSquare) { var currSquare = "square" + thisSquare; var colPlace = new Array(0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4); var colBasis = colPlace[thisSquare] * 15; var newNum; do { newNum = colBasis + getNewNum() + 1; } while (MaxNumber[newNum]); MaxNumber[newNum] = true; document.getElementById(currSquare).innerHTML = newNum; document.getElementById(currSquare).className = ""; document.getElementById(currSquare).onmousedown = toggleColor; } function getNewNum() { return Math.floor(Math.random() * 15); } function anotherCard() { for (var i = 1; i < MaxNumber.length; i++) { MaxNumber[i] = false; } newCard(); return false; } function toggleColor(evt) { if (evt) { var thisSquare = evt.target; } else { var thisSquare = window.event.srcElement; } if (thisSquare.className == "") { thisSquare.className = "pickedBG"; } else { thisSquare.className = ""; } checkWin(); } function checkWin() { var winningOption = -1; var setSquares = 0; var winners = new Array(40, 31, 992, 15360, 507904, 541729, 557328, 1083458, 2162820, 4329736, 8519745, 8659472, 16252928); for (var i = 0; i < 24; i++) { var currSquare = "square" + i; if (document.getElementById(currSquare).className != "") { document.getElementById(currSquare).className = "pickedBG"; setSquares = setSquares | Math.pow(2, i); } } for (var i = 0; i < winners.length; i++) { if ((winners[i] & setSquares) == winners[i]) { winningOption = i; } } if (winningOption > -1) { for (var i = 0; i < 24; i++) { if (winners[winningOption] & Math.pow(2, i)) { currSquare = "square" + i; document.getElementById(currSquare).className = "winningBG"; } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started