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

2017/6/13

Title/Start screen

1
2
3
SchoolStuff SchoolStuff

2017/6/16

#
And it also happens in the third world..
SchoolStuff SchoolStuff

2017/6/16

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void act()
    {
        this.setLocation (getX(), getY() +1);
        if (getY()>getWorld().getHeight()+10)
        {
            this.getWorld().removeObject(this);
        }
        
        if (Greenfoot.mouseClicked(this))
        {
            ((Counter_w1)getWorld().getObjects(Counter_w1.class).get(0)).addScore();
            Greenfoot.playSound(soundfile);
            turnWhite();
        }
    }
I see that it is talking about 1 counter, but we used three counters. I also put this code in the act method of the block.
Yehuda Yehuda

2017/6/16

#
If you know how to copy code then you can know how to copy the terminal window output. Highlight the text then press either Ctrl+C to copy or go to the Options menu and choose Copy.
Super_Hippo Super_Hippo

2017/6/16

#
You don't need to have different score classes. Just add more instances of the counter class and give them different text, so change the String variable which I passed in the parameter. Why do you have three worlds, what are they doing?
SchoolStuff SchoolStuff

2017/6/17

#
The three worlds are three different levels. We actually wanted to make the game faster after every 20 points, but that was too difficult. Every score counter is for one of the worlds(level), so after every 20 points you go to another world which is actually another level, we couldn't find any information on this concept and we didn't practice this in class, that is the reason why I ask so much. I really don't understand anything of this. This is the terminal window I get:
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
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:48)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:48)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:48)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:48)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:48)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:48)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:44)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:44)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:44)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:44)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:45)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:45)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:45)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:45)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:44)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at Block.act(Block.java:44)
    at greenfoot.core.Simulation.actActor(Simulation.java:594)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
    at greenfoot.core.Simulation.runContent(Simulation.java:215)
    at greenfoot.core.Simulation.run(Simulation.java:205)
danpost danpost

2017/6/17

#
The message is telling you that the problem is in the act method of the Block class -- line 48 at the time the last terminal error printed, as per this line:
1
at Block.act(Block.java:48)
line 4 above. It basically says that you tried to get access to an element of the ArrayList while it was empty:
1
IndexOutOfBoundsException: Index: 0, Size: 0
You tried to access the first element (index of '0') when the size of the array is zero. You might try asking if the ArrayList object is not empty before trying to access an element of it.
SchoolStuff SchoolStuff

2017/6/17

#
Thank you, it started working. How do I make the game over if the blocks are out the screen and if you click on the background, I know someone commented it, but it is not working. I haven't put it in the code yet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void act()
    {
        this.setLocation (getX(), getY() +1);
        if (getY()>getWorld().getHeight()+10)
        {
            this.getWorld().removeObject(this);
        }
        
        if (Greenfoot.mouseClicked(this))
        {
            ((Counter_w1)getWorld().getObjects(Counter_w1.class).get(0)).addScore();
            Greenfoot.playSound(soundfile);
            turnWhite();
        }
    }
I think it should be put in this code, but I don't how to refer to it (the background thing). And I think I should make another code for the game over like:
1
2
3
4
public void gameOver()
{
    //something which should happen when the game is lost
}
but what do I put in between brackets. I hope that I'm clear. So that the game is over if the blocks are not in the window anymore and if you click on the background.
danpost danpost

2017/6/17

#
SchoolStuff wrote...
How do I make the game over if the blocks are out the screen and if you click on the background,
That information was already provided here within this discussion thread. What goes in the brackets would usually be code to display some message ("You Win" or "You Lose", for example) and stop the scenario.
Yehuda Yehuda

2017/6/18

#
danpost wrote...
The message is telling you that the problem is in the act method of the Block class -- line 48 at the time the last terminal error printed, as per this line:
1
at Block.act(Block.java:48)
line 4 above.
The way the terminal works by me is the newest output gets added to the bottom, it doesn't push all the old stuff down and go to the top.
You need to login to post a reply.
1
2
3