Closed adamjw closed 9 years ago
One form of loops in java looks like this: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
Since there are n
lines, you'll need a loop that repeats n
times, spacing each line appropriately.
The Point
class is designed to be immutable. This means that when you create a point
object, there's no way to change its x
or y
values! Methods like addX
or addY
return a new point
object with the altered x
and y
values.
Point translatedPointX = oldPoint.addX(1);
Point translatedPointY = oldPoint.addY(-2);
As well, the above example can be done in one line - you don't have to store the temporary value, just use it directly.
Point translatedPoint = oldPoint.addX(1).addY(-2);
This is an example of method chaining.
A further note on immutable classes - if you press F3 to look at the source code of Point
, you'll see that x
and y
are declared like this:
private final int x, y;
The final
keyword means that once the value has been set, it can never be changed again (it must also be set in the special constructor methods). This enforces the immutable design.
Implement the necessary code to draw the grid to the screen. Should be done in
snake.game.drawer.BoardDrawer
. ImplementdrawBoard
, making use of thewindow
object'sdrawLine
function, keeping in mind the given pointtopLeft
.Acceptance Criteria: