You need to learn how to define a class and use it. That will make it easier to have more than one brick and to have the bricks be at unique locations.
Classes (The Java™ Tutorials > Learning the...
Type: Posts; User: Norm
You need to learn how to define a class and use it. That will make it easier to have more than one brick and to have the bricks be at unique locations.
Classes (The Java™ Tutorials > Learning the...
Where is the class definition for the brick?
Can you post the code you have now?
The normal way is to make a class that represents the brick. The class contains all the info about the brick and has methods for accessing and changing that info.
What happens when the if is executed and beenHit is false?
What happens when the if is executed and beenHit is true?
Setting beenHit true when it's true seems redundant.
What do you mean by "link a boolean and method together"?
boolean is a data type. You can define variables of type boolean.
A boolean variable can be used as the condition of an if statement....
Yes, all methods and constructors are defined at the class level.
No. Those two variables only exist when the methods are executed. You need to define a variable at the class level. For example the variable: paper is at the class level.
You also need to remove...
You need to consider how local variables (defined in a method) and variables defined at the class level remember their values. Local variables only hold values when the method is executing. When...
Where are the variables defined that hold the state of a brick? For example its x,y location?
Add another boolean variable to the group of variables: beenHit and set it initially false.
When a...
One problem I see in the code is too many hardcoded values. Most of the numbers should be in variables that describe their usage which will make the program more maintainable and easier to read and...
Can you explain what happens when you execute the program and what the problem is?
When I execute it,I get a fast moving round white shape and a rectangle. Changing how the round shape moves using...
In the object for a brick add a boolean: beenHit that is initially false. Set it true when the brick is hit.
Use its value to control when to add: add if false, do not add if true.
An idea: Have a flag for the brick that records if it has been been hit. If the flag is set, don't add.