NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// MEMBERS
// SIEGFRED TROY BAGASINA
// JASPER T ORCIGA
// FRANCIS LUIGI SOLANO
// SEAN PAUL NIEVA
// DAVE RANDELL ENDRANO

import java.util.Scanner;

public class BingoGame {
private static final int ROWS = 5;
private static final int COLS = 5;
private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {
System.out.println("Initializing Bingo game...");
boolean playAgain = true;

while (playAgain) {
playBingoGame();
System.out.println("Do you want to play again? (yes/no): ");
String playAgainInput = scanner.next();
playAgain = playAgainInput.equalsIgnoreCase("yes");
}

scanner.close();
System.out.println("Thank you for playing!");
}

private static void playBingoGame() {
System.out.println("How many cards do you want to play? ");
int numBoards = scanner.nextInt();

int[][][] allBoards = new int[numBoards][ROWS][COLS];

for (int boardNum = 0; boardNum < numBoards; boardNum++) {
System.out.println("nBoard #" + (boardNum + 1) + ":");
int[][] board = initializeBoard();
allBoards[boardNum] = board;
displayBoard(board);
System.out.println();
}

System.out.println("Let's play the game! Roll!");

StringBuilder rolledNumbers = new StringBuilder();

int winningCard = -1;
while (true) {
int number = (int) (Math.random() * 75) + 1;
rolledNumbers.append(number).append(" ");
System.out.println("rRolled Numbers: " + rolledNumbers);
winningCard = markNumberOnBoards(allBoards, number);
if (winningCard != -1) {
System.out.println("nBINGO at card #" + (winningCard + 1) + ". You won!");
break;
}
try {
Thread.sleep(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

private static int[][] initializeBoard() {
int[][] board = new int[ROWS][COLS];
boolean[] used = new boolean[75];

for (int i = 0; i < COLS; i++) {
for (int j = 0; j < ROWS; j++) {
int min = i * 15 + 1;
int max = (i + 1) * 15;
int number;
do {
number = (int) (Math.random() * (max - min + 1)) + min;
} while (used[number - 1]);
board[j][i] = number;
used[number - 1] = true;
}
}

// Free space
board[ROWS / 2][COLS / 2] = 0;

return board;
}

private static int markNumberOnBoards(int[][][] boards, int number) {
for (int i = 0; i < boards.length; i++) {
if (markNumber(boards[i], number) && isBingo(boards[i])) {
return i; // Return the winning card number
}
displayBoard(boards[i]);
System.out.println();
}
return -1; // No winning card found
}

private static boolean markNumber(int[][] board, int number) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
if (board[i][j] == number) {
board[i][j] = 0;
return true;
}
}
}
return false;
}

private static boolean isBingo(int[][] board) {
return isXPattern(board) || isBoxPattern(board) || isPlusSignPattern(board);
}

private static boolean isXPattern(int[][] board) {
return (board[0][0] == 0 && board[0][4] == 0 && board[1][1] == 0 && board[1][3] == 0 && board[2][2] == 0 &&
board[3][1] == 0 && board[3][3] == 0 && board[4][0] == 0 && board[4][4] == 0);
}

private static boolean isBoxPattern(int[][] board) {
return (board[0][0] == 0 && board[0][1] == 0 && board[0][2] == 0 && board[0][3] == 0 && board[0][4] == 0 &&
board[1][0] == 0 && board[1][4] == 0 &&
board[2][0] == 0 && board[2][4] == 0 &&
board[3][0] == 0 && board[3][4] == 0 &&
board[4][0] == 0 && board[4][1] == 0 && board[4][2] == 0 && board[4][3] == 0 && board[4][4] == 0);
}

private static boolean isPlusSignPattern(int[][] board) {
return (board[0][2] == 0 && board[1][2] == 0 && board[2][2] == 0 && board[3][2] == 0 && board[4][2] == 0)
&& (board[2][0] == 0 && board[2][1] == 0 && board[2][3] == 0 && board[2][4] == 0 && board[2][2] == 0);
}

private static void displayBoard(int[][] board) {
System.out.println("[ B][ I][ N][ G][ O]");
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
if (i == ROWS / 2 && j == COLS / 2) {
System.out.print("[FF]");
} else if (board[i][j] == 0) {
System.out.print("[ X]");
} else {
int value = board[i][j];
String formattedValue = String.format("[%2d]", value);
System.out.print(formattedValue);
}
}
System.out.println();
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.