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

2017/1/2

User Input - Storage

2
3
4
5
6
7
danpost danpost

2017/1/4

#
The textbox class was complete. It should not be taken away from or added to. If I am not mistaken as to which code you are referring, it should be in your Chest class.
danpost danpost

2017/1/4

#
JulianYoung wrote...
I tried adding it in. But im not sure i put it in the right place. the minute i press start it instantly collects 100 coins and wins the game code below.
if (visited >= 0 && isTouching(Player.class)) visited = -(++visited);{
    Money_Counter.money=Money_Counter.money+10;
}
The open squiggly bracket needs to be immediately after the 'if' condition:
if (visited >= 0 && isTouching(Player.class))
{
    visited = -(++visited);
    Money_Counter.money=Money_Counter.money+10;
}
JulianYoung JulianYoung

2017/1/4

#
okay thanks for that. I still not sure i am putting the other code for not creating the error message in the right place or implementing it correctly this is the chest section.
import greenfoot.*;

/**
 * Write a description of class Chest here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class Chest extends Actor
{
    private int visited;
    /**
     * Act - do whatever the Chest wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {

        GreenfootImage image = getImage();  
        image.scale(35, 35);       
        setImage(image);
        if (visited >= 0 && isTouching(Player.class))
        {
            visited = -(++visited);
            Money_Counter.money=Money_Counter.money+10;
        }

        if (visited < 0 && ! isTouching(Player.class)) visited = -visited;
        if (visited == 3){
            getWorld().removeObject(this);
            Bandit_counter.Bandit++;
            Chest_counter.chest--;

        }
    }
}    

danpost danpost

2017/1/4

#
I though you made the image in the file itself the appropriate size. I wonder why you still have lines 20 through 22 in the code. I do not see any reason to get an error message with this code. Please provide the entire error output for review.
JulianYoung JulianYoung

2017/1/4

#
Another small problem sometimes more then 5 bandits form in my program even though they shouldn't. Also they can still spawn on top of chests. i have attached photo of this and my game code. code
import greenfoot.*;

/**
 * Write a description of class Game here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Game extends World
{
    public Move_Sideways horizontalRangeBox, verticalRangeBox;

    public static Actor chest;
    /**
     * Constructor for objects of class Game.
     * 
     */
    public Game()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(500, 500, 1); 
        Player player = new Player();
        addObject(player, 125,125 );

        Chest_counter ccounter = new Chest_counter();
        addObject(ccounter, 45,150 );

        Money_Counter MOcounter = new Money_Counter();
        addObject(MOcounter, 45,250 );

        Move_Counter Mcounter = new Move_Counter();
        addObject(Mcounter, 45,300 );        

        Bandit_counter bcounter = new Bandit_counter();

        Up_Down up = new Up_Down();
        addObject(up, 133,25 );
        Sideways side = new Sideways();
        addObject(side, 133,75 );

        addObject(bcounter, 45,200 );

        Run_Button rbutton = new Run_Button();
        addObject(rbutton, 375,50 );

        Run run = new Run();
        addObject(run, 450,50 );

        for(int b =1; b<11;b++){
            int g = Greenfoot.getRandomNumber(8);
            int c = Greenfoot.getRandomNumber(8);
            g=(g+1)*50+75;
            c=(c+1)*50+75;
            // starting place for player is 125,125
            if(g==125&&c==125){
                g=g+50;
                c=c+50;

            } if (getObjectsAt(g, c, Chest.class).isEmpty())
            {
                Chest chest = new Chest();
                addObject(chest, g, c);
            }
            else b--;                                                           
        }
        for( int d =1; d<6;d++){
            int e= Greenfoot.getRandomNumber(8);
            int f = Greenfoot.getRandomNumber(8);
            e=(e+1)*50+75;
            f=(f+1)*50+75;
            if(e==125&&f==125){
                e=e+50;
                f=f+50;

            }
            if (getObjectsAt(e, f, Bandit.class).isEmpty())
            {
                Bandit bandit = new Bandit();
                addObject(bandit, e, f);
            }
            else d--;    
            if (getObjectsAt(e, f, Chest.class).isEmpty())
            {
                Bandit bandit = new Bandit();
                addObject(bandit, e, f);
            }
            else d--;    
        }


        horizontalRangeBox = new Move_Sideways();
        addObject(horizontalRangeBox,250,75);
        verticalRangeBox = new Move_Sideways();

        addObject(verticalRangeBox,250,25);

    }}
JulianYoung JulianYoung

2017/1/4

#
danpost wrote...
I though you made the image in the file itself the appropriate size. I wonder why you still have lines 20 through 22 in the code. I do not see any reason to get an error message with this code. Please provide the entire error output for review.
oops need to get rid of that
JulianYoung JulianYoung

2017/1/4

#
I do not see any reason to get an error message with this code. Please provide the entire error output for review. not getting error any more thanks.
JulianYoung JulianYoung

2017/1/4

#
image for problem is here!
danpost danpost

2017/1/4

#
JulianYoung wrote...
sometimes more then 5 bandits form in my program even though they shouldn't. Also they can still spawn on top of chests
Remove lines 82 through 87 and on line 76, change 'Bandit.class' to 'null'. That should fix both issues.
JulianYoung JulianYoung

2017/1/4

#
can you get it to show you the lines on greenfoot or not? just so in future it could be easier.
JulianYoung JulianYoung

2017/1/4

#
Thanks that is working. In the end the chest and bandit characters will have to be invisible would i have to change their image and set transparency to 0 and if so how would i implement this. Thank You for all you help so far. without it my program would be terrible!
JulianYoung JulianYoung

2017/1/4

#
Another question once a chest has been visited three times it should turn into a bandit and the bandit counter should go up and chest counter go down. I have the code below but im not sure how to make the bandit. would i have to use getx and gety and create bandit on that position. This could also only happen after the player has moved on.
 if (visited < 0 && ! isTouching(Player.class)) visited = -visited;
        if (visited == 3){
            getWorld().removeObject(this);
            Bandit_counter.Bandit++;
            Chest_counter.chest--;
         
        }
danpost danpost

2017/1/4

#
JulianYoung wrote...
once a chest has been visited three times it should turn into a bandit and the bandit counter should go up and chest counter go down. I have the code below but im not sure how to make the bandit. would i have to use getx and gety and create bandit on that position. This could also only happen after the player has moved on. < Code Omitted >
The code you gave here (lines 3 through 5) is indeed the code that executes when the player has just moved on. You can add the bandit BEFORE you remove the chest using:
getWorld().addObject(new Bandit(), getX(), getY());
JulianYoung wrote...
can you get it to show you the lines on greenfoot or not? just so in future it could be easier.
I am not sure what you mean. Be more specific. What lines? where in greenfoot? make what easier?
JulianYoung JulianYoung

2017/1/4

#
JulianYoung wrote...
can you get it to show you the lines on greenfoot or not? just so in future it could be easier.
I am not sure what you mean. Be more specific. What lines? where in greenfoot? make what easier? when you click the add code button on the post a reply and post you get a white box with the code in and the line numbers to the side. Is there a way to turn the line numbers on in greenfoot. i am finished for today but will probably be back tomorrow. thank you for all you help.
danpost danpost

2017/1/4

#
JulianYoung wrote...
Is there a way to turn the line numbers on in greenfoot.
I presume it has not changed. In my version, I can use the menubar -- 'Edit>Preferences...' and go to the 'Editor' tab for the line numbering checkbox option.
There are more replies on the next page.
2
3
4
5
6
7