Bingo Card Game in Java
I created two methods for my Bingo Game in Java. One method creates a new
board which populates the Bingo Board with integers according to the Bingo
rule (1-75). My second method generates random numbers with a range of 1 -
75.
public static int drawNum(){
Random rand = new Random();
int num = rand.nextInt(75)+1;
return num;
}
public static void bingoCard(){
int [][]card=new int [5][5];
ArrayList<Integer> alreadyUsed = new ArrayList<Integer>();
boolean valid = false;
int tmp = 0;
for(int i = 0; i <= 4; i++){
for(int row = 0; row < card.length; row++){
while(!valid){
tmp = (int)(Math.random() * 15) + 1 + 15 * i;
if(!alreadyUsed.contains(tmp)){
valid = true;
alreadyUsed.add(tmp);
}
}
card[row][i] = tmp;
valid = false;
}
}
card[2][2] = 0;
//create array to make title.
String title []={"B","I","N","G","O"};
for(int i=0;i<title.length;i++){
System.out.print(title[i]+ "\t");
}
System.out.println();
for(int row=0;row<card.length;row++){
for(int col=0;col<card[row].length;col++){
System.out.print(card[row][col]+ "\t");
}
System.out.println();
}
}
What I need help with is, how do I check whether or not the drawNum()
method corresponds to any values stored inside my bingoCard() array? If
so, print out a new array with the integers filled in. If the condition is
met for a bingo, then you win.
I hope I don't make it sound like I want you to do it for me, but I am
confused as to how to start coding that part. Thank you.
No comments:
Post a Comment