This site requires JavaScript, please enable it in your browser!
Greenfoot back
kiarocks
kiarocks wrote ...

2011/12/20

Code not compiling?

kiarocks kiarocks

2011/12/20

#
Why will this not compile? I have restarted Greenfoot and double checked everything.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class SoliWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SoliWorld extends World
{
    Card card = new Card();
    Deck deck = new Deck();
    Option option = new Option();
    CardPile crdple = new CardPile();
    StartScreen start = new StartScreen();
    Random rand = new Random();
    TakenCards taken = new TakenCards();
    boolean[][] tcnas = taken.takenCardNumAndSuit;
    int suit = 0;
    int randnum = 0;
    String suitS = "";
    /**
     * Constructor for objects of class SoliWorld.
     * 
     */
    public SoliWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 500, 1); 
        addObject(deck,45,60);
        addObject(start,350,250);
        addCards();
        setPaintOrder(StartScreen.class,Card.class,Deck.class);
    }

    public void addCards()
    {
        for(int i = 1; i != 8; i++)
        {
            addRow(i);
        }

    }

    public void setVars()
    {
        switch(rand.rand(4)+1)
        {
            case 1:suitS = "clubs"; suit = 1; break;
            case 2:suitS = "spades"; suit = 2; break;
            case 3:suitS = "hearts"; suit = 3; break;
            case 4:suitS = "diamonds"; suit = 4; break;
        }
        randnum = rand.rand(13)+1;
    }

    public void addRow(int rownum)
    {
        setVars();
        addObject(new Card(true,randnum,suitS),135+(80*rownum),165+(20*rownum));
        for(int i = 1; i != (7-rownum); i++)
        {
            setVars();
            addObject(new Card(false,randnum,suitS),135+((i+rownum)*80),165);
        }
    }

    public void started()
    {
        removeObject(start);
    }

    public Option getOption()
    {
        return option;
    }
}
AwesomeNameGuy AwesomeNameGuy

2011/12/20

#
whats the error mesage?
kiarocks kiarocks

2011/12/20

#
None, it just wont show up. The buttons are also grayed out, except for the "Compile" button.
danpost danpost

2011/12/20

#
Updated: later in the code you have another '!=' (somewhere around line 60, I think). Your range of rownum is 1 to 7 and 7 - 7 = 0. You probably need 8 - rownum, instead.
AwesomeNameGuy AwesomeNameGuy

2011/12/20

#
I don't know I'm afraid.
kiarocks kiarocks

2011/12/20

#
Whoops! thanks for that, i think it will work.
kiarocks kiarocks

2011/12/20

#
Still no. Uploaded if you want a look, under the name solitaire.
danpost danpost

2011/12/20

#
The loop at line 37 in the method addCards is sending the method addrow numbers ranging from 1 through 7. The method addrow uses '7 - rownum' as the cutoff for 'i' starting at 1 (rownum is the number sent to it via addCards). When 7 is sent to addrow by addCards, the cutoff becomes zero, which is already less than 1 (what 'i' starts at). Processing never leaves this loop because i will never be EQUAL TO zero. The two ways to correct this dilema are (1) use '<', instead of '!=', and (2) ensure that the cutoff is never below the start value (in this case, changing '7 - rownum' to '8 - rownum')
kiarocks kiarocks

2011/12/20

#
I did that, got a weird NullPointer, and then it worked. It runs now, i don't know what happened.
danpost danpost

2011/12/20

#
You should set up all your cards initially, and them choose them randomly. You are getting duplicate cards the way it is.
kiarocks kiarocks

2011/12/20

#
Oh, I got that cleared up. I'll update tomorrow.
kiarocks kiarocks

2011/12/20

#
New problem: an unreachable statement that shouldn't be possible.
/**
     * Constructor for objects of class SoliWorld.
     * 
     */
    public SoliWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 500, 1); 
        addObject(deck,45,60);
        addObject(start,350,250);
        for(int i = 0; 1 != 4; i++)
        {
            addObject(new CardPile(),375+(80*i),60);
        }
        addCards(); //this line!!!!! How is this unreachable?
        setPaintOrder(StartScreen.class,Card.class,Deck.class,CardPile.class);
    }
kiarocks kiarocks

2011/12/20

#
If you move addCards(); above the for loop the error moves to the setPaint(); line.
davmac davmac

2011/12/20

#
line 11: for(int i = 0; 1 != 4; i++) 1 is never equal to 4, so the loop is infinite. You meant "i != 4".
kiarocks kiarocks

2011/12/20

#
*Facepalm* Thank you!
You need to login to post a reply.