From 4931a0a10b175766a6f27f8041009576edb42b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 27 Jan 2021 20:39:13 +0100 Subject: redovisning --- .idea/.gitignore | 8 - .idea/.name | 1 - .idea/codeStyles/Project.xml | 261 -- .idea/codeStyles/codeStyleConfig.xml | 5 - .idea/description.html | 1 - .idea/encodings.xml | 6 - .idea/inspectionProfiles/JavaOO_2021.xml | 3997 ------------------- .idea/inspectionProfiles/Project_Default.xml | 4008 -------------------- .idea/inspectionProfiles/profiles_settings.xml | 6 - .idea/libraries/commons_cli_1_4.xml | 13 - .idea/libraries/gson.xml | 11 - .idea/libraries/miglayout_swing.xml | 13 - .idea/libraries/tddd78_annotations.xml | 9 - .idea/misc.xml | 12 - .idea/modules.xml | 8 - .idea/project-template.xml | 3 - .idea/vcs.xml | 6 - JavaOO.iml | 16 - src/se/liu/gusso230/calendar/Cal.java | 6 + src/se/liu/gusso230/calendar/Month.java | 11 + src/se/liu/gusso230/tetris/Board.java | 3 + src/se/liu/gusso230/tetris/BoardTester.java | 4 + .../liu/gusso230/tetris/BoardToTextConverter.java | 8 +- src/se/liu/gusso230/tetris/Point.java | 6 +- src/se/liu/gusso230/tetris/Poly.java | 10 + src/se/liu/gusso230/tetris/TetrominoMaker.java | 10 +- 26 files changed, 46 insertions(+), 8396 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.name delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/description.html delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/inspectionProfiles/JavaOO_2021.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/libraries/commons_cli_1_4.xml delete mode 100644 .idea/libraries/gson.xml delete mode 100644 .idea/libraries/miglayout_swing.xml delete mode 100644 .idea/libraries/tddd78_annotations.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/project-template.xml delete mode 100644 .idea/vcs.xml delete mode 100644 JavaOO.iml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 6c15ed3..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -JavaOO \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index f1f9173..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html deleted file mode 100644 index 3f5bd45..0000000 --- a/.idea/description.html +++ /dev/null @@ -1 +0,0 @@ -Basic project setup for Java/OO labs and projects. \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/JavaOO_2021.xml b/.idea/inspectionProfiles/JavaOO_2021.xml deleted file mode 100644 index 54179b2..0000000 --- a/.idea/inspectionProfiles/JavaOO_2021.xml +++ /dev/null @@ -1,3997 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 88aa82c..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,4008 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index b71c1f4..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/libraries/commons_cli_1_4.xml b/.idea/libraries/commons_cli_1_4.xml deleted file mode 100644 index d40e557..0000000 --- a/.idea/libraries/commons_cli_1_4.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/gson.xml b/.idea/libraries/gson.xml deleted file mode 100644 index ff58299..0000000 --- a/.idea/libraries/gson.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/miglayout_swing.xml b/.idea/libraries/miglayout_swing.xml deleted file mode 100644 index c47f13b..0000000 --- a/.idea/libraries/miglayout_swing.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/tddd78_annotations.xml b/.idea/libraries/tddd78_annotations.xml deleted file mode 100644 index f7fb2c1..0000000 --- a/.idea/libraries/tddd78_annotations.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1e2dd00..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 5213271..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml deleted file mode 100644 index 1f08b88..0000000 --- a/.idea/project-template.xml +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/JavaOO.iml b/JavaOO.iml deleted file mode 100644 index 79515aa..0000000 --- a/JavaOO.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file 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); } } -- cgit v1.2.1