22
33import java .awt .Color ;
44import java .awt .Dimension ;
5- import java .awt .event .ActionEvent ;
6- import java .awt .event .ActionListener ;
75import java .awt .event .MouseEvent ;
86import java .awt .event .MouseListener ;
97import java .awt .event .MouseMotionListener ;
2119public class Editor extends JFrame implements MouseListener , MouseMotionListener {
2220
2321 private final LevelFile levelFile ;
22+ private final int rowCount ;
23+ private final int columnCount ;
2424
2525 @ VisibleForTesting
2626 enum Component {
@@ -63,7 +63,9 @@ TileType getContent() {
6363 public Editor (int rowCount , int columnCount , String name ) throws IOException {
6464
6565 levelFile = LevelFile .of (name );
66- initializeEmptyLevel (rowCount , columnCount );
66+ this .rowCount = rowCount ;
67+ this .columnCount = columnCount ;
68+ initializeEmptyLevel ();
6769
6870 controller = new Controller (levelFile .getFilePath ().toString ());
6971 windowWidth = controller .warehouse .getColumns () * TILE_SIZE ;
@@ -93,8 +95,8 @@ public Editor (int rowCount, int columnCount, String name) throws IOException {
9395 JButton save = createSaveButton ();
9496
9597 save .addActionListener (_ -> {
96- if (isValidLevel (rowCount , columnCount )) {
97- saveLevelToFile (rowCount , columnCount );
98+ if (isValidLevel ()) {
99+ saveLevelToFile ();
98100 dispose ();
99101 new HomeWindow ();
100102 } else {
@@ -113,7 +115,7 @@ public Editor (int rowCount, int columnCount, String name) throws IOException {
113115 this .setVisible ( true );
114116 }
115117
116- private void initializeEmptyLevel (int rowCount , int columnCount ) {
118+ private void initializeEmptyLevel () {
117119 final var wall = TileType .WALL .codeAsString ();
118120 String wallRow = wall .repeat (columnCount );
119121 String middleRow = wall
@@ -283,11 +285,10 @@ public void mouseExited(MouseEvent e) {}
283285
284286 /**
285287 * Validates the level based on its dimensions and tile counts.
286- * @param rowCount Number of rows in the level
287- * @param columnCount Number of columns in the level
288+ *
288289 * @return true if the level is valid, false otherwise
289290 */
290- private boolean isValidLevel (int rowCount , int columnCount ) {
291+ private boolean isValidLevel () {
291292 int [] tileCounts = new int [TileType .values ().length ];
292293
293294 IntStream .range (0 , rowCount * columnCount ).forEach (i -> {
@@ -302,10 +303,8 @@ private boolean isValidLevel(int rowCount, int columnCount) {
302303
303304 /**
304305 * Saves the current level state to a file.
305- * @param rowCount Number of rows in the level
306- * @param columnCount Number of columns in the level
307306 */
308- private void saveLevelToFile (int rowCount , int columnCount ) {
307+ private void saveLevelToFile () {
309308 StringBuilder levelContent = new StringBuilder ();
310309
311310 IntStream .range (0 , rowCount * columnCount ).forEach (i -> {
0 commit comments