Hey guys I'm having some issues with this error, any help would be appreciated


1 2 3 4 5 6 7 8 9 10 11 12 | public void fillArray() { for ( int i ; i < BOARD_SIZE/ 2 ; i++) { Card randomCard = deck.deal(); Card cardCopy = new Card(randomCard.getCardImage()); board[getRandomPosition()] = randomCard; board[getRandomPosition()] = cardCopy; //System.out.println(); } } |
1 | for ( int i = 0 ; i < BOARD_SIZE/ 2 ; i++) |
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) import greenfoot.Color; /** * Object: Player is to turn over two cards at a time tring to obtain a match. * In the case of a match, the cards remain face-up. If no match, the cards are turned * back over. Game continues until all cards are turned face-up. */ public class Level extends World { private GreenfootImage bg; // background image private Card[] board; // holds cards for game private Deck deck; // the deck from which the cards are dealt. private int numOver; // total number of cards face-up. private int numShowing; // number of cards showing for the current play private Card[] cardsShowing; // holds the cards showing for the current play private Label label1; private static final int BOARD_SIZE = 16 ; //Number of cards on the Memory Board private static final Color bgColor = Color.LIGHT_GRAY; //Board color /** * Constructor for objects of class MemoryWorld. */ public Level() { // Create a new world with 1000 x 600 cells with a cell size of 1x1 pixels. super ( 1000 , 600 , 1 ); setBackground( new GreenfootImage( "Background.jpg" )); //fills background of board bg = getBackground(); bg.setColor(bgColor); bg.fill(); //keeps track of cards on board board = new Card[BOARD_SIZE]; //keeps track of Cards for current play cardsShowing = new Card[ 2 ]; numOver = 0 ; // total number of cards face-up. numShowing = 0 ; // number of cards showing for the current play deck = new Deck(); fillArray(); setup(); } /** * Gets BOARD_SIZE/2 cards from the Deck. Creates a copy of each of these cards. Randomly * places these cards in the board array created for this purpose. */ public void fillArray() { for ( int i = 0 ; i < BOARD_SIZE/ 2 ; i++) { Card randomCard = deck.deal(); Card cardCopy = new Card(randomCard.getCardImage()); board[getRandomPosition()] = randomCard; board[getRandomPosition()] = cardCopy; //System.out.println(); } } /** * Sets the visual board. */ public void setup() { final int SQUARE_SIZE = 3 ; //number of rows and columns int x = 80 ; int y = 80 ; int index = 0 ; for ( int row = 0 ; row < SQUARE_SIZE;row++) { x = 80 ; for ( int col = 0 ; col < SQUARE_SIZE; col++) { board[index].turnOver(); //comment if you want cards to be face-up //board[index].showFace(); //uncomment if you want cards to show addObject(board[index], x, y); index++; x += 80 ; } y += 110 ; } addObject(label1, 120 , 470 ); } /** * Chooses a random empty position in the board array.. * @return a random empty position in the board array. */ public int getRandomPosition() { int randPlace = Greenfoot.getRandomNumber(BOARD_SIZE); while (board[randPlace] != null ) { randPlace = Greenfoot.getRandomNumber(BOARD_SIZE); } //System.out.print(randPlace + " "); return randPlace; } /** * Places this card in the array the holds the cards of the current play (max of 2) * Increments the current number of cards showing. * @param c the Card object currently face-up on this turn. */ public void recordCardShowing(Card c) { cardsShowing[numShowing] = c; numShowing++; } /** * Checks to see is the cards in the cardsShowing array (cards showing on current play) * have the same image. * @return true if cards in cardsShowing array have the same image, false otherwise. */ public boolean checkMatch() { return cardsShowing[ 0 ].getCardImage().equals(cardsShowing[ 1 ].getCardImage()); } /** * The game. * Check if there are two cards currently showing. If so, check to see if they match. * If so, flash screen red, increment total number of cards showing by 2. If the cards * do not match, turn the cards over. * In either case, the array elements of cardsShowing are set to null and * number of cards currently showing is set to 0. * * Check for a win (are all cards face-up? If so, game is over. */ public void act() { if (numShowing == 2 ) { Greenfoot.delay( 50 ); if (checkMatch()) { bg.setColor(Color.RED); bg.fill(); Greenfoot.playSound( "cowbell.wav" ); Greenfoot.delay( 10 ); bg.setColor(bgColor); bg.fill(); numOver += 2 ; } else { Greenfoot.playSound ( "no.wav" ); cardsShowing[ 0 ].turnOver(); cardsShowing[ 1 ].turnOver(); } cardsShowing[ 0 ]= null ; cardsShowing[ 1 ]= null ;; numShowing = 0 ; } //check win if (numOver == BOARD_SIZE) { //System.out.println("WIN"); Greenfoot.playSound( "tada.wav" ); bg.setColor(Color.RED); bg.fill(); Greenfoot.stop(); } } } |
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import greenfoot.Color; /** * Object: Player is to turn over two cards at a time tring to obtain a match. * In the case of a match, the cards remain face-up. If no match, the cards are turned * back over. Game continues until all cards are turned face-up. */ public class Level extends World { private GreenfootImage bg; // background image private Card[] board; // holds cards for game private Deck deck; // the deck from which the cards are dealt. private int numOver; // total number of cards face-up. private int numShowing; // number of cards showing for the current play private Card[] cardsShowing; // holds the cards showing for the current play private Label label1; private static final int BOARD_SIZE = 16 ; //Number of cards on the Memory Board private static final Color bgColor = Color.LIGHT_GRAY; //Board color /** * Constructor for objects of class MemoryWorld. */ public Level() { // Create a new world with 1000 x 600 cells with a cell size of 1x1 pixels. super ( 1000 , 600 , 1 ); setBackground( new GreenfootImage( "Background.jpg" )); //fills background of board bg = getBackground(); bg.setColor(bgColor); bg.fill(); //keeps track of cards on board board = new Card[BOARD_SIZE]; //keeps track of Cards for current play cardsShowing = new Card[ 2 ]; numOver = 0 ; // total number of cards face-up. numShowing = 0 ; // number of cards showing for the current play deck = new Deck(); fillArray(); setup(); } /** * Gets BOARD_SIZE/2 cards from the Deck. Creates a copy of each of these cards. Randomly * places these cards in the board array created for this purpose. */ public void fillArray() { for ( int i = 0 ; i < BOARD_SIZE/ 2 ; i++) { Card randomCard = deck.deal(); Card cardCopy = new Card(randomCard.getCardImage()); board[getRandomPosition()] = randomCard; board[getRandomPosition()] = cardCopy; //System.out.println(); } } /** * Sets the visual board. */ public void setup() { final int SQUARE_SIZE = 4 ; //number of rows and columns int x = 80 ; int y = 80 ; int index = 0 ; for ( int row = 0 ; row < SQUARE_SIZE;row++) { x = 80 ; for ( int col = 0 ; col < SQUARE_SIZE; col++) { board[index].turnOver(); //comment if you want cards to be face-up //board[index].showFace(); //uncomment if you want cards to show addObject(board[index], x, y); index++; x += 80 ; } y += 110 ; } } /** * Chooses a random empty position in the board array.. * @return a random empty position in the board array. */ public int getRandomPosition() { int randPlace = Greenfoot.getRandomNumber(BOARD_SIZE); while (board[randPlace] != null ) { randPlace = Greenfoot.getRandomNumber(BOARD_SIZE); } //System.out.print(randPlace + " "); return randPlace; } /** * Places this card in the array the holds the cards of the current play (max of 2) * Increments the current number of cards showing. * @param c the Card object currently face-up on this turn. */ public void recordCardShowing(Card c) { cardsShowing[numShowing] = c; numShowing++; } /** * Checks to see is the cards in the cardsShowing array (cards showing on current play) * have the same image. * @return true if cards in cardsShowing array have the same image, false otherwise. */ public boolean checkMatch() { return cardsShowing[ 0 ].getCardImage().equals(cardsShowing[ 1 ].getCardImage()); } /** * The game. * Check if there are two cards currently showing. If so, check to see if they match. * If so, flash screen red, increment total number of cards showing by 2. If the cards * do not match, turn the cards over. * In either case, the array elements of cardsShowing are set to null and * number of cards currently showing is set to 0. * * Check for a win (are all cards face-up? If so, game is over. */ public void act() { if (numShowing == 2 ) { Greenfoot.delay( 50 ); if (checkMatch()) { bg.setColor(Color.RED); bg.fill(); Greenfoot.playSound( "cowbell.wav" ); Greenfoot.delay( 10 ); bg.setColor(bgColor); bg.fill(); numOver += 2 ; } else { Greenfoot.playSound ( "no.wav" ); cardsShowing[ 0 ].turnOver(); cardsShowing[ 1 ].turnOver(); } cardsShowing[ 0 ]= null ; cardsShowing[ 1 ]= null ;; numShowing = 0 ; } //check win if (numOver == BOARD_SIZE) { //System.out.println("WIN"); Greenfoot.playSound( "tada.wav" ); bg.setColor(Color.RED); bg.fill(); Greenfoot.stop(); } } } |
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList; public class Deck extends Actor { // Strings used to form filenames for the card images. private static final String[] DENOMINATIONS = { "1" , "2" , "3" , "4" , "5" , "0" }; private static final String[] SUITS = { "Card" }; private List<Card> cards; // holds playing cards /** * Default constructor initializes and fills the list of Card objects. */ public Deck() { cards = new ArrayList<Card>(); for ( int d = 0 ; d < DENOMINATIONS.length; d++) { for ( int s = 0 ; s < SUITS.length; s++) { String cardImage = DENOMINATIONS[d] + SUITS[s] + ".jpg" ; Card c = new Card(cardImage); cards.add(c); } } } /** * Chooses and returns a random ccard object fr.om this deck. * The card is removed from the deck. * @return a random Card object */ public Card deal() { int randCard = Greenfoot.getRandomNumber(cards.size()); Card c = cards.remove(randCard); //System.out.print(c.getCardImage()); return c; } /** * No action */ public void act() { //do nothing } } |