Re: Java Score Not Working
Quote:
it has been going up by 40 each time the bullet hits.
Try debugging your code by adding printlns every where the score is changed. Print out the new value.
The print out should help you figure out what is wrong with your code.
Re: Java Score Not Working
I realized its not exactly 40 each time its like a random number between 10-70. I'm very new to java I'm sorry I'm not even sure how to add printlns, if you could tell me how to do that I would. Sorry for my idiocy once again, and thank for your help sir.
Re: Java Score Not Working
I have found that the statement:
if (bullet_y <= disc_y && bullet_x > disc_x && bullet_x < disc_x + disc_width)
has made the bullet go through it multiple times and the score would therefore increase by more than 1.
Does anyone know how to change this so the score will only increase once when the bullet and disc hit?
Re: Java Score Not Working
Quote:
Does anyone know how to change this so the score will only increase once when the bullet and disc hit?
What are the conditions that controls whether you increase the score? How many times can the bullet continue to hit the target? Is the first time enough?
Then remove/destroy the bullet after its first contact with the target.
Re: Java Score Not Working
I typed:
if (bullet_y <= disc_y && bullet_x > disc_x && bullet_x < disc_x + disc_width) {
bullet = false;
score = score+1;
disc = false;
This made the score go up almost infinitely, and then the cannon stopped shooting the bullets. Am I doing something more wrong?
Re: Java Score Not Working
Quote:
Am I doing something more wrong?
You need to look at the program's logic to see what it is doing.
Remember the computer will do EXACTLY what you tell it to do. So check your code to make sure you are telling it what you want it to do. It is not very good are reading minds, so you must be very specific with your instructions to tell it what to do.
Re: Java Score Not Working
This is the logic I put in, (or at least think i did):
When esc is pressed all the discs become true, and begin going across the screen, some from left to right, others from left to right, this works.
When the bullet hits any disc, the disc disappears. (Works)
When the bullet reached the top of the applet, the bullet = false. (Works)
Now, from what I understand when the bullet hits the disc, the bullet = false, and should go away.
When this happens, I say the score should increase 1.
That is what I think I did.
Re: Java Score Not Working
What makes the score continue to increase after you set bullet = false?
Re: Java Score Not Working
I'm not sure, I set it so when I press esc the bullet=true again, (line 254)
but the bullet does not shoot after the first time the bullet hits the disc.
Could it be that although the bullet and disc does not show up on the screen anymore they are still interacting with each other?
This is the one thing I cannot figure out, I did everything without really running into any issues.
Re: Java Score Not Working
What makes the score continue to increase?
You have an if test to control when the score will increase.
When will that if test not be true?
Re: Java Score Not Working
Hmm...yeah I'm sorry I feel like a complete fool but I'm not quite sure I follow what you're saying, I need to make a test to see when the score won't increase?
Re: Java Score Not Working
Your code has a problem. It continues to increase the value of score.
WHY????
You need to change something so that the program does not execute the: score = score+1; statement.
That statement's execution is controlled by an if statement.
Look at the conditions the if statement tests and see why it becomes true when you do NOT want it to be true.
Re: Java Score Not Working
It is because this statement...
if (bullet_y <= disc3_y && bullet_x > disc3_x && bullet_x < disc3_x + disc3_width) {
happens multiple times, so each time this statement happens the score increases by 1, so is there any way I can change this statement to only occur once?
Re: Java Score Not Working
Add the test of a boolean variable to the if condition.
Set the boolean false when the if statement is true.
Somewhere else you will have to set it true to for that if condition to ever be true again.
Re: Java Score Not Working
First of all I want to thank you for all the time you've spent helping me it means a lot.
Secondly, my java idiocy shines brightly once again, I'm really new and don't quite understand how to do this.
Could you go into a little more detail?
Sorry once again.
Re: Java Score Not Working
Code:
boolean aFlag = true; // define this somewhere
...
if(aFlag && ....) {
aFlag = false; // don't come into this if again until aFlag is set true someplace
...
}
....
aFlag = true; // Now OK for the if to be true
Last post for me tonight.