adamjw / SnakeWS

0 stars 1 forks source link

2] The grid isn't drawn to the screen #2

Closed adamjw closed 9 years ago

adamjw commented 9 years ago

Implement the necessary code to draw the grid to the screen. Should be done in snake.game.drawer.BoardDrawer. Implement drawBoard, making use of the window object's drawLine function, keeping in mind the given point topLeft.

Acceptance Criteria:

  1. A line is drawn for each row and column
  2. The lines are evenly spaced
  3. The lines are below the header.
adamjw commented 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.

adamjw commented 9 years ago

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.