diff options
Diffstat (limited to 'src/se')
| -rw-r--r-- | src/se/liu/gusso230/calendar/Cal.java | 6 | ||||
| -rw-r--r-- | src/se/liu/gusso230/calendar/Month.java | 11 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/Board.java | 3 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/BoardTester.java | 4 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/BoardToTextConverter.java | 8 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/Point.java | 6 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/Poly.java | 10 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/TetrominoMaker.java | 10 |
8 files changed, 46 insertions, 12 deletions
diff --git a/src/se/liu/gusso230/calendar/Cal.java b/src/se/liu/gusso230/calendar/Cal.java index 3f0856e..9de6008 100644 --- a/src/se/liu/gusso230/calendar/Cal.java +++ b/src/se/liu/gusso230/calendar/Cal.java @@ -20,12 +20,18 @@ public class Cal { this.appointments = new ArrayList<>(); } + /** + * Prints all booked appointments to stdout. + */ public void show() { for (Appointment appointment : appointments) { System.out.println(appointment); } } + /** + * Books an appointment. + */ public void book(int year, String monthString, int day, int startHour, int startMinute, int endHour, int endMinute, String subject) { if (year <= 1970) { diff --git a/src/se/liu/gusso230/calendar/Month.java b/src/se/liu/gusso230/calendar/Month.java index a0224c1..c793e92 100644 --- a/src/se/liu/gusso230/calendar/Month.java +++ b/src/se/liu/gusso230/calendar/Month.java @@ -23,6 +23,11 @@ public class Month { return days; } + /** + * Returns the number of the month with a specific name. + * @param name the name of the month + * @return the index, starting at 1. -1 if the name is unknown + */ static int getMonthNumber(String name) { switch (name) { case "January": @@ -53,6 +58,12 @@ public class Month { return -1; } } + + /** + * Returns the amount of days in the month with a specific name. + * @param name the name of the month + * @return the amount of days. -1 if the name is unknown + */ static int getMonthDays(String name) { switch (name) { case "January": diff --git a/src/se/liu/gusso230/tetris/Board.java b/src/se/liu/gusso230/tetris/Board.java index 759df90..947877a 100644 --- a/src/se/liu/gusso230/tetris/Board.java +++ b/src/se/liu/gusso230/tetris/Board.java @@ -68,6 +68,9 @@ public class Board { this.fallingY = fallingY; } + /** + * Randomize all squares inside this board. + */ public void randomize() { SquareType[] values = SquareType.values(); int numValues = values.length; diff --git a/src/se/liu/gusso230/tetris/BoardTester.java b/src/se/liu/gusso230/tetris/BoardTester.java index 32c558f..487107a 100644 --- a/src/se/liu/gusso230/tetris/BoardTester.java +++ b/src/se/liu/gusso230/tetris/BoardTester.java @@ -4,6 +4,8 @@ public class BoardTester { public static void main(String[] args) { Board board = new Board(5, 5); + board.randomize(); + board.setFalling(new TetrominoMaker().getPoly(0)); board.setFallingX(0); board.setFallingY(0); @@ -11,8 +13,10 @@ public class BoardTester { BoardToTextConverter converter = new BoardToTextConverter(); System.out.println(converter.toText(board)); + System.out.println("-".repeat(board.getWidth())); board.getFalling().rotateCW(); System.out.println(converter.toText(board)); + System.out.println("-".repeat(board.getWidth())); TetrisViewer viewer = new TetrisViewer(board); viewer.show(); diff --git a/src/se/liu/gusso230/tetris/BoardToTextConverter.java b/src/se/liu/gusso230/tetris/BoardToTextConverter.java index 8096dd7..ab8914c 100644 --- a/src/se/liu/gusso230/tetris/BoardToTextConverter.java +++ b/src/se/liu/gusso230/tetris/BoardToTextConverter.java @@ -23,6 +23,10 @@ public class BoardToTextConverter { return ' '; } + /** + * Converts a board to a text representation. + * @param board the board to convert. + */ public String toText(Board board) { StringBuilder s = new StringBuilder(); for (int y = 0; y < board.getHeight(); y++) { @@ -31,10 +35,6 @@ public class BoardToTextConverter { } s.append('\n'); } - for (int i = 0; i < board.getWidth(); i++) { - s.append('-'); - } - s.append('\n'); return s.toString(); } } diff --git a/src/se/liu/gusso230/tetris/Point.java b/src/se/liu/gusso230/tetris/Point.java index 32e92ab..2b6e3a7 100644 --- a/src/se/liu/gusso230/tetris/Point.java +++ b/src/se/liu/gusso230/tetris/Point.java @@ -17,9 +17,13 @@ public class Point { return y; } + /** + * Rotates this point one step clockwise. + * @param boundingBoxSize the size of the bounding box this point should be rotated with respect to. + */ public void rotateCW(int boundingBoxSize) { int prevX = x; x = boundingBoxSize - y; - y = prevX; + y = prevX; // IntelliJ marks this as suspiscious but I assure you, it is intended. } } diff --git a/src/se/liu/gusso230/tetris/Poly.java b/src/se/liu/gusso230/tetris/Poly.java index 01fed45..4de957c 100644 --- a/src/se/liu/gusso230/tetris/Poly.java +++ b/src/se/liu/gusso230/tetris/Poly.java @@ -21,6 +21,13 @@ public class Poly { return squareType; } + /** + * Returns wether this poly covers a position (x, y) if the top left corner of the poly is at (posX, posY). + * @param x The x position of the coordinate to test. + * @param y The y position of the coordinate to test. + * @param posX The x position of the top left corner of the poly's bounding box. + * @param posY The y position of the top left corner of the poly's bounding box. + */ public boolean covers(int x, int y, int posX, int posY) { for (Point point : points) { if (posX + point.getX() == x && posY + point.getY() == y) { @@ -30,6 +37,9 @@ public class Poly { return false; } + /** + * Rotates all the poly's points one step clockwise. + */ public void rotateCW() { for (Point point : points) { point.rotateCW(boundingBoxSize); diff --git a/src/se/liu/gusso230/tetris/TetrominoMaker.java b/src/se/liu/gusso230/tetris/TetrominoMaker.java index c9c8704..b24c00e 100644 --- a/src/se/liu/gusso230/tetris/TetrominoMaker.java +++ b/src/se/liu/gusso230/tetris/TetrominoMaker.java @@ -9,7 +9,6 @@ public class TetrominoMaker { public TetrominoMaker() { polys = new ArrayList<>(); - // I polys.add(new Poly(SquareType.I, new Point[] { new Point(0, 1), new Point(1, 1), @@ -17,7 +16,6 @@ public class TetrominoMaker { new Point(3, 1), })); - // J polys.add(new Poly(SquareType.J, new Point[] { new Point(0, 0), new Point(0, 1), @@ -25,7 +23,6 @@ public class TetrominoMaker { new Point(2, 1), })); - // L polys.add(new Poly(SquareType.L, new Point[] { new Point(0, 1), new Point(1, 1), @@ -33,7 +30,6 @@ public class TetrominoMaker { new Point(2, 0), })); - // O polys.add(new Poly(SquareType.O, new Point[] { new Point(0, 0), new Point(0, 1), @@ -41,7 +37,6 @@ public class TetrominoMaker { new Point(1, 1), })); - // S polys.add(new Poly(SquareType.S, new Point[] { new Point(0, 0), new Point(0, 1), @@ -49,7 +44,6 @@ public class TetrominoMaker { new Point(1, 1), })); - // T polys.add(new Poly(SquareType.T, new Point[] { new Point(0, 1), new Point(1, 1), @@ -57,7 +51,6 @@ public class TetrominoMaker { new Point(1, 0), })); - // Z polys.add(new Poly(SquareType.Z, new Point[] { new Point(0, 0), new Point(1, 0), @@ -71,6 +64,9 @@ public class TetrominoMaker { } public Poly getPoly(int n) { + if (n >= getNumberOfTypes()) { + throw new IllegalArgumentException("Index out of bounds - the wanted poly does not exist"); + } return polys.get(n); } } |
