Computer Science Canada

For loops in applets

Author:  Master [ Sat May 22, 2004 11:01 pm ]
Post subject:  For loops in applets

i have a program - type of asteroids game - in which you can shoot the asteroids. If everytime i press "shoot" i get the number of shots to appear on the screen, but everytime i have to use:

g2.fill(shot[a])

instead i want to use a for loop so i can have it draw the amount that was pressed:

for (int i =0; i >= shotPressedl; i++)
{
g2.fill(shot[i]
}

what i have is:
g2.fill(shot[a])
g2.fill(shot[b])
g2.fill(shot[c])... and for ever

what happens is that my program wont recognize my for loop or it just wont execute for some reason. Is there a restriction that i cannot use loops in a paint method of an applet?

Author:  Dan [ Sat May 22, 2004 11:47 pm ]
Post subject: 

try making i >= shotPressedl in to i <= shotPressedl

since i starts at 0 and gose up not the other way around.

Author:  Master [ Sun May 23, 2004 10:48 pm ]
Post subject: 

Quote:
try making i >= shotPressedl in to i <= shotPressedl


i understand, but this statement is always true and it will never run
i is always less than the number of shots pressed

this is my code which isnt working
code:

for (int i = 0; i >= shotPressed; i++)
{
        g2.fill(fire1[i - 1]);
}

for some reason this for loop doesnt seem to be even executing. Could someone please help me
thanks

Author:  Tony [ Sun May 23, 2004 11:15 pm ]
Post subject: 

Master wrote:

i understand, but this statement is always true and it will never run

*smack*
now that I got your attention... you do realize that the loop is executed while the statement is true, right?

Author:  Master [ Mon May 24, 2004 10:23 pm ]
Post subject: 

for (int i = 0; i >= shotPressed; i++)
{
g2.fill(fire1[i - 1]);
}

even if this loop executes, it will not follow my instructions... it will not fill the object. Do you know what is wrong. IT FEELS LIKE THE LOOP DOESNT EXECUTE EVEN THOUGH IT MAYBE EXECUTING. I want the loop to execute and run properly atleast once, because when i tell it to run, it just wont work.

Author:  Tony [ Mon May 24, 2004 11:33 pm ]
Post subject: 

do you know how to read? Thinking no?
code:

for (int i = 0; i <= shotPressed; i++)
{
g2.fill(fire1[i]);
}


: