So I'm working on a personal project. Basically Bingo. Is there any possible way for you to see if an array contains a value? Here's the code i'm working on.
These lines are what i'm having trouble with.
Help would be appreciated. Thank you in advance!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends greenfoot.World
{
private Call call = new Call();
private Button button = new Button();
private boolean taken[] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
private Numbers numbers[] = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
private String called[] = {null};
private int arraySize = 0;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
initialize();
}
public void act()
{
update();
checkWin();
}
private void checkWin()
{
if (taken[0] == true & taken[1] == true & taken[2] == true & taken[3] == true & taken[4] == true)
{
win();
}
if (taken[5] == true & taken[6] == true & taken[7] == true & taken[8] == true & taken[9] == true)
{
win();
}
if (taken[10] == true & taken[11] == true & taken[12] == true & taken[13] == true & taken[14] == true)
{
win();
}
if (taken[15] == true & taken[16] == true & taken[17] == true & taken[18] == true & taken[19] == true)
{
win();
}
if (taken[20] == true & taken[21] == true & taken[22] == true & taken[23] == true & taken[24] == true)
{
win();
}
if (taken[0] == true & taken[5] == true & taken[10] == true & taken[15] == true & taken[20] == true)
{
win();
}
if (taken[1] == true & taken[6] == true & taken[11] == true & taken[16] == true & taken[21] == true)
{
win();
}
if (taken[2] == true & taken[7] == true & taken[12] == true & taken[17] == true & taken[22] == true)
{
win();
}
if (taken[3] == true & taken[8] == true & taken[13] == true & taken[18] == true & taken[23] == true)
{
win();
}
if (taken[4] == true & taken[9] == true & taken[14] == true & taken[19] == true & taken[24] == true)
{
win();
}
if (taken[0] == true & taken[6] == true & taken[12] == true & taken[18] == true & taken[24] == true)
{
win();
}
if (taken[4] == true & taken[8] == true & taken[12] == true & taken[16] == true & taken[20] == true)
{
win();
}
}
private void win()
{
removeObject(button);
removeObject(call);
GreenfootImage img = new GreenfootImage("Bingo!",50,Color.BLACK,Color.WHITE);
getBackground().drawImage(img,100-img.getWidth()/2,getHeight()/2-img.getHeight()/2);
Greenfoot.stop();
}
private void initialize()
{
addObject(new Board(),400,200);
int y = 99;
int x = 240;
int identifier = 0;
do
{
numbers[identifier] = new Numbers('b',identifier);
addObject(numbers[identifier],x,y);
y = y + 66;
identifier++;
}while(y != 429);
x = x + 80;
y = 99;
do
{
numbers[identifier] = new Numbers('i',identifier);
addObject(numbers[identifier],x,y);
y = y + 66;
identifier++;
}while(y != 429);
x = x + 80;
y = 99;
do
{
numbers[identifier] = new Numbers('n',identifier);
addObject(numbers[identifier],x,y);
y = y + 66;
identifier++;
}while(y != 429);
x = x + 80;
y = 99;
do
{
numbers[identifier] = new Numbers('g',identifier);
addObject(numbers[identifier],x,y);
y = y + 66;
identifier++;
}while(y != 429);
x = x + 80;
y = 99;
do
{
numbers[identifier] = new Numbers('o',identifier);
addObject(numbers[identifier],x,y);
y = y + 66;
identifier++;
}while(y != 429);
int number = 0;
do
{
taken[number] = false;
number++;
}while(number != 25);
addObject(call,100,100);
addObject(button,100,350);
}
public void call()
{
int callNum = Greenfoot.getRandomNumber(51);
char callChar[] = {'b','i','n','g','o'};
int randomNum = Greenfoot.getRandomNumber(5);
int identifier = 0;
String totalCall = "" + callChar[randomNum] + callNum;
do
{
callNum = Greenfoot.getRandomNumber(51);
randomNum = Greenfoot.getRandomNumber(5);
identifier = 0;
totalCall = "" + callChar[randomNum] + callNum;
}while(arrayContains(totalCall));
call.setCall(callChar[randomNum],callNum);
do
{
if (totalCall.equals(numbers[identifier].getCall()))
{
numbers[identifier].setClickable(true);
}
identifier++;
}while(identifier != 25);
}
private void update()
{
int identifier = 0;
do
{
taken[identifier] = numbers[identifier].takenStatus();
identifier++;
}while(identifier != 25);
}
}
public void call()
{
int callNum = Greenfoot.getRandomNumber(51);
char callChar[] = {'b','i','n','g','o'};
int randomNum = Greenfoot.getRandomNumber(5);
int identifier = 0;
String totalCall = "" + callChar[randomNum] + callNum;
do
{
callNum = Greenfoot.getRandomNumber(51);
randomNum = Greenfoot.getRandomNumber(5);
identifier = 0;
totalCall = "" + callChar[randomNum] + callNum;
}while(arrayContains(totalCall));
call.setCall(callChar[randomNum],callNum);
do
{
if (totalCall.equals(numbers[identifier].getCall()))
{
numbers[identifier].setClickable(true);
}
identifier++;
}while(identifier != 25);
}

