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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | 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 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 ); } |