Hey guys I'm having some issues with this error, any help would be appreciated
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();
}
}for (int i = 0; i < BOARD_SIZE/2; i++)
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();
}
}
}
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();
}
}
}
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
}
}