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

2011/6/11

Percents in game

1
2
danpost danpost

2011/6/11

#
Use of brackets: to group statements together so the compiler knows where a procedure ends. 1) a method or constructor (the code for these should be within a set of brackets) 2) an if or else (the code that should be executed when if statement is true should be bracketed; the code that should be executed when if statement is false (for else part) should be bracketed). 3) a switch (the code within a switch statement should be bracketed). 4) a for loop (the code that should be looped through should be bracketed). Those listed above are the main ones. Also everything within the class (after the class indentifier) should be.
danpost danpost

2011/6/11

#
Do you have code elsewhere that calls this method. Something like:
    if(infect())
    {
        ...
    }
kiarocks kiarocks

2011/6/11

#
no
danpost danpost

2011/6/11

#
You must have something calling this method or execution will never get there. You gave the method a type 'boolean', meaning when called upon will return a true/false value. It needs to be called from another method, possibly 'public void act()'. The 'if' statement above might be sufficient, depending on what you do with the information. Add the code for what needs done where the '...' is when 'infect()' returns true.
kiarocks kiarocks

2011/6/11

#
public void getinfected();
    if(infect())<error illegal start
what goes after this? how to fix error?
danpost danpost

2011/6/11

#
Again BRACKETS. All the code for 'public void getinfected()' needs to be bracketed -- one after the method declaration and one at the end of the code for the method. Also, the semi-colon ';' is only used at the end of executable statements -- not at the end of general declaration statements.
kiarocks kiarocks

2011/6/11

#
I would use a switch, would that work?
danpost danpost

2011/6/11

#
A switch statement is good only if you needed to do several different things depending on the value of a variable. I am not at this point going into that -- and I do not think you are on the right path. Your code (as I see it) should look like this:
public void getinfected()
{
    if(infect())
    {
        // what you do when infect() return true
    }
}
Again, this method must be called from somewhere else using the (executable) statement:
getinfected();
kiarocks kiarocks

2011/6/11

#
WORKS!Thank you you might want to check it out later-its called infect
kiarocks kiarocks

2011/6/11

#
how would you add a timer to change image also?
danpost danpost

2011/6/11

#
Use the act cycle as the timer. Just need a counter that increments each time act is run.
kiarocks kiarocks

2011/6/11

#
no, i mean to have the infected change to a higher level each, say, 20 seconds? and how do you like the game?
danpost danpost

2011/6/12

#
I would not call it a game. The 'simulation' is good. You might try making the grid finer (i.e. instead of 15 x 15 or 15 x 30 at 20 pixels, maybe try 45 x 45 or 45 x 60 at 5 pixels. Then, increase the speed a bit. This will give more of a smooth movement. Also, make sure you adjust getObjectsInRange to a higher radius and increase the range of your random numbers.
davmac davmac

2011/6/12

#
D'oh... you'd think after all these years of Java programming I'd know how to write a method signature by now. As pointed out by danpost, you need the "()" as well: public boolean infect() { .... }
You need to login to post a reply.
1
2