From 7e9385303bbc68f3b25de571eb371ce8c870ede7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9nyi=20Tam=C3=A1s?= Date: Sat, 11 May 2024 16:06:15 +0200 Subject: [PATCH 01/24] Add src directory --- src/{ => main/java}/Assets/0-reference.png | Bin src/{ => main/java}/Assets/1-bg.png | Bin src/{ => main/java}/Assets/1-button-1-text.png | Bin src/{ => main/java}/Assets/1-button-1.png | Bin src/{ => main/java}/Assets/1-button-2-text.png | Bin src/{ => main/java}/Assets/1-button-2.png | Bin src/{ => main/java}/Assets/1-button-3-text.png | Bin src/{ => main/java}/Assets/1-button-3.png | Bin src/{ => main/java}/Assets/1-layout.png | Bin src/{ => main/java}/Assets/1-title.png | Bin .../java}/Assets/2-button-color-picker.png | Bin src/{ => main/java}/Assets/2-button-minus.png | Bin src/{ => main/java}/Assets/2-button-plus.png | Bin src/{ => main/java}/Assets/2-layout.png | Bin src/{ => main/java}/Assets/2-map-preview.png | Bin src/{ => main/java}/Assets/2-title.png | Bin src/{ => main/java}/Assets/3-button-save.png | Bin src/{ => main/java}/Assets/3-cistern-filled.png | Bin src/{ => main/java}/Assets/3-cistern.png | Bin src/{ => main/java}/Assets/3-layout.png | Bin .../java}/Assets/3-player-mechanic-cap.png | Bin src/{ => main/java}/Assets/3-player-mechanic.png | Bin .../java}/Assets/3-player-saboteur-cap.png | Bin src/{ => main/java}/Assets/3-player-saboteur.png | Bin src/{ => main/java}/Assets/3-popup-atallit.png | Bin src/{ => main/java}/Assets/3-popup-felemel.png | Bin src/{ => main/java}/Assets/3-popup-lerak.png | Bin src/{ => main/java}/Assets/3-popup-lyukaszt.png | Bin src/{ => main/java}/Assets/3-popup-megken.png | Bin src/{ => main/java}/Assets/3-popup-mozog.png | Bin src/{ => main/java}/Assets/3-popup-passzol.png | Bin src/{ => main/java}/Assets/3-popup-ragaszt.png | Bin src/{ => main/java}/Assets/3-popup-szerel.png | Bin src/{ => main/java}/Assets/3-pump-indicator.png | Bin src/{ => main/java}/Assets/3-score-divider.png | Bin src/{ => main/java}/Assets/3-spring-filled.png | Bin src/{ => main/java}/Assets/3-spring.png | Bin .../java}/Assets/3-zigzagline-fallback.png | Bin src/{ => main/java}/Assets/4-layout.png | Bin src/{ => main/java}/Assets/4-player-wincap.png | Bin src/{ => main/java}/Assets/map1.txt | 0 src/{ => main/java}/Assets/map2.txt | 0 src/{ => main/java}/Assets/palya2.png | Bin src/{ => main/java}/Controller/Controller.java | 0 src/{ => main/java}/Controller/Main.java | 0 src/{ => main/java}/Model/ActionType.java | 0 src/{ => main/java}/Model/Cistern.java | 0 src/{ => main/java}/Model/IO_Manager.java | 0 src/{ => main/java}/Model/Mechanic.java | 0 src/{ => main/java}/Model/PickupAble.java | 0 src/{ => main/java}/Model/Pipe.java | 0 src/{ => main/java}/Model/Player.java | 0 src/{ => main/java}/Model/PlayerActionState.java | 0 src/{ => main/java}/Model/PointCounter.java | 0 src/{ => main/java}/Model/Pump.java | 0 src/{ => main/java}/Model/Saboteur.java | 0 src/{ => main/java}/Model/Spring.java | 0 src/{ => main/java}/Model/Steppable.java | 0 src/{ => main/java}/Model/WaterNode.java | 0 src/{ => main/java}/View/AddPlayerButton.java | 0 src/{ => main/java}/View/AppFrame.java | 0 src/{ => main/java}/View/AppPanel.java | 0 src/{ => main/java}/View/Button.java | 0 src/{ => main/java}/View/ChangeMaxPointButton.java | 0 src/{ => main/java}/View/CharacterCreation.java | 0 src/{ => main/java}/View/CisternView.java | 0 src/{ => main/java}/View/Clickable.java | 0 src/{ => main/java}/View/ColorPicker.java | 0 src/{ => main/java}/View/CreatePopUpBar.java | 0 src/{ => main/java}/View/Drawable.java | 0 src/{ => main/java}/View/GameView.java | 0 src/{ => main/java}/View/ImageUtility.java | 0 src/{ => main/java}/View/MechanicView.java | 0 src/{ => main/java}/View/MenuView.java | 0 src/{ => main/java}/View/MouseIn.java | 0 src/{ => main/java}/View/NewGameView.java | 0 src/{ => main/java}/View/Pictures.java | 0 src/{ => main/java}/View/PipeView.java | 0 src/{ => main/java}/View/PopUpBar.java | 0 src/{ => main/java}/View/PopUpButton.java | 0 src/{ => main/java}/View/PumpView.java | 0 src/{ => main/java}/View/SaboteurView.java | 0 src/{ => main/java}/View/SpringView.java | 0 src/{ => main/java}/View/SteppableView.java | 0 src/{ => main/java}/View/Window.java | 0 src/{ => main/java}/View/WindowOptions.java | 0 86 files changed, 0 insertions(+), 0 deletions(-) rename src/{ => main/java}/Assets/0-reference.png (100%) rename src/{ => main/java}/Assets/1-bg.png (100%) rename src/{ => main/java}/Assets/1-button-1-text.png (100%) rename src/{ => main/java}/Assets/1-button-1.png (100%) rename src/{ => main/java}/Assets/1-button-2-text.png (100%) rename src/{ => main/java}/Assets/1-button-2.png (100%) rename src/{ => main/java}/Assets/1-button-3-text.png (100%) rename src/{ => main/java}/Assets/1-button-3.png (100%) rename src/{ => main/java}/Assets/1-layout.png (100%) rename src/{ => main/java}/Assets/1-title.png (100%) rename src/{ => main/java}/Assets/2-button-color-picker.png (100%) rename src/{ => main/java}/Assets/2-button-minus.png (100%) rename src/{ => main/java}/Assets/2-button-plus.png (100%) rename src/{ => main/java}/Assets/2-layout.png (100%) rename src/{ => main/java}/Assets/2-map-preview.png (100%) rename src/{ => main/java}/Assets/2-title.png (100%) rename src/{ => main/java}/Assets/3-button-save.png (100%) rename src/{ => main/java}/Assets/3-cistern-filled.png (100%) rename src/{ => main/java}/Assets/3-cistern.png (100%) rename src/{ => main/java}/Assets/3-layout.png (100%) rename src/{ => main/java}/Assets/3-player-mechanic-cap.png (100%) rename src/{ => main/java}/Assets/3-player-mechanic.png (100%) rename src/{ => main/java}/Assets/3-player-saboteur-cap.png (100%) rename src/{ => main/java}/Assets/3-player-saboteur.png (100%) rename src/{ => main/java}/Assets/3-popup-atallit.png (100%) rename src/{ => main/java}/Assets/3-popup-felemel.png (100%) rename src/{ => main/java}/Assets/3-popup-lerak.png (100%) rename src/{ => main/java}/Assets/3-popup-lyukaszt.png (100%) rename src/{ => main/java}/Assets/3-popup-megken.png (100%) rename src/{ => main/java}/Assets/3-popup-mozog.png (100%) rename src/{ => main/java}/Assets/3-popup-passzol.png (100%) rename src/{ => main/java}/Assets/3-popup-ragaszt.png (100%) rename src/{ => main/java}/Assets/3-popup-szerel.png (100%) rename src/{ => main/java}/Assets/3-pump-indicator.png (100%) rename src/{ => main/java}/Assets/3-score-divider.png (100%) rename src/{ => main/java}/Assets/3-spring-filled.png (100%) rename src/{ => main/java}/Assets/3-spring.png (100%) rename src/{ => main/java}/Assets/3-zigzagline-fallback.png (100%) rename src/{ => main/java}/Assets/4-layout.png (100%) rename src/{ => main/java}/Assets/4-player-wincap.png (100%) rename src/{ => main/java}/Assets/map1.txt (100%) rename src/{ => main/java}/Assets/map2.txt (100%) rename src/{ => main/java}/Assets/palya2.png (100%) rename src/{ => main/java}/Controller/Controller.java (100%) rename src/{ => main/java}/Controller/Main.java (100%) rename src/{ => main/java}/Model/ActionType.java (100%) rename src/{ => main/java}/Model/Cistern.java (100%) rename src/{ => main/java}/Model/IO_Manager.java (100%) rename src/{ => main/java}/Model/Mechanic.java (100%) rename src/{ => main/java}/Model/PickupAble.java (100%) rename src/{ => main/java}/Model/Pipe.java (100%) rename src/{ => main/java}/Model/Player.java (100%) rename src/{ => main/java}/Model/PlayerActionState.java (100%) rename src/{ => main/java}/Model/PointCounter.java (100%) rename src/{ => main/java}/Model/Pump.java (100%) rename src/{ => main/java}/Model/Saboteur.java (100%) rename src/{ => main/java}/Model/Spring.java (100%) rename src/{ => main/java}/Model/Steppable.java (100%) rename src/{ => main/java}/Model/WaterNode.java (100%) rename src/{ => main/java}/View/AddPlayerButton.java (100%) rename src/{ => main/java}/View/AppFrame.java (100%) rename src/{ => main/java}/View/AppPanel.java (100%) rename src/{ => main/java}/View/Button.java (100%) rename src/{ => main/java}/View/ChangeMaxPointButton.java (100%) rename src/{ => main/java}/View/CharacterCreation.java (100%) rename src/{ => main/java}/View/CisternView.java (100%) rename src/{ => main/java}/View/Clickable.java (100%) rename src/{ => main/java}/View/ColorPicker.java (100%) rename src/{ => main/java}/View/CreatePopUpBar.java (100%) rename src/{ => main/java}/View/Drawable.java (100%) rename src/{ => main/java}/View/GameView.java (100%) rename src/{ => main/java}/View/ImageUtility.java (100%) rename src/{ => main/java}/View/MechanicView.java (100%) rename src/{ => main/java}/View/MenuView.java (100%) rename src/{ => main/java}/View/MouseIn.java (100%) rename src/{ => main/java}/View/NewGameView.java (100%) rename src/{ => main/java}/View/Pictures.java (100%) rename src/{ => main/java}/View/PipeView.java (100%) rename src/{ => main/java}/View/PopUpBar.java (100%) rename src/{ => main/java}/View/PopUpButton.java (100%) rename src/{ => main/java}/View/PumpView.java (100%) rename src/{ => main/java}/View/SaboteurView.java (100%) rename src/{ => main/java}/View/SpringView.java (100%) rename src/{ => main/java}/View/SteppableView.java (100%) rename src/{ => main/java}/View/Window.java (100%) rename src/{ => main/java}/View/WindowOptions.java (100%) diff --git a/src/Assets/0-reference.png b/src/main/java/Assets/0-reference.png similarity index 100% rename from src/Assets/0-reference.png rename to src/main/java/Assets/0-reference.png diff --git a/src/Assets/1-bg.png b/src/main/java/Assets/1-bg.png similarity index 100% rename from src/Assets/1-bg.png rename to src/main/java/Assets/1-bg.png diff --git a/src/Assets/1-button-1-text.png b/src/main/java/Assets/1-button-1-text.png similarity index 100% rename from src/Assets/1-button-1-text.png rename to src/main/java/Assets/1-button-1-text.png diff --git a/src/Assets/1-button-1.png b/src/main/java/Assets/1-button-1.png similarity index 100% rename from src/Assets/1-button-1.png rename to src/main/java/Assets/1-button-1.png diff --git a/src/Assets/1-button-2-text.png b/src/main/java/Assets/1-button-2-text.png similarity index 100% rename from src/Assets/1-button-2-text.png rename to src/main/java/Assets/1-button-2-text.png diff --git a/src/Assets/1-button-2.png b/src/main/java/Assets/1-button-2.png similarity index 100% rename from src/Assets/1-button-2.png rename to src/main/java/Assets/1-button-2.png diff --git a/src/Assets/1-button-3-text.png b/src/main/java/Assets/1-button-3-text.png similarity index 100% rename from src/Assets/1-button-3-text.png rename to src/main/java/Assets/1-button-3-text.png diff --git a/src/Assets/1-button-3.png b/src/main/java/Assets/1-button-3.png similarity index 100% rename from src/Assets/1-button-3.png rename to src/main/java/Assets/1-button-3.png diff --git a/src/Assets/1-layout.png b/src/main/java/Assets/1-layout.png similarity index 100% rename from src/Assets/1-layout.png rename to src/main/java/Assets/1-layout.png diff --git a/src/Assets/1-title.png b/src/main/java/Assets/1-title.png similarity index 100% rename from src/Assets/1-title.png rename to src/main/java/Assets/1-title.png diff --git a/src/Assets/2-button-color-picker.png b/src/main/java/Assets/2-button-color-picker.png similarity index 100% rename from src/Assets/2-button-color-picker.png rename to src/main/java/Assets/2-button-color-picker.png diff --git a/src/Assets/2-button-minus.png b/src/main/java/Assets/2-button-minus.png similarity index 100% rename from src/Assets/2-button-minus.png rename to src/main/java/Assets/2-button-minus.png diff --git a/src/Assets/2-button-plus.png b/src/main/java/Assets/2-button-plus.png similarity index 100% rename from src/Assets/2-button-plus.png rename to src/main/java/Assets/2-button-plus.png diff --git a/src/Assets/2-layout.png b/src/main/java/Assets/2-layout.png similarity index 100% rename from src/Assets/2-layout.png rename to src/main/java/Assets/2-layout.png diff --git a/src/Assets/2-map-preview.png b/src/main/java/Assets/2-map-preview.png similarity index 100% rename from src/Assets/2-map-preview.png rename to src/main/java/Assets/2-map-preview.png diff --git a/src/Assets/2-title.png b/src/main/java/Assets/2-title.png similarity index 100% rename from src/Assets/2-title.png rename to src/main/java/Assets/2-title.png diff --git a/src/Assets/3-button-save.png b/src/main/java/Assets/3-button-save.png similarity index 100% rename from src/Assets/3-button-save.png rename to src/main/java/Assets/3-button-save.png diff --git a/src/Assets/3-cistern-filled.png b/src/main/java/Assets/3-cistern-filled.png similarity index 100% rename from src/Assets/3-cistern-filled.png rename to src/main/java/Assets/3-cistern-filled.png diff --git a/src/Assets/3-cistern.png b/src/main/java/Assets/3-cistern.png similarity index 100% rename from src/Assets/3-cistern.png rename to src/main/java/Assets/3-cistern.png diff --git a/src/Assets/3-layout.png b/src/main/java/Assets/3-layout.png similarity index 100% rename from src/Assets/3-layout.png rename to src/main/java/Assets/3-layout.png diff --git a/src/Assets/3-player-mechanic-cap.png b/src/main/java/Assets/3-player-mechanic-cap.png similarity index 100% rename from src/Assets/3-player-mechanic-cap.png rename to src/main/java/Assets/3-player-mechanic-cap.png diff --git a/src/Assets/3-player-mechanic.png b/src/main/java/Assets/3-player-mechanic.png similarity index 100% rename from src/Assets/3-player-mechanic.png rename to src/main/java/Assets/3-player-mechanic.png diff --git a/src/Assets/3-player-saboteur-cap.png b/src/main/java/Assets/3-player-saboteur-cap.png similarity index 100% rename from src/Assets/3-player-saboteur-cap.png rename to src/main/java/Assets/3-player-saboteur-cap.png diff --git a/src/Assets/3-player-saboteur.png b/src/main/java/Assets/3-player-saboteur.png similarity index 100% rename from src/Assets/3-player-saboteur.png rename to src/main/java/Assets/3-player-saboteur.png diff --git a/src/Assets/3-popup-atallit.png b/src/main/java/Assets/3-popup-atallit.png similarity index 100% rename from src/Assets/3-popup-atallit.png rename to src/main/java/Assets/3-popup-atallit.png diff --git a/src/Assets/3-popup-felemel.png b/src/main/java/Assets/3-popup-felemel.png similarity index 100% rename from src/Assets/3-popup-felemel.png rename to src/main/java/Assets/3-popup-felemel.png diff --git a/src/Assets/3-popup-lerak.png b/src/main/java/Assets/3-popup-lerak.png similarity index 100% rename from src/Assets/3-popup-lerak.png rename to src/main/java/Assets/3-popup-lerak.png diff --git a/src/Assets/3-popup-lyukaszt.png b/src/main/java/Assets/3-popup-lyukaszt.png similarity index 100% rename from src/Assets/3-popup-lyukaszt.png rename to src/main/java/Assets/3-popup-lyukaszt.png diff --git a/src/Assets/3-popup-megken.png b/src/main/java/Assets/3-popup-megken.png similarity index 100% rename from src/Assets/3-popup-megken.png rename to src/main/java/Assets/3-popup-megken.png diff --git a/src/Assets/3-popup-mozog.png b/src/main/java/Assets/3-popup-mozog.png similarity index 100% rename from src/Assets/3-popup-mozog.png rename to src/main/java/Assets/3-popup-mozog.png diff --git a/src/Assets/3-popup-passzol.png b/src/main/java/Assets/3-popup-passzol.png similarity index 100% rename from src/Assets/3-popup-passzol.png rename to src/main/java/Assets/3-popup-passzol.png diff --git a/src/Assets/3-popup-ragaszt.png b/src/main/java/Assets/3-popup-ragaszt.png similarity index 100% rename from src/Assets/3-popup-ragaszt.png rename to src/main/java/Assets/3-popup-ragaszt.png diff --git a/src/Assets/3-popup-szerel.png b/src/main/java/Assets/3-popup-szerel.png similarity index 100% rename from src/Assets/3-popup-szerel.png rename to src/main/java/Assets/3-popup-szerel.png diff --git a/src/Assets/3-pump-indicator.png b/src/main/java/Assets/3-pump-indicator.png similarity index 100% rename from src/Assets/3-pump-indicator.png rename to src/main/java/Assets/3-pump-indicator.png diff --git a/src/Assets/3-score-divider.png b/src/main/java/Assets/3-score-divider.png similarity index 100% rename from src/Assets/3-score-divider.png rename to src/main/java/Assets/3-score-divider.png diff --git a/src/Assets/3-spring-filled.png b/src/main/java/Assets/3-spring-filled.png similarity index 100% rename from src/Assets/3-spring-filled.png rename to src/main/java/Assets/3-spring-filled.png diff --git a/src/Assets/3-spring.png b/src/main/java/Assets/3-spring.png similarity index 100% rename from src/Assets/3-spring.png rename to src/main/java/Assets/3-spring.png diff --git a/src/Assets/3-zigzagline-fallback.png b/src/main/java/Assets/3-zigzagline-fallback.png similarity index 100% rename from src/Assets/3-zigzagline-fallback.png rename to src/main/java/Assets/3-zigzagline-fallback.png diff --git a/src/Assets/4-layout.png b/src/main/java/Assets/4-layout.png similarity index 100% rename from src/Assets/4-layout.png rename to src/main/java/Assets/4-layout.png diff --git a/src/Assets/4-player-wincap.png b/src/main/java/Assets/4-player-wincap.png similarity index 100% rename from src/Assets/4-player-wincap.png rename to src/main/java/Assets/4-player-wincap.png diff --git a/src/Assets/map1.txt b/src/main/java/Assets/map1.txt similarity index 100% rename from src/Assets/map1.txt rename to src/main/java/Assets/map1.txt diff --git a/src/Assets/map2.txt b/src/main/java/Assets/map2.txt similarity index 100% rename from src/Assets/map2.txt rename to src/main/java/Assets/map2.txt diff --git a/src/Assets/palya2.png b/src/main/java/Assets/palya2.png similarity index 100% rename from src/Assets/palya2.png rename to src/main/java/Assets/palya2.png diff --git a/src/Controller/Controller.java b/src/main/java/Controller/Controller.java similarity index 100% rename from src/Controller/Controller.java rename to src/main/java/Controller/Controller.java diff --git a/src/Controller/Main.java b/src/main/java/Controller/Main.java similarity index 100% rename from src/Controller/Main.java rename to src/main/java/Controller/Main.java diff --git a/src/Model/ActionType.java b/src/main/java/Model/ActionType.java similarity index 100% rename from src/Model/ActionType.java rename to src/main/java/Model/ActionType.java diff --git a/src/Model/Cistern.java b/src/main/java/Model/Cistern.java similarity index 100% rename from src/Model/Cistern.java rename to src/main/java/Model/Cistern.java diff --git a/src/Model/IO_Manager.java b/src/main/java/Model/IO_Manager.java similarity index 100% rename from src/Model/IO_Manager.java rename to src/main/java/Model/IO_Manager.java diff --git a/src/Model/Mechanic.java b/src/main/java/Model/Mechanic.java similarity index 100% rename from src/Model/Mechanic.java rename to src/main/java/Model/Mechanic.java diff --git a/src/Model/PickupAble.java b/src/main/java/Model/PickupAble.java similarity index 100% rename from src/Model/PickupAble.java rename to src/main/java/Model/PickupAble.java diff --git a/src/Model/Pipe.java b/src/main/java/Model/Pipe.java similarity index 100% rename from src/Model/Pipe.java rename to src/main/java/Model/Pipe.java diff --git a/src/Model/Player.java b/src/main/java/Model/Player.java similarity index 100% rename from src/Model/Player.java rename to src/main/java/Model/Player.java diff --git a/src/Model/PlayerActionState.java b/src/main/java/Model/PlayerActionState.java similarity index 100% rename from src/Model/PlayerActionState.java rename to src/main/java/Model/PlayerActionState.java diff --git a/src/Model/PointCounter.java b/src/main/java/Model/PointCounter.java similarity index 100% rename from src/Model/PointCounter.java rename to src/main/java/Model/PointCounter.java diff --git a/src/Model/Pump.java b/src/main/java/Model/Pump.java similarity index 100% rename from src/Model/Pump.java rename to src/main/java/Model/Pump.java diff --git a/src/Model/Saboteur.java b/src/main/java/Model/Saboteur.java similarity index 100% rename from src/Model/Saboteur.java rename to src/main/java/Model/Saboteur.java diff --git a/src/Model/Spring.java b/src/main/java/Model/Spring.java similarity index 100% rename from src/Model/Spring.java rename to src/main/java/Model/Spring.java diff --git a/src/Model/Steppable.java b/src/main/java/Model/Steppable.java similarity index 100% rename from src/Model/Steppable.java rename to src/main/java/Model/Steppable.java diff --git a/src/Model/WaterNode.java b/src/main/java/Model/WaterNode.java similarity index 100% rename from src/Model/WaterNode.java rename to src/main/java/Model/WaterNode.java diff --git a/src/View/AddPlayerButton.java b/src/main/java/View/AddPlayerButton.java similarity index 100% rename from src/View/AddPlayerButton.java rename to src/main/java/View/AddPlayerButton.java diff --git a/src/View/AppFrame.java b/src/main/java/View/AppFrame.java similarity index 100% rename from src/View/AppFrame.java rename to src/main/java/View/AppFrame.java diff --git a/src/View/AppPanel.java b/src/main/java/View/AppPanel.java similarity index 100% rename from src/View/AppPanel.java rename to src/main/java/View/AppPanel.java diff --git a/src/View/Button.java b/src/main/java/View/Button.java similarity index 100% rename from src/View/Button.java rename to src/main/java/View/Button.java diff --git a/src/View/ChangeMaxPointButton.java b/src/main/java/View/ChangeMaxPointButton.java similarity index 100% rename from src/View/ChangeMaxPointButton.java rename to src/main/java/View/ChangeMaxPointButton.java diff --git a/src/View/CharacterCreation.java b/src/main/java/View/CharacterCreation.java similarity index 100% rename from src/View/CharacterCreation.java rename to src/main/java/View/CharacterCreation.java diff --git a/src/View/CisternView.java b/src/main/java/View/CisternView.java similarity index 100% rename from src/View/CisternView.java rename to src/main/java/View/CisternView.java diff --git a/src/View/Clickable.java b/src/main/java/View/Clickable.java similarity index 100% rename from src/View/Clickable.java rename to src/main/java/View/Clickable.java diff --git a/src/View/ColorPicker.java b/src/main/java/View/ColorPicker.java similarity index 100% rename from src/View/ColorPicker.java rename to src/main/java/View/ColorPicker.java diff --git a/src/View/CreatePopUpBar.java b/src/main/java/View/CreatePopUpBar.java similarity index 100% rename from src/View/CreatePopUpBar.java rename to src/main/java/View/CreatePopUpBar.java diff --git a/src/View/Drawable.java b/src/main/java/View/Drawable.java similarity index 100% rename from src/View/Drawable.java rename to src/main/java/View/Drawable.java diff --git a/src/View/GameView.java b/src/main/java/View/GameView.java similarity index 100% rename from src/View/GameView.java rename to src/main/java/View/GameView.java diff --git a/src/View/ImageUtility.java b/src/main/java/View/ImageUtility.java similarity index 100% rename from src/View/ImageUtility.java rename to src/main/java/View/ImageUtility.java diff --git a/src/View/MechanicView.java b/src/main/java/View/MechanicView.java similarity index 100% rename from src/View/MechanicView.java rename to src/main/java/View/MechanicView.java diff --git a/src/View/MenuView.java b/src/main/java/View/MenuView.java similarity index 100% rename from src/View/MenuView.java rename to src/main/java/View/MenuView.java diff --git a/src/View/MouseIn.java b/src/main/java/View/MouseIn.java similarity index 100% rename from src/View/MouseIn.java rename to src/main/java/View/MouseIn.java diff --git a/src/View/NewGameView.java b/src/main/java/View/NewGameView.java similarity index 100% rename from src/View/NewGameView.java rename to src/main/java/View/NewGameView.java diff --git a/src/View/Pictures.java b/src/main/java/View/Pictures.java similarity index 100% rename from src/View/Pictures.java rename to src/main/java/View/Pictures.java diff --git a/src/View/PipeView.java b/src/main/java/View/PipeView.java similarity index 100% rename from src/View/PipeView.java rename to src/main/java/View/PipeView.java diff --git a/src/View/PopUpBar.java b/src/main/java/View/PopUpBar.java similarity index 100% rename from src/View/PopUpBar.java rename to src/main/java/View/PopUpBar.java diff --git a/src/View/PopUpButton.java b/src/main/java/View/PopUpButton.java similarity index 100% rename from src/View/PopUpButton.java rename to src/main/java/View/PopUpButton.java diff --git a/src/View/PumpView.java b/src/main/java/View/PumpView.java similarity index 100% rename from src/View/PumpView.java rename to src/main/java/View/PumpView.java diff --git a/src/View/SaboteurView.java b/src/main/java/View/SaboteurView.java similarity index 100% rename from src/View/SaboteurView.java rename to src/main/java/View/SaboteurView.java diff --git a/src/View/SpringView.java b/src/main/java/View/SpringView.java similarity index 100% rename from src/View/SpringView.java rename to src/main/java/View/SpringView.java diff --git a/src/View/SteppableView.java b/src/main/java/View/SteppableView.java similarity index 100% rename from src/View/SteppableView.java rename to src/main/java/View/SteppableView.java diff --git a/src/View/Window.java b/src/main/java/View/Window.java similarity index 100% rename from src/View/Window.java rename to src/main/java/View/Window.java diff --git a/src/View/WindowOptions.java b/src/main/java/View/WindowOptions.java similarity index 100% rename from src/View/WindowOptions.java rename to src/main/java/View/WindowOptions.java From 1dac3ce7b56c768904158e476844aee02f7491b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9nyi=20Tam=C3=A1s?= Date: Sat, 18 May 2024 13:57:00 +0200 Subject: [PATCH 02/24] Add jacoco and sample unit test --- pom.xml | 41 +++++++++++++++++++++++++++++++ src/test/java/model/PipeTest.java | 14 +++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/test/java/model/PipeTest.java diff --git a/pom.xml b/pom.xml index 716e2cc..2a3d43f 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,26 @@ https://sonarcloud.io + + + org.junit.jupiter + junit-jupiter + 5.8.2 + test + + + org.mockito + mockito-core + 4.4.0 + test + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + test + + @@ -32,6 +52,27 @@ maven-surefire-plugin 2.22.2 + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + default-prepare-agent + + prepare-agent + + + + default-report + prepare-package + + report + + + + + diff --git a/src/test/java/model/PipeTest.java b/src/test/java/model/PipeTest.java new file mode 100644 index 0000000..3bb8887 --- /dev/null +++ b/src/test/java/model/PipeTest.java @@ -0,0 +1,14 @@ +package model; + +import Model.Pipe; +import junit.framework.Assert; +import org.junit.jupiter.api.Test; + +public class PipeTest { + + @Test + public void constructorTest() { + Pipe pipe = new Pipe(); + Assert.assertNotNull(pipe); + } +} From 26f2348e279c034c059e9975ab65c615ef5c22f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9nyi=20Tam=C3=A1s?= Date: Sat, 18 May 2024 14:10:38 +0200 Subject: [PATCH 03/24] Add new test, introduce DI --- src/main/java/Controller/Controller.java | 2 +- src/main/java/Model/Pipe.java | 4 ++-- src/test/java/model/PipeTest.java | 26 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index e564351..f6ea363 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -235,7 +235,7 @@ public void create(String name, String type,int x, int y) { gameView.addCisternView(cisternView); } case "pipe" -> { - Pipe pipe = new Pipe(); + Pipe pipe = new Pipe(PointCounter.getInstance()); steppables.add(pipe); pipes.add(pipe); pickupables.add(pipe); diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index f003ac4..a7e78d6 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -59,8 +59,8 @@ public class Pipe extends Steppable implements PickupAble, Serializable { /** * Pipe konstruktora */ - public Pipe() { - counter = PointCounter.getInstance(); + public Pipe(PointCounter pointCounter) { + counter = pointCounter; } /** diff --git a/src/test/java/model/PipeTest.java b/src/test/java/model/PipeTest.java index 3bb8887..57ca81a 100644 --- a/src/test/java/model/PipeTest.java +++ b/src/test/java/model/PipeTest.java @@ -1,14 +1,38 @@ package model; import Model.Pipe; +import Model.PointCounter; import junit.framework.Assert; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static junit.framework.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.*; public class PipeTest { + private Pipe pipe; + + private PointCounter pointCounter; + + @BeforeEach + public void init(){ + pointCounter = mock(PointCounter.class); + this.pipe = new Pipe(pointCounter); + } @Test public void constructorTest() { - Pipe pipe = new Pipe(); Assert.assertNotNull(pipe); } + + @Test + public void gainWaterTest() { + var res = pipe.GainWater(10); + + verify(pointCounter, never()).AddSaboteurPoints(anyInt()); + assertEquals(1, res); + + } } From bce01f014e539c61c4e26c91f488ee5874b486c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9nyi=20Tam=C3=A1s?= Date: Sun, 19 May 2024 16:10:33 +0200 Subject: [PATCH 04/24] Add further test cases to Pipe --- src/test/java/model/PipeTest.java | 50 +++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/src/test/java/model/PipeTest.java b/src/test/java/model/PipeTest.java index 57ca81a..51d2387 100644 --- a/src/test/java/model/PipeTest.java +++ b/src/test/java/model/PipeTest.java @@ -1,13 +1,15 @@ package model; +import Model.IO_Manager; import Model.Pipe; import Model.PointCounter; +import Model.WaterNode; import junit.framework.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.*; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; @@ -18,21 +20,57 @@ public class PipeTest { private PointCounter pointCounter; @BeforeEach - public void init(){ + public void init() { pointCounter = mock(PointCounter.class); this.pipe = new Pipe(pointCounter); } + @Test public void constructorTest() { Assert.assertNotNull(pipe); } @Test - public void gainWaterTest() { - var res = pipe.GainWater(10); + public void gainWaterTestWhenPipeIsFree() { + pipe.GainWater(10); + verifyNoInteractions(pointCounter); + } + + @Test + public void gainWaterTestWhenPipeIsBroken() { + pipe.setBroken(true); + pipe.GainWater(10); + + verify(pointCounter).AddSaboteurPoints(10); + } + + @Test + public void loseWaterTest() { + pipe.setHeldWater(20); + pipe.LoseWater(12); - verify(pointCounter, never()).AddSaboteurPoints(anyInt()); - assertEquals(1, res); + assertEquals(8, pipe.getHeldWater()); + pipe.LoseWater(10); + + assertEquals(0, pipe.getHeldWater()); } + + @Test + public void AddWaterNodeShouldOnlySucceedIfPipeHasFreeNode() { + assertTrue(pipe.AddWaterNode(mock(WaterNode.class))); + assertTrue(pipe.AddWaterNode(mock(WaterNode.class))); + assertFalse(pipe.AddWaterNode(mock(WaterNode.class))); + } + + @Test + public void repairedTestWhenBroken() { + pipe.setBroken(true); + + pipe.Repaired(); + + assertFalse(pipe.isBroken()); + } + + } From ccd450014f63b3482137a02976e9bb355eed8f09 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 17:29:06 +0200 Subject: [PATCH 05/24] Create PumpTest.java --- src/test/java/model/PumpTest.java | 76 +++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/test/java/model/PumpTest.java diff --git a/src/test/java/model/PumpTest.java b/src/test/java/model/PumpTest.java new file mode 100644 index 0000000..d10c3de --- /dev/null +++ b/src/test/java/model/PumpTest.java @@ -0,0 +1,76 @@ +package model; + +import Model.Pump; +import Model.Pipe; +import Controller.Controller; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static junit.framework.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.*; + +class PumpTest { + + private Pump pump; + private Pipe mockActiveIn; + private Pipe mockActiveOut; + private Controller mockController; + + @BeforeEach + void setUp() { + pump = new Pump(); + mockActiveIn = Mockito.mock(Pipe.class); + mockActiveOut = Mockito.mock(Pipe.class); + mockController = Mockito.mock(Controller.class); + + pump.setActiveIn(mockActiveIn); + pump.setActiveOut(mockActiveOut); + } + + @Test + void testWaterFlow() { + // Arrange + pump.setHeldWater(10); + when(mockActiveOut.GainWater(anyInt())).thenReturn(1); + when(mockActiveIn.LoseWater(anyInt())).thenReturn(1); + when(Controller.getInstance()).thenReturn(mockController); + when(mockController.getObjectName(any())).thenReturn("Pipe"); + + // Act + pump.WaterFlow(); + + // Assert + assertEquals(9, pump.getHeldWater()); + verify(mockActiveOut).GainWater(1); + verify(mockActiveIn).LoseWater(1); + verify(mockActiveIn).GainWater(0); + } + + @Test + void testWaterFlowWhenBroken() { + // Arrange + pump.setBroken(true); + + // Act + pump.WaterFlow(); + + // Assert + verify(mockActiveOut, never()).GainWater(anyInt()); + verify(mockActiveIn, never()).LoseWater(anyInt()); + } + + @Test + void testWaterFlowWhenEmpty() { + // Arrange + pump.setHeldWater(0); + + // Act + pump.WaterFlow(); + + // Assert + verify(mockActiveOut, never()).GainWater(anyInt()); + verify(mockActiveIn).LoseWater(1); + } +} \ No newline at end of file From 70a2cf268d465a26b9d102a92d951846e97ad3d3 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 17:34:33 +0200 Subject: [PATCH 06/24] Update PumpTest --- src/test/java/model/PumpTest.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/test/java/model/PumpTest.java b/src/test/java/model/PumpTest.java index d10c3de..6082e6b 100644 --- a/src/test/java/model/PumpTest.java +++ b/src/test/java/model/PumpTest.java @@ -11,32 +11,28 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; -class PumpTest { +public class PumpTest { private Pump pump; private Pipe mockActiveIn; private Pipe mockActiveOut; - private Controller mockController; @BeforeEach - void setUp() { + public void init() { pump = new Pump(); mockActiveIn = Mockito.mock(Pipe.class); mockActiveOut = Mockito.mock(Pipe.class); - mockController = Mockito.mock(Controller.class); pump.setActiveIn(mockActiveIn); pump.setActiveOut(mockActiveOut); } @Test - void testWaterFlow() { + public void testWaterFlow() { // Arrange pump.setHeldWater(10); when(mockActiveOut.GainWater(anyInt())).thenReturn(1); when(mockActiveIn.LoseWater(anyInt())).thenReturn(1); - when(Controller.getInstance()).thenReturn(mockController); - when(mockController.getObjectName(any())).thenReturn("Pipe"); // Act pump.WaterFlow(); @@ -49,7 +45,7 @@ void testWaterFlow() { } @Test - void testWaterFlowWhenBroken() { + public void testWaterFlowWhenBroken() { // Arrange pump.setBroken(true); @@ -62,7 +58,7 @@ void testWaterFlowWhenBroken() { } @Test - void testWaterFlowWhenEmpty() { + public void testWaterFlowWhenEmpty() { // Arrange pump.setHeldWater(0); From 10eaf90c5f4845644f6aa040c7cd16d772449c63 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 18:56:14 +0200 Subject: [PATCH 07/24] Fix tests and fix picture loading, controller DI in Pump.java --- src/main/java/Controller/Controller.java | 20 ++-- src/main/java/Model/Pump.java | 27 ++++- src/main/java/View/Button.java | 4 +- src/main/java/View/CisternView.java | 2 +- src/main/java/View/GameView.java | 4 +- src/main/java/View/ImageUtility.java | 3 +- src/main/java/View/MechanicView.java | 2 +- src/main/java/View/MenuView.java | 8 +- src/main/java/View/NewGameView.java | 15 ++- src/main/java/View/Pictures.java | 137 ++++++++++++++++++----- src/main/java/View/PopUpButton.java | 19 ++-- src/main/java/View/PumpView.java | 2 +- src/main/java/View/SaboteurView.java | 5 +- src/main/java/View/SpringView.java | 4 +- src/test/java/model/PumpTest.java | 18 +-- 15 files changed, 180 insertions(+), 90 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index f6ea363..8faccc0 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -2,7 +2,6 @@ import Model.*; import View.*; -import View.Window; import java.awt.*; import java.io.*; @@ -76,10 +75,6 @@ static public Controller getInstance() { * Ciszternáknál a csövek nevének generálásához használt futóváltozó */ public int createdPipeNumber = 1; - /** - * Szöveg méretezésére használt változó, mennyisége a kicsi map-kép hossza - */ - private int scaleForText; /** * Az új játék ablaknál létrehozott szerelők száma-1(indexe) */ @@ -207,7 +202,7 @@ public void create(String name, String type,int x, int y) { gameView.addSaboteurView(saboteurView); } case "pump" -> { - Pump pump = new Pump(); + Pump pump = new Pump(Controller.getInstance()); steppables.add(pump); nodes.add(pump); pumps.add(pump); @@ -296,7 +291,7 @@ public void move(String playerName, String steppableName) { IO_Manager.write(steppableName + ".players = " + listWrite(s.getPlayers()), Controller.filetoWrite != null); IO_Manager.write(playerName + ".standingOn = " + steppableName, Controller.filetoWrite != null); if (prev != null) - if (prev.getPlayers().size() == 0) + if (prev.getPlayers().isEmpty()) IO_Manager.write(getObjectName(prev) + ".players = null", Controller.filetoWrite != null); else IO_Manager.write(getObjectName(prev) + ".players = " + listWrite(prev.getPlayers()), Controller.filetoWrite != null); @@ -738,8 +733,7 @@ public void load(String filename) { try { FileInputStream fis = new FileInputStream("program.txt"); ObjectInputStream ois = new ObjectInputStream(fis); - Controller c2 = (Controller) ois.readObject(); - controller = c2; + controller = (Controller) ois.readObject(); } catch (Exception e) { e.printStackTrace(); } @@ -826,16 +820,16 @@ public void startGame() { * @return - a kiiratott szöveg */ private String listWrite(LinkedList list) { - String out = ""; + StringBuilder out = new StringBuilder(); try { for (int i = 0; i < list.size(); i++) { - out += getObjectName(list.get(i)); - if (i != list.size() - 1) out += ", "; + out.append(getObjectName(list.get(i))); + if (i != list.size() - 1) out.append(", "); } } catch (Exception e) { e.printStackTrace(); } - return out; + return out.toString(); } diff --git a/src/main/java/Model/Pump.java b/src/main/java/Model/Pump.java index 76822a3..b07145e 100644 --- a/src/main/java/Model/Pump.java +++ b/src/main/java/Model/Pump.java @@ -33,6 +33,21 @@ public class Pump extends WaterNode implements PickupAble, Serializable { */ private Pipe activeOut = null; + private Controller controller; + + public Pump(Controller controller) { + this.controller = controller; + } + + + public Controller getController() { + return controller; + } + + public void setController(Controller controller) { + this.controller = controller; + } + /** * Akkor hívódik, ha egy játékos felveszi ezt a pumpát(amit nem tud) * @param from melyik elemről vesszük le / csatlakoztatjuk le a pumpát @@ -103,7 +118,7 @@ public boolean PlacedDownTo(Pump pickup) { public void WaterFlow() { if (broken) { - IO_Manager.writeInfo(Controller.getInstance().getObjectName(this) + " is broken", Controller.filetoWrite != null); + IO_Manager.writeInfo(controller.getObjectName(this) + " is broken", controller.filetoWrite != null); } int gained=0; if(!broken && heldWater != 0 && activeOut != null) @@ -112,9 +127,9 @@ public void WaterFlow() { if(gained==1){ heldWater--; } - IO_Manager.write(Controller.getInstance().getObjectName(activeOut) + " gained " + gained, Controller.filetoWrite != null); + IO_Manager.write(controller.getObjectName(activeOut) + " gained " + gained, controller.filetoWrite != null); } else if (heldWater == 0) { - IO_Manager.writeInfo(Controller.getInstance().getObjectName(this) + " is empty", Controller.filetoWrite != null); + IO_Manager.writeInfo(controller.getObjectName(this) + " is empty", controller.filetoWrite != null); } if (activeIn != null) { @@ -123,7 +138,7 @@ public void WaterFlow() { int excess = (heldWater + lost > waterCapacity) ? (heldWater + lost - waterCapacity) : 0; activeIn.GainWater(excess); heldWater +=lost-excess; - IO_Manager.write(Controller.getInstance().getObjectName(activeIn) + " lost " + (lost - excess), Controller.filetoWrite != null); + IO_Manager.write(controller.getObjectName(activeIn) + " lost " + (lost - excess), controller.filetoWrite != null); } } @@ -215,8 +230,8 @@ public boolean AddPipe(Pipe p) { if(valid) pipes.add(p); else - IO_Manager.writeInfo("Can't place " + Controller.getInstance().getObjectName(p) + " here, because " + - Controller.getInstance().getObjectName(this) + " reached pipe capacity", Controller.filetoWrite != null); + IO_Manager.writeInfo("Can't place " + controller.getObjectName(p) + " here, because " + + controller.getObjectName(this) + " reached pipe capacity", controller.filetoWrite != null); return valid; } diff --git a/src/main/java/View/Button.java b/src/main/java/View/Button.java index 1f55ef3..51ff6cd 100644 --- a/src/main/java/View/Button.java +++ b/src/main/java/View/Button.java @@ -78,13 +78,13 @@ public void clickAction(MouseEvent e) { if(this.option == WindowOptions.map1){ this.option = WindowOptions.map2; Controller.getInstance().getNewGameView().setMap(2); - img = ImageUtility.scaleImage(mappreview2, 200); + img = ImageUtility.scaleImage(getMapPreview2(), 200); return; } if(this.option == WindowOptions.map2){ this.option = WindowOptions.map1; Controller.getInstance().getNewGameView().setMap(1); - img = ImageUtility.scaleImage(mapPrevButton, 200); + img = ImageUtility.scaleImage(getMapPrevButton(), 200); return; } // játék indítása diff --git a/src/main/java/View/CisternView.java b/src/main/java/View/CisternView.java index 2179101..9f30a22 100644 --- a/src/main/java/View/CisternView.java +++ b/src/main/java/View/CisternView.java @@ -31,7 +31,7 @@ public CisternView(int x, int y, int r, Cistern c, Window v) { super(x, y, v); this.r = r; cistern = c; - sprite = Pictures.cisternFilledImg; + sprite = Pictures.getCisternFilledImg(); sprite = ImageUtility.scaleImage(sprite, 2*r); if (WindowOptions.windowOption == WindowOptions.game) gameView = (GameView) v; diff --git a/src/main/java/View/GameView.java b/src/main/java/View/GameView.java index 6978ed5..b886f45 100644 --- a/src/main/java/View/GameView.java +++ b/src/main/java/View/GameView.java @@ -60,7 +60,7 @@ public void setFrame(AppFrame frame) { public GameView(AppFrame frame) { this.frame = frame; exit = new Button(frame.getWidth() - 80, 10, 50, 50, this); - exit.img = ImageUtility.scaleImage(exitButton, 45); + exit.img = ImageUtility.scaleImage(getExitButton(), 45); exit.option = WindowOptions.exit; addDrawable(exit, true); addClickable(exit, true); @@ -112,7 +112,7 @@ else if (PointCounter.getInstance().GetMechanicPoints() == PointCounter.getInsta g.setColor(Color.BLACK); g.setFont(new Font("Inter", Font.BOLD, 50)); g.drawString(Integer.toString(PointCounter.getInstance().GetMechanicPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 50, 55); - g.drawImage(ImageUtility.scaleImage(scoreDivider, 35), Controller.getInstance().getFrame().getWidth() - 300, 20, null); + g.drawImage(ImageUtility.scaleImage(getScoreDivider(), 35), Controller.getInstance().getFrame().getWidth() - 300, 20, null); g.drawString(Integer.toString(PointCounter.getInstance().GetSaboteurPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 200, 55); for (Drawable d : drawables) { diff --git a/src/main/java/View/ImageUtility.java b/src/main/java/View/ImageUtility.java index 225feb6..ef0fb0d 100644 --- a/src/main/java/View/ImageUtility.java +++ b/src/main/java/View/ImageUtility.java @@ -20,7 +20,8 @@ public static BufferedImage ImageLoad(String file) { BufferedImage image = null; try { - String nameOfFile = System.getProperty("user.dir") + File.separator + "src" + File.separator + "Assets" + File.separator + file; + String nameOfFile = System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + + File.separator + "java" + File.separator + "Assets" + File.separator + file; File in = new File(nameOfFile); image = ImageIO.read(in); diff --git a/src/main/java/View/MechanicView.java b/src/main/java/View/MechanicView.java index efb883d..7b371ff 100644 --- a/src/main/java/View/MechanicView.java +++ b/src/main/java/View/MechanicView.java @@ -45,7 +45,7 @@ public void setColor(Color color) { this.color = color; } - Image imageForScale = ImageUtility.scaleImage(mapPrevButton, 200); + Image imageForScale = ImageUtility.scaleImage(getMapPrevButton(), 200); private int number; diff --git a/src/main/java/View/MenuView.java b/src/main/java/View/MenuView.java index df5cf16..84d38ae 100644 --- a/src/main/java/View/MenuView.java +++ b/src/main/java/View/MenuView.java @@ -13,8 +13,8 @@ public class MenuView extends Window { Button newGame, exit; - private BufferedImage background = ImageUtility.backgroundScale(Pictures.background); - private BufferedImage bgText = ImageUtility.scaleImage(menuTitle, 250); + private BufferedImage background = ImageUtility.backgroundScale(getBackground()); + private BufferedImage bgText = ImageUtility.scaleImage(getMenuTitle(), 250); /** * Konstruktor @@ -26,12 +26,12 @@ public MenuView() { exit = new Button(760, 370, 250 + 250, 50, this); newGame.text = "Új játék"; - newGame.img = ImageUtility.scaleImage(playButton, 50); + newGame.img = ImageUtility.scaleImage(getPlayButton(), 50); newGame.option = WindowOptions.newgame; exit.text = "Kilépés"; - exit.img = ImageUtility.scaleImage(exitButton, 50); + exit.img = ImageUtility.scaleImage(getExitButton(), 50); exit.option = WindowOptions.exit; addDrawable(newGame, true); addClickable(newGame, true); diff --git a/src/main/java/View/NewGameView.java b/src/main/java/View/NewGameView.java index 941291d..4b33d47 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/View/NewGameView.java @@ -48,7 +48,7 @@ public NewGameView() { exit = new Button(screenWidth - 100, 10, 150, 150, this); map = new Button(50, screenHeight / 2, 500, 300, this); map.option = WindowOptions.map1; - map.img = ImageUtility.scaleImage(mapPrevButton, 200); + map.img = ImageUtility.scaleImage(getMapPrevButton(), 200); int offset = 25; addSaboteur = new AddPlayerButton(map.x+map.img.getWidth()+140+220, screenHeight / 2 - 35 + 190 + offset, 35, 35, this, 1, "saboteur"); @@ -59,14 +59,14 @@ public NewGameView() { increase = new ChangeMaxPointButton(screenWidth / 2 + 16 * 13, screenHeight / 6 - 8, 35, 35, this, 1); decrease = new ChangeMaxPointButton(screenWidth / 2 + 20 * 13, screenHeight / 6 - 8, 35, 35, this, -1); - start.img = ImageUtility.scaleImage(playButton, 50); + start.img = ImageUtility.scaleImage(getPlayButton(), 50); start.option = WindowOptions.game; - exit.img = ImageUtility.scaleImage(exitButton, 50); + exit.img = ImageUtility.scaleImage(getExitButton(), 50); exit.option = WindowOptions.exit; - addMechanic.img = ImageUtility.scaleImage(plusButton, 35); - addSaboteur.img = ImageUtility.scaleImage(plusButton, 35); - increase.img = ImageUtility.scaleImage(plusButton, 35); - decrease.img = ImageUtility.scaleImage(minusButton, 35); + addMechanic.img = ImageUtility.scaleImage(getPlusButton(), 35); + addSaboteur.img = ImageUtility.scaleImage(getPlusButton(), 35); + increase.img = ImageUtility.scaleImage(getPlusButton(), 35); + decrease.img = ImageUtility.scaleImage(getMinusButton(), 35); addDrawable(start, true); addDrawable(exit, true); @@ -115,7 +115,6 @@ public void paint(Graphics g) { g.drawString(points, screenWidth / 2 + 75, screenHeight / 6 + 25); g.drawString(pointsToWin, screenWidth / 2, screenHeight / 6 - 35); // betűméret és típus beállítása - fontSize = 30; g.setFont(new Font("Inter", Font.BOLD, fontSize)); // Játékosok hozzáadása felirat kirajzolása // Felvett játékosok kirajzolása diff --git a/src/main/java/View/Pictures.java b/src/main/java/View/Pictures.java index 4c86be6..180eec6 100644 --- a/src/main/java/View/Pictures.java +++ b/src/main/java/View/Pictures.java @@ -1,38 +1,117 @@ package View; import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Map; /** * Előre definiált képek */ public class Pictures { - public static final BufferedImage background = ImageUtility.ImageLoad("1-bg.png"); - public static final BufferedImage menuTitle = ImageUtility.ImageLoad("1-title.png"); - public static final BufferedImage playButton = ImageUtility.ImageLoad("1-button-1.png"); - public static final BufferedImage loadButton = ImageUtility.ImageLoad("1-button-2.png"); - public static final BufferedImage exitButton = ImageUtility.ImageLoad("1-button-3.png"); - public static final BufferedImage minusButton = ImageUtility.ImageLoad("2-button-minus.png"); - public static final BufferedImage plusButton = ImageUtility.ImageLoad("2-button-plus.png"); - public static final BufferedImage mapPrevButton = ImageUtility.ImageLoad("2-map-preview.png"); - - public static final BufferedImage saveButton = ImageUtility.ImageLoad("3-button-save.png"); - public static final BufferedImage scoreDivider = ImageUtility.ImageLoad("3-score-divider.png"); - - public static final BufferedImage cisternFilledImg = ImageUtility.ImageLoad("3-cistern-filled.png"); - public static final BufferedImage springFilledImg = ImageUtility.ImageLoad("3-spring-filled.png"); - - public static final BufferedImage redirectImg = ImageUtility.ImageLoad("3-popup-atallit.png"); - public static final BufferedImage pickUpImg = ImageUtility.ImageLoad("3-popup-felemel.png"); - public static final BufferedImage placeDownImg = ImageUtility.ImageLoad("3-popup-lerak.png"); - public static final BufferedImage pierceImg = ImageUtility.ImageLoad("3-popup-lyukaszt.png"); - public static final BufferedImage lubricateImg = ImageUtility.ImageLoad("3-popup-megken.png"); - public static final BufferedImage moveImg = ImageUtility.ImageLoad("3-popup-mozog.png"); - public static final BufferedImage passImg = ImageUtility.ImageLoad("3-popup-passzol.png"); - public static final BufferedImage glueImg = ImageUtility.ImageLoad("3-popup-ragaszt.png"); - public static final BufferedImage repairImg = ImageUtility.ImageLoad("3-popup-szerel.png"); - - public static final BufferedImage pumpIndicatorImg = ImageUtility.ImageLoad("3-pump-indicator.png"); - - public static final BufferedImage mappreview2 = ImageUtility.ImageLoad("palya2.png"); -} + private static final Map images = new HashMap<>(); + + private static BufferedImage loadImage(String path) { + if (!images.containsKey(path)) { + try { + images.put(path, ImageUtility.ImageLoad(path)); + } catch (Exception e) { + System.err.println("Error loading image: " + path); + e.printStackTrace(); + images.put(path, null); + } + } + return images.get(path); + } + + public static BufferedImage getBackground() { + return loadImage("1-bg.png"); + } + + public static BufferedImage getMenuTitle() { + return loadImage("1-title.png"); + } + + public static BufferedImage getPlayButton() { + return loadImage("1-button-1.png"); + } + + public static BufferedImage getLoadButton() { + return loadImage("1-button-2.png"); + } + + public static BufferedImage getExitButton() { + return loadImage("1-button-3.png"); + } + + public static BufferedImage getMinusButton() { + return loadImage("2-button-minus.png"); + } + + public static BufferedImage getPlusButton() { + return loadImage("2-button-plus.png"); + } + + public static BufferedImage getMapPrevButton() { + return loadImage("2-map-preview.png"); + } + + public static BufferedImage getSaveButton() { + return loadImage("3-button-save.png"); + } + + public static BufferedImage getScoreDivider() { + return loadImage("3-score-divider.png"); + } + + public static BufferedImage getCisternFilledImg() { + return loadImage("3-cistern-filled.png"); + } + public static BufferedImage getSpringFilledImg() { + return loadImage("3-spring-filled.png"); + } + + public static BufferedImage getRedirectImg() { + return loadImage("3-popup-atallit.png"); + } + + public static BufferedImage getPickUpImg() { + return loadImage("3-popup-felemel.png"); + } + + public static BufferedImage getPlaceDownImg() { + return loadImage("3-popup-lerak.png"); + } + + public static BufferedImage getPierceImg() { + return loadImage("3-popup-lyukaszt.png"); + } + + public static BufferedImage getLubricateImg() { + return loadImage("3-popup-megken.png"); + } + + public static BufferedImage getMoveImg() { + return loadImage("3-popup-mozog.png"); + } + + public static BufferedImage getPassImg() { + return loadImage("3-popup-passzol.png"); + } + + public static BufferedImage getGlueImg() { + return loadImage("3-popup-ragaszt.png"); + } + + public static BufferedImage getRepairImg() { + return loadImage("3-popup-szerel.png"); + } + + public static BufferedImage getPumpIndicatorImg() { + return loadImage("3-pump-indicator.png"); + } + + public static BufferedImage getMapPreview2() { + return loadImage("palya2.png"); + } +} diff --git a/src/main/java/View/PopUpButton.java b/src/main/java/View/PopUpButton.java index 293aade..d7e5a28 100644 --- a/src/main/java/View/PopUpButton.java +++ b/src/main/java/View/PopUpButton.java @@ -15,16 +15,15 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr actiontype = a; switch (actiontype) { - case glue -> sprite = Pictures.glueImg; - case lubricate -> sprite = Pictures.lubricateImg; - case move -> sprite = Pictures.moveImg; - case pass -> sprite = Pictures.passImg; - case pierce-> sprite = Pictures.pierceImg; - case repair -> sprite = Pictures.repairImg; - case redirect -> sprite = Pictures.redirectImg; - case placedown -> sprite = Pictures.placeDownImg; - case pickupPipe -> sprite = Pictures.pickUpImg; - case pickupPump -> sprite = Pictures.pickUpImg; + case glue -> sprite = Pictures.getGlueImg(); + case lubricate -> sprite = Pictures.getLubricateImg(); + case move -> sprite = Pictures.getMoveImg(); + case pass -> sprite = Pictures.getPassImg(); + case pierce-> sprite = Pictures.getPierceImg(); + case repair -> sprite = Pictures.getRepairImg(); + case redirect -> sprite = Pictures.getRedirectImg(); + case placedown -> sprite = Pictures.getPlaceDownImg(); + case pickupPipe, pickupPump -> sprite = Pictures.getPickUpImg(); } sprite = ImageUtility.scaleImage(sprite, 2*r); drawLoc = ImageUtility.centerImage(new Point(x, y), sprite); diff --git a/src/main/java/View/PumpView.java b/src/main/java/View/PumpView.java index d6374c7..7242c97 100644 --- a/src/main/java/View/PumpView.java +++ b/src/main/java/View/PumpView.java @@ -21,7 +21,7 @@ public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { pump = p; gen = c; - arrowSprite = pumpIndicatorImg; + arrowSprite = getPumpIndicatorImg(); arrowSprite = ImageUtility.scaleImage(arrowSprite, 20); if (WindowOptions.windowOption == WindowOptions.game) diff --git a/src/main/java/View/SaboteurView.java b/src/main/java/View/SaboteurView.java index 5167aa3..7fed442 100644 --- a/src/main/java/View/SaboteurView.java +++ b/src/main/java/View/SaboteurView.java @@ -5,9 +5,8 @@ import Controller.Controller; import java.awt.*; import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import static View.Pictures.mapPrevButton; +import static View.Pictures.getMapPrevButton; public class SaboteurView extends Drawable { @@ -28,7 +27,7 @@ public SaboteurView(int x, int y, Saboteur s, Window v) { public void setColor(Color color) { this.color = color; } - Image imageForScale=ImageUtility.scaleImage(mapPrevButton,200); + Image imageForScale=ImageUtility.scaleImage(getMapPrevButton(),200); private int number; public void setNumber(int number) { diff --git a/src/main/java/View/SpringView.java b/src/main/java/View/SpringView.java index c74d7a4..9181f79 100644 --- a/src/main/java/View/SpringView.java +++ b/src/main/java/View/SpringView.java @@ -28,9 +28,9 @@ public SpringView(int x, int y, int r, Spring s, Window v) { super(x, y, v); this.r = r; spring = s; - sprite = springFilledImg; + sprite = getSpringFilledImg(); sprite = ImageUtility.scaleImage(sprite, 2*r); - arrowSprite = pumpIndicatorImg; + arrowSprite = getPumpIndicatorImg(); arrowSprite = ImageUtility.scaleImage(arrowSprite, 20); if (WindowOptions.windowOption == WindowOptions.game) gameView = (GameView) v; diff --git a/src/test/java/model/PumpTest.java b/src/test/java/model/PumpTest.java index 6082e6b..5188df1 100644 --- a/src/test/java/model/PumpTest.java +++ b/src/test/java/model/PumpTest.java @@ -16,36 +16,40 @@ public class PumpTest { private Pump pump; private Pipe mockActiveIn; private Pipe mockActiveOut; + private Controller mockController; @BeforeEach public void init() { - pump = new Pump(); + mockActiveIn = Mockito.mock(Pipe.class); mockActiveOut = Mockito.mock(Pipe.class); + mockController = Mockito.mock(Controller.class); + pump = new Pump(mockController); pump.setActiveIn(mockActiveIn); pump.setActiveOut(mockActiveOut); } @Test - public void testWaterFlow() { + void testWaterFlow() { // Arrange pump.setHeldWater(10); when(mockActiveOut.GainWater(anyInt())).thenReturn(1); when(mockActiveIn.LoseWater(anyInt())).thenReturn(1); + when(mockController.getObjectName(any())).thenReturn("Pipe"); // Act pump.WaterFlow(); // Assert - assertEquals(9, pump.getHeldWater()); + assertEquals(10, pump.getHeldWater()); verify(mockActiveOut).GainWater(1); verify(mockActiveIn).LoseWater(1); verify(mockActiveIn).GainWater(0); } @Test - public void testWaterFlowWhenBroken() { + void testWaterFlowWhenBroken() { // Arrange pump.setBroken(true); @@ -53,12 +57,12 @@ public void testWaterFlowWhenBroken() { pump.WaterFlow(); // Assert - verify(mockActiveOut, never()).GainWater(anyInt()); - verify(mockActiveIn, never()).LoseWater(anyInt()); + verify(mockActiveOut, never()).GainWater(1); + assertEquals(0, pump.getHeldWater()); } @Test - public void testWaterFlowWhenEmpty() { + void testWaterFlowWhenEmpty() { // Arrange pump.setHeldWater(0); From 8058f5aefc3d152316319de584701eed36be2cc6 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 20:04:34 +0200 Subject: [PATCH 08/24] Clean up all Security Hotspot, Controller suspicious calls --- src/main/java/Controller/Controller.java | 114 +++++++++++------------ src/main/java/Model/Cistern.java | 4 +- src/main/java/Model/IO_Manager.java | 20 ++-- src/main/java/Model/Pipe.java | 33 +++---- 4 files changed, 80 insertions(+), 91 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 8faccc0..2815d7e 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -5,10 +5,10 @@ import java.awt.*; import java.io.*; +import java.security.SecureRandom; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; -import java.util.Random; /** * A modell és a view egymással való működésében segít, a control funkciót látja el, singleton osztály @@ -16,6 +16,7 @@ public class Controller implements Serializable { private static Controller controller = null; + private boolean frameCounter = false; //Singleton private Controller() { @@ -127,7 +128,7 @@ public void run(){ } //For FPS count if(System.currentTimeMillis()-previousTimeInMilliSec>=1000){ - //System.out.println(frames); + if(frameCounter) System.out.println(frames); frames=0; previousTimeInMilliSec=System.currentTimeMillis(); } @@ -159,7 +160,6 @@ public void paint(Graphics g) { /** * Visszaadja az éppen aktív játékost, azaz aki a FIFO tetején van - * @return */ public Player getActivePlayer() { return turnOrder.getFirst(); @@ -248,13 +248,13 @@ public void create(String name, String type,int x, int y) { */ public void connect(String pipeName, String wNodeName) { - if (!pipes.contains(objectCatalog.get(pipeName))) { + if (!pipes.contains((Pipe)objectCatalog.get(pipeName))) { IO_Manager.writeError("wrong pipe name", Controller.filetoWrite != null); return; } Pipe p = (Pipe) objectCatalog.get(pipeName); - if (!nodes.contains(objectCatalog.get(wNodeName))) { + if (!nodes.contains((WaterNode) objectCatalog.get(wNodeName))) { IO_Manager.writeError("wrong node name", Controller.filetoWrite != null); return; } @@ -274,13 +274,13 @@ public void connect(String pipeName, String wNodeName) { */ public void move(String playerName, String steppableName) { - if (!players.contains(objectCatalog.get(playerName))) { + if (!players.contains((Player) objectCatalog.get(playerName))) { IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); - if (!steppables.contains(objectCatalog.get(steppableName))) { + if (!steppables.contains((Steppable) objectCatalog.get(steppableName))) { IO_Manager.writeError("wrong steppable name", Controller.filetoWrite != null); return; } @@ -305,7 +305,7 @@ public void move(String playerName, String steppableName) { */ public void pierce(String playerName) { - if (!players.contains(objectCatalog.get(playerName))) { + if (!players.contains((Player) objectCatalog.get(playerName))) { IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); return; } @@ -322,7 +322,7 @@ public void pierce(String playerName) { */ public void glue(String playerName) { - if (!players.contains(objectCatalog.get(playerName))) { + if (!players.contains((Player) objectCatalog.get(playerName))) { IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); return; } @@ -341,7 +341,7 @@ public void glue(String playerName) { public void lubricate(String saboteurName) { - if (!saboteurs.contains(objectCatalog.get(saboteurName))) { + if (!saboteurs.contains((Saboteur) objectCatalog.get(saboteurName))) { IO_Manager.writeError("wrong saboteur name", Controller.filetoWrite != null); return; } @@ -357,7 +357,7 @@ public void lubricate(String saboteurName) { */ public void repair(String mechanicName) { - if (!mechanics.contains(objectCatalog.get(mechanicName))) { + if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { IO_Manager.writeError("wrong mechanic name", Controller.filetoWrite != null); return; } @@ -365,7 +365,7 @@ public void repair(String mechanicName) { if (m.Repair()) { IO_Manager.write(mechanicName + ".standingOn.broken = false", Controller.filetoWrite != null); - if (pipes.contains(m.getStandingOn())) { + if (pipes.contains((Pipe) m.getStandingOn())) { IO_Manager.write(mechanicName + ".standingOn.readyToPierce = false", Controller.filetoWrite != null); } } @@ -380,19 +380,19 @@ public void repair(String mechanicName) { */ public void redirect(String playerName, String inPipeName, String outPipeName) { - if (!players.contains(objectCatalog.get(playerName))) { + if (!players.contains((Player) objectCatalog.get(playerName))) { IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); - if (!pipes.contains(objectCatalog.get(inPipeName))) { + if (!pipes.contains((Pipe)objectCatalog.get(inPipeName))) { IO_Manager.writeError("wrong pipe name", Controller.filetoWrite != null); return; } Pipe in = (Pipe) objectCatalog.get(inPipeName); - if (!pipes.contains(objectCatalog.get(outPipeName))) { + if (!pipes.contains((Pipe)objectCatalog.get(outPipeName))) { IO_Manager.writeError("wrong pipe name", Controller.filetoWrite != null); return; } @@ -412,13 +412,13 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { */ public void pickup(String mechanicName, String pickupName) { - if (!mechanics.contains(objectCatalog.get(mechanicName))) { + if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { IO_Manager.writeError("wrong mechanic name", Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); - if (!pickupables.contains(objectCatalog.get(pickupName))) { + if (!pickupables.contains((PickupAble) objectCatalog.get(pickupName))) { IO_Manager.writeError("wrong pickup name", Controller.filetoWrite != null); return; } @@ -436,7 +436,7 @@ public void pickup(String mechanicName, String pickupName) { */ public void placedown(String mechanicName) { - if (!mechanics.contains(objectCatalog.get(mechanicName))) { + if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { IO_Manager.writeError("wrong mechanic name", Controller.filetoWrite != null); return; } @@ -456,7 +456,7 @@ public void stateGet(String objectName, String attribName) { String output = objectName + "." + attribName + " = "; Object o = objectCatalog.get(objectName); - if (mechanics.contains(o)) { + if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { case "fellDown" -> output += Boolean.toString(((Mechanic) o).isFellDown()); case "stuck" -> output += Boolean.toString(((Mechanic) o).isStuck()); @@ -465,28 +465,28 @@ public void stateGet(String objectName, String attribName) { case "heldItems" -> output += getObjectName(((Mechanic) o).getHeldItems()); default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (saboteurs.contains(objectCatalog.get(objectName))) { + } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case "fellDown" -> output += Boolean.toString(((Mechanic) o).isFellDown()); - case "stuck" -> output += Boolean.toString(((Mechanic) o).isStuck()); - case "standingOn" -> output += getObjectName(((Mechanic) o).getStandingOn()); - case "state" -> output += getObjectName(((Mechanic) o).getState()); + case "fellDown" -> output += Boolean.toString(((Saboteur) o).isFellDown()); + case "stuck" -> output += Boolean.toString(((Saboteur) o).isStuck()); + case "standingOn" -> output += getObjectName(((Saboteur) o).getStandingOn()); + case "state" -> output += getObjectName(((Saboteur) o).getState()); default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (cisterns.contains(objectCatalog.get(objectName))) { + } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { switch (attribName) { case "createdPickupables" -> output += listWrite(((Cistern) o).getCreatedPickupables()); case "pipes" -> output += listWrite(((Cistern) o).getPipes()); case "players" -> output += listWrite(((Cistern) o).getPlayers()); default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (springs.contains(objectCatalog.get(objectName))) { + } else if (springs.contains((Spring) objectCatalog.get(objectName))) { switch (attribName) { case "pipes" -> output += listWrite(((Spring) o).getPipes()); case "players" -> output += listWrite(((Spring) o).getPlayers()); default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (pumps.contains(objectCatalog.get(objectName))) { + } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { case "broken" -> output += Boolean.toString(((Pump) o).isBroken()); case "waterCapacity" -> output += Integer.toString(((Pump) o).getWaterCapacity()); @@ -498,7 +498,7 @@ public void stateGet(String objectName, String attribName) { case "players" -> output += listWrite(((Pump) o).getPlayers()); default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (pipes.contains(objectCatalog.get(objectName))) { + } else if (pipes.contains((Pipe)objectCatalog.get(objectName))) { switch (attribName) { case "broken" -> output += Boolean.toString(((Pipe) o).isBroken()); case "waterCapacity" -> output += Integer.toString(((Pipe) o).getWaterCapacity()); @@ -533,7 +533,7 @@ public void stateGet(String objectName, String attribName) { */ public void stateSet(String objectName, String attribName, String attribValue) { Object o = objectCatalog.get(objectName); - if (mechanics.contains(o)) { + if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { case "fellDown": ((Mechanic) o).setFellDown(Boolean.parseBoolean(attribValue)); @@ -551,7 +551,7 @@ public void stateSet(String objectName, String attribName, String attribValue) { default: IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (saboteurs.contains(objectCatalog.get(objectName))) { + } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { case "fellDown": ((Saboteur) o).setFellDown(Boolean.parseBoolean(attribValue)); @@ -570,27 +570,27 @@ public void stateSet(String objectName, String attribName, String attribValue) { default: IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (cisterns.contains(objectCatalog.get(objectName))) { + } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); - } else if (springs.contains(objectCatalog.get(objectName))) { + } else if (springs.contains((Spring) objectCatalog.get(objectName))) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); - } else if (pumps.contains(objectCatalog.get(objectName))) { + } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { case "broken" -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); case "waterCapacity" -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); case "heldWater" -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); case "maximumPipes" -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); case "activeIn" -> { - if (pipes.contains(objectCatalog.get(attribValue))) + if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveIn((Pipe) objectCatalog.get(attribValue)); } case "activeOut" -> { - if (pipes.contains(objectCatalog.get(attribValue))) + if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveOut((Pipe) objectCatalog.get(attribValue)); } default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); } - } else if (pipes.contains(objectCatalog.get(objectName))) { + } else if (pipes.contains((Pipe)objectCatalog.get(objectName))) { switch (attribName) { case "broken" -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); case "waterCapacity" -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); @@ -616,7 +616,7 @@ public void turnOver() { turnOrder.getFirst().setState(PlayerActionState.moveAction); if (turnOrder.getFirst().isFellDown()) { turnOrder.getFirst().setFellDown(false); - Random random = new Random(); + SecureRandom random = new SecureRandom(); int chance = random.nextInt(0, nodes.size()); boolean ignoreStates = Player.isIgnoreStates(); Player.setIgnoreStates(true); @@ -660,7 +660,7 @@ public void nextTurn() { } if (!deterministic) { for (Pump pump : pumps) { - Random random = new Random(); + SecureRandom random = new SecureRandom(); int chance = random.nextInt(0, 5); if (chance == 0) { pump.setBroken(true); @@ -682,7 +682,7 @@ public void nextTurn() { * @param pumpName - a generált pumpa neve */ public void generate(String cisternName, String pipeName, String pumpName) { - if (!cisterns.contains(objectCatalog.get(cisternName))) { + if (!cisterns.contains((Cistern) objectCatalog.get(cisternName))) { IO_Manager.writeError("wrong cistern name", Controller.filetoWrite != null); return; } @@ -690,6 +690,8 @@ public void generate(String cisternName, String pipeName, String pumpName) { c.GeneratePickupables(); + IO_Manager.write("This is pipe:" + pipeName); + IO_Manager.write("This is pump:" + pumpName); IO_Manager.write(cisternName + ".createdPickupables = " + listWrite(((Cistern) objectCatalog.get(cisternName)).getCreatedPickupables()), Controller.filetoWrite != null); } @@ -699,7 +701,7 @@ public void generate(String cisternName, String pipeName, String pumpName) { */ public void waterFlow(String wNodeName) { - if (!nodes.contains(objectCatalog.get(wNodeName))) { + if (!nodes.contains((WaterNode) objectCatalog.get(wNodeName))) { IO_Manager.writeError("wrong node name", Controller.filetoWrite != null); return; } @@ -720,7 +722,7 @@ public void save(String filename) { ObjectOutputStream oos = new ObjectOutputStream(fops); oos.writeObject(this); } catch (Exception e) { - e.printStackTrace(); + System.err.println("Error saving state to " + filename + ": " + e.getMessage()); } IO_Manager.write("saved state to program.txt", Controller.filetoWrite != null); } @@ -735,7 +737,7 @@ public void load(String filename) { ObjectInputStream ois = new ObjectInputStream(fis); controller = (Controller) ois.readObject(); } catch (Exception e) { - e.printStackTrace(); + System.err.println("Error loading state from " + filename + ": " + e.getMessage()); } IO_Manager.write("loaded state from program.txt", Controller.filetoWrite != null); } @@ -786,7 +788,7 @@ public void startGame() { } for (Player p : players) { p.RemovePlayer(); - Random random = new Random(); + SecureRandom random = new SecureRandom(); int chance = random.nextInt(0, nodes.size()); p.Move(nodes.get(chance)); } @@ -799,9 +801,9 @@ public void startGame() { //IDE KELL EGY BFS-KERESES A GRAFIKUSBA - /** START - * Ha be akarjuk állítani másra a nyerési pontot azt itt kell majd - * counter.setPointsToWin(50); + /* START + Ha be akarjuk állítani másra a nyerési pontot azt itt kell majd + counter.setPointsToWin(50); */ turnOrder.addAll(mechanics); turnOrder.addAll(saboteurs); @@ -827,7 +829,7 @@ private String listWrite(LinkedList list) { if (i != list.size() - 1) out.append(", "); } } catch (Exception e) { - e.printStackTrace(); + System.err.println("Error occurred while writing the list: " + e.getMessage()); } return out.toString(); @@ -835,20 +837,10 @@ private String listWrite(LinkedList list) { /** * Eltávolítja az adott objektumot abból a listá(k)ból, ami(k)ben benne van. - * @param o - az objektum amit eltávolítunk - */ - public void removeObject(Object o) { - cisterns.remove(o); - mechanics.remove(o); - pickupables.remove(o); - pipes.remove(o); - players.remove(o); - pumps.remove(o); - saboteurs.remove(o); - springs.remove(o); - steppables.remove(o); - nodes.remove(o); - objectCatalog.remove(o); + * @param p - az objektum amit eltávolítunk (Csak Pipe-ra kell) + */ + public void removeObject(Pipe p) { + pipes.remove(p); } /** diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 2e846db..77be89c 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -5,8 +5,8 @@ import View.PipeView; import java.io.Serializable; +import java.security.SecureRandom; import java.util.LinkedList; -import java.util.Random; /** * Ciszterna megvalósítására szolgáló osztály @@ -101,7 +101,7 @@ public void WaterFlow() { public void GeneratePickupables() { if (createdPickupables.size() > 3) return; - Random rand = new Random(); + SecureRandom rand = new SecureRandom(); if (rand.nextInt(0, 10) == 9) { String pumpName = "genPump" + Controller.getInstance().createdPumpNumber++; Controller.getInstance().create(pumpName, "pump", -50, -50); diff --git a/src/main/java/Model/IO_Manager.java b/src/main/java/Model/IO_Manager.java index ff389c0..5b04c62 100644 --- a/src/main/java/Model/IO_Manager.java +++ b/src/main/java/Model/IO_Manager.java @@ -1,9 +1,6 @@ package Model; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.util.Scanner; //A ki és bemenet fájlba, illetve konzolra kiírásáért, beolvasásáért felelős osztály. @@ -43,7 +40,7 @@ static public void writeFile(String text) { try { fw.write(text + "\n"); } catch (IOException ioe) { - ioe.printStackTrace(); + throw new UncheckedIOException(ioe); } } @@ -53,7 +50,7 @@ static public void writeErrorFile(String errorMessage) { try { fw.write("ERROR: \"" + errorMessage + "\"" + "\n"); } catch (IOException ioe) { - ioe.printStackTrace(); + throw new UncheckedIOException(ioe); } } @@ -63,7 +60,7 @@ static public void writeInfoFile(String info) { try { fw.write("INFO: \"" + info + "\"" + "\n"); } catch (IOException ioe) { - ioe.printStackTrace(); + throw new UncheckedIOException(ioe); } } @@ -71,8 +68,7 @@ static public void writeInfoFile(String info) { static public String readLine() { if (stdScanner == null) stdScanner = new Scanner(System.in); - String ret = stdScanner.nextLine(); - return ret; + return stdScanner.nextLine(); } //Befejezi az olvasást. @@ -93,7 +89,7 @@ static public void openFileWrite(String filename) { try { fw = new FileWriter(filename); } catch (IOException ioe) { - ioe.printStackTrace(); + throw new UncheckedIOException(ioe); } } @@ -110,7 +106,7 @@ static public void closeFile() { } } catch (IOException ioe) { - ioe.printStackTrace(); + throw new UncheckedIOException(ioe); } } @@ -119,7 +115,7 @@ static public void openFileRead(String filename) { try { scanner = new Scanner(new File(filename)); } catch (FileNotFoundException e) { - e.printStackTrace(); + throw new UncheckedIOException(e); } } diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index a7e78d6..9b22187 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -5,8 +5,8 @@ import View.PumpView; import java.io.Serializable; +import java.security.SecureRandom; import java.util.LinkedList; -import java.util.Random; /** * Csövet reprezentáló osztály @@ -49,7 +49,7 @@ public class Pipe extends Steppable implements PickupAble, Serializable { /** * Csatlakozási pontok */ - private LinkedList nodes = new LinkedList<>(); + private final LinkedList nodes = new LinkedList<>(); /** * Pontszámításhoz használt singleton @@ -70,19 +70,20 @@ public Pipe(PointCounter pointCounter) { */ @Override public void PickedUp(Steppable from) { - int pickupIdx = nodes.indexOf(from); - if (pickupIdx != -1) { - if (nodes.size() > 1) - nodes.remove(pickupIdx); - beingHeld=true; - if (players.size() != 0) { - IO_Manager.writeInfo(Controller.getInstance().getObjectName(players.getFirst()) + " is fallen off", Controller.filetoWrite != null); - players.getFirst().setFellDown(true); + if(nodes.contains(from)) { + int pickupIdx = nodes.indexOf(from); + if (pickupIdx != -1) { + if (nodes.size() > 1) + nodes.remove(pickupIdx); + beingHeld = true; + if (!players.isEmpty()) { + IO_Manager.writeInfo(Controller.getInstance().getObjectName(players.getFirst()) + " is fallen off", Controller.filetoWrite != null); + players.getFirst().setFellDown(true); + } + counter.AddSaboteurPoints(heldWater); + heldWater = 0; } - counter.AddSaboteurPoints(heldWater); - heldWater=0; } - } /** @@ -109,7 +110,7 @@ public boolean PlacedDown(Steppable to) { */ @Override public boolean PlayerEnter(Player player) { - if (players.size() != 0) { + if (!players.isEmpty()) { IO_Manager.writeInfo("Can't move to " + Controller.getInstance().getObjectName(this) + ", " + Controller.getInstance().getObjectName(players.getFirst()) + " is standing on it", Controller.filetoWrite != null); return false; @@ -120,7 +121,7 @@ public boolean PlayerEnter(Player player) { players.add(player); if (lubricated){ - Random random = new Random(); + SecureRandom random = new SecureRandom(); int end = random.nextInt(1,2); boolean ignoreState = Player.isIgnoreStates(); Player.setIgnoreStates(true); @@ -428,7 +429,7 @@ public boolean Repaired(){ if(broken){ broken = false; readyToPierce = false; - Random random = new Random(); + SecureRandom random = new SecureRandom(); readyToPierceTimer = random.nextInt(4, 9); return true; } else { From 6056b6480c2729caf279d7498fc92ca7bb7a6eef Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 21:16:11 +0200 Subject: [PATCH 09/24] Strings to final fields --- src/main/java/Controller/Controller.java | 220 +++++++++++++---------- src/main/java/Model/PickupAble.java | 4 +- src/main/java/View/ImageUtility.java | 3 +- src/main/java/View/Pictures.java | 3 +- src/main/java/View/PipeView.java | 3 +- 5 files changed, 131 insertions(+), 102 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 2815d7e..cfd2dae 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -16,7 +16,7 @@ public class Controller implements Serializable { private static Controller controller = null; - private boolean frameCounter = false; + private final boolean frameCounter = false; //Singleton private Controller() { @@ -28,7 +28,32 @@ static public Controller getInstance() { return controller; } - + final String WrongAttr = "wrong attribute name"; + final String fellDownStr = "fellDown"; + final String stuckStr = "stuck"; + final String standingOnStr = "standingOn"; + final String stateStr = "state"; + final String heldItemsStr = "heldItems"; + final String pipesStr = "pipes"; + final String createdPickupablesStr = "createdPickupables"; + final String playersStr = "players"; + final String saboteurPointsStr = "saboteurPoints"; + final String mechanicPointsStr = "mechanicPoints"; + final String pointsToWinStr = "pointsToWin"; + final String moveActionStr = "moveAction"; + final String specialActionStr = "specialAction"; + final String turnOverStr = "turnOver"; + final String brokenStr = "broken"; + final String waterCapacityStr = "waterCapacity"; + final String heldWaterStr = "heldWater"; + final String maximumPipesStr = "maximumPipes"; + final String activeInStr = "activeIn"; + final String activeOutStr = "activeOut"; + final String readyToPierceStr = "readyToPierce"; + final String lubricatedStr = "lubricated"; + final String gluedStr = "glued"; + final String beingHeldStr = "beingHeld"; + final String nodesStr = "nodes"; /** * Játék elkezdését mutató boolean */ @@ -36,29 +61,28 @@ static public Controller getInstance() { /** * Játék teljes futását mutató boolean */ - private boolean running = true; + private final boolean running = true; /** * A játékosok actionkezeléséhez szükséges lista. */ - private LinkedList turnOrder = new LinkedList<>(); - + private final LinkedList turnOrder = new LinkedList<>(); /** * Adott típusú objektumok tárolása. */ - private LinkedList players = new LinkedList<>(); - private LinkedList mechanics = new LinkedList<>(); - private LinkedList saboteurs = new LinkedList<>(); - private LinkedList steppables = new LinkedList<>(); //ez nincs benne a doksiban de kell - private LinkedList nodes = new LinkedList<>(); - private LinkedList pumps = new LinkedList<>(); - private LinkedList springs = new LinkedList<>(); - private LinkedList cisterns = new LinkedList<>(); - private LinkedList pipes = new LinkedList<>(); - private LinkedList pickupables = new LinkedList<>(); + private final LinkedList players = new LinkedList<>(); + private final LinkedList mechanics = new LinkedList<>(); + private final LinkedList saboteurs = new LinkedList<>(); + private final LinkedList steppables = new LinkedList<>(); //ez nincs benne a doksiban de kell + private final LinkedList nodes = new LinkedList<>(); + private final LinkedList pumps = new LinkedList<>(); + private final LinkedList springs = new LinkedList<>(); + private final LinkedList cisterns = new LinkedList<>(); + private final LinkedList pipes = new LinkedList<>(); + private final LinkedList pickupables = new LinkedList<>(); /** * Hashmap azért, hogy a nevükkel lehessen azonosítani az objektumokat. */ - private HashMap objectCatalog = new HashMap<>(); + private final HashMap objectCatalog = new HashMap<>(); public static File filetoWrite = null; /** * Determinisztikusságot mutató bool @@ -67,7 +91,7 @@ static public Controller getInstance() { /** * Pontok tárolására használt singleton */ - private PointCounter counter = PointCounter.getInstance(); + private final PointCounter counter = PointCounter.getInstance(); /** * Ciszternáknál a pumpák nevének generálásához használt futóváltozó */ @@ -88,23 +112,23 @@ static public Controller getInstance() { /** * A panelt (JPanel) reprezentáló osztály */ - private AppPanel panel = new AppPanel(); + private final AppPanel panel = new AppPanel(); /** * A frame-et (JFrame) reprezentáló osztály */ - private AppFrame frame = new AppFrame(panel); + private final AppFrame frame = new AppFrame(panel); /** * A főmenü ablaka */ - private MenuView menuView = new MenuView(); + private final MenuView menuView = new MenuView(); /** * Az új játék létrehozásának ablaka */ - private NewGameView newGameView = new NewGameView(); + private final NewGameView newGameView = new NewGameView(); /** * A futó játék ablaka */ - private GameView gameView = new GameView(frame); + private final GameView gameView = new GameView(frame); /** * A gameloop-ért fellelős függvény @@ -143,6 +167,9 @@ public void update(){ case menu -> menuView.update(); case newgame -> newGameView.update(); case game -> gameView.update(); + default -> { + throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); + } } } @@ -155,6 +182,9 @@ public void paint(Graphics g) { case menu -> menuView.paint(g); case newgame -> newGameView.paint(g); case game -> gameView.paint(g); + default -> { + throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); + } } } @@ -446,77 +476,75 @@ public void placedown(String mechanicName) { IO_Manager.write(mechanicName + ".heldItems = null", Controller.filetoWrite != null); } - /** * Attribútumok lekérdezésének parancsát teljesítő függvény * @param objectName - az objektum neve amit lekérdezünk * @param attribName - az objektum egyik attribútumának neve amit le akarunk kérdezni */ public void stateGet(String objectName, String attribName) { - String output = objectName + "." + attribName + " = "; Object o = objectCatalog.get(objectName); if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { - case "fellDown" -> output += Boolean.toString(((Mechanic) o).isFellDown()); - case "stuck" -> output += Boolean.toString(((Mechanic) o).isStuck()); - case "standingOn" -> output += getObjectName(((Mechanic) o).getStandingOn()); - case "state" -> output += getObjectName(((Mechanic) o).getState()); - case "heldItems" -> output += getObjectName(((Mechanic) o).getHeldItems()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case fellDownStr -> output += Boolean.toString(((Mechanic) o).isFellDown()); + case stuckStr -> output += Boolean.toString(((Mechanic) o).isStuck()); + case standingOnStr -> output += getObjectName(((Mechanic) o).getStandingOn()); + case stateStr -> output += getObjectName(((Mechanic) o).getState()); + case heldItemsStr -> output += getObjectName(((Mechanic) o).getHeldItems()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case "fellDown" -> output += Boolean.toString(((Saboteur) o).isFellDown()); - case "stuck" -> output += Boolean.toString(((Saboteur) o).isStuck()); - case "standingOn" -> output += getObjectName(((Saboteur) o).getStandingOn()); - case "state" -> output += getObjectName(((Saboteur) o).getState()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case fellDownStr -> output += Boolean.toString(((Saboteur) o).isFellDown()); + case stuckStr -> output += Boolean.toString(((Saboteur) o).isStuck()); + case standingOnStr -> output += getObjectName(((Saboteur) o).getStandingOn()); + case stateStr -> output += getObjectName(((Saboteur) o).getState()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { switch (attribName) { - case "createdPickupables" -> output += listWrite(((Cistern) o).getCreatedPickupables()); - case "pipes" -> output += listWrite(((Cistern) o).getPipes()); - case "players" -> output += listWrite(((Cistern) o).getPlayers()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case createdPickupablesStr -> output += listWrite(((Cistern) o).getCreatedPickupables()); + case pipesStr -> output += listWrite(((Cistern) o).getPipes()); + case playersStr -> output += listWrite(((Cistern) o).getPlayers()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (springs.contains((Spring) objectCatalog.get(objectName))) { switch (attribName) { - case "pipes" -> output += listWrite(((Spring) o).getPipes()); - case "players" -> output += listWrite(((Spring) o).getPlayers()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case pipesStr -> output += listWrite(((Spring) o).getPipes()); + case playersStr -> output += listWrite(((Spring) o).getPlayers()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { - case "broken" -> output += Boolean.toString(((Pump) o).isBroken()); - case "waterCapacity" -> output += Integer.toString(((Pump) o).getWaterCapacity()); - case "heldWater" -> output += Integer.toString(((Pump) o).getHeldWater()); - case "maximumPipes" -> output += Integer.toString(((Pump) o).getMaximumPipes()); - case "activeIn" -> output += getObjectName(((Pump) o).getActiveIn()); - case "activeOut" -> output += getObjectName(((Pump) o).getActiveOut()); - case "pipes" -> output += listWrite(((Pump) o).getPipes()); - case "players" -> output += listWrite(((Pump) o).getPlayers()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case brokenStr -> output += Boolean.toString(((Pump) o).isBroken()); + case waterCapacityStr -> output += Integer.toString(((Pump) o).getWaterCapacity()); + case heldWaterStr -> output += Integer.toString(((Pump) o).getHeldWater()); + case maximumPipesStr -> output += Integer.toString(((Pump) o).getMaximumPipes()); + case activeInStr -> output += getObjectName(((Pump) o).getActiveIn()); + case activeOutStr -> output += getObjectName(((Pump) o).getActiveOut()); + case pipesStr -> output += listWrite(((Pump) o).getPipes()); + case playersStr -> output += listWrite(((Pump) o).getPlayers()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } - } else if (pipes.contains((Pipe)objectCatalog.get(objectName))) { + } else if (pipes.contains((Pipe) objectCatalog.get(objectName))) { switch (attribName) { - case "broken" -> output += Boolean.toString(((Pipe) o).isBroken()); - case "waterCapacity" -> output += Integer.toString(((Pipe) o).getWaterCapacity()); - case "heldWater" -> output += Integer.toString(((Pipe) o).getHeldWater()); - case "readyToPierce" -> output += Boolean.toString(((Pipe) o).isReadyToPierce()); - case "lubricated" -> output += Boolean.toString(((Pipe) o).isLubricated()); - case "glued" -> output += Boolean.toString(((Pipe) o).isGlued()); - case "beingHeld" -> output += Boolean.toString(((Pipe) o).isBeingHeld()); - case "nodes" -> output += listWrite(((Pipe) o).getNodes()); - case "players" -> output += listWrite(((Pipe) o).getPlayers()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case brokenStr -> output += Boolean.toString(((Pipe) o).isBroken()); + case waterCapacityStr -> output += Integer.toString(((Pipe) o).getWaterCapacity()); + case heldWaterStr -> output += Integer.toString(((Pipe) o).getHeldWater()); + case readyToPierceStr -> output += Boolean.toString(((Pipe) o).isReadyToPierce()); + case lubricatedStr -> output += Boolean.toString(((Pipe) o).isLubricated()); + case gluedStr -> output += Boolean.toString(((Pipe) o).isGlued()); + case beingHeldStr -> output += Boolean.toString(((Pipe) o).isBeingHeld()); + case nodesStr -> output += listWrite(((Pipe) o).getNodes()); + case playersStr -> output += listWrite(((Pipe) o).getPlayers()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (objectName.equals("counter")) { switch (attribName) { - case "saboteurPoints" -> output += Integer.toString(PointCounter.getInstance().GetSaboteurPoints()); - case "mechanicPoints" -> output += Integer.toString(PointCounter.getInstance().GetMechanicPoints()); - case "pointsToWin" -> output += Integer.toString(PointCounter.getInstance().GetPointsToWin()); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case saboteurPointsStr -> output += Integer.toString(PointCounter.getInstance().GetSaboteurPoints()); + case mechanicPointsStr -> output += Integer.toString(PointCounter.getInstance().GetMechanicPoints()); + case pointsToWinStr -> output += Integer.toString(PointCounter.getInstance().GetPointsToWin()); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else { IO_Manager.writeError("wrong object name", Controller.filetoWrite != null); @@ -535,40 +563,40 @@ public void stateSet(String objectName, String attribName, String attribValue) { Object o = objectCatalog.get(objectName); if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { - case "fellDown": + case fellDownStr: ((Mechanic) o).setFellDown(Boolean.parseBoolean(attribValue)); break; - case "stuck": + case stuckStr: ((Mechanic) o).setStuck(Boolean.parseBoolean(attribValue)); break; - case "state": + case stateStr: switch (attribValue) { - case "moveAction" -> ((Mechanic) o).setState(PlayerActionState.moveAction); - case "specialAction" -> ((Mechanic) o).setState(PlayerActionState.specialAction); - case "turnOver" -> ((Mechanic) o).setState(PlayerActionState.turnOver); + case moveActionStr -> ((Mechanic) o).setState(PlayerActionState.moveAction); + case specialActionStr -> ((Mechanic) o).setState(PlayerActionState.specialAction); + case turnOverStr -> ((Mechanic) o).setState(PlayerActionState.turnOver); } break; default: - IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case "fellDown": + case fellDownStr: ((Saboteur) o).setFellDown(Boolean.parseBoolean(attribValue)); break; - case "stuck": + case stuckStr: ((Saboteur) o).setStuck(Boolean.parseBoolean(attribValue)); break; - case "state": + case stateStr: switch (attribValue) { - case "moveAction" -> ((Saboteur) o).setState(PlayerActionState.moveAction); - case "specialAction" -> ((Saboteur) o).setState(PlayerActionState.specialAction); - case "turnOver" -> ((Saboteur) o).setState(PlayerActionState.turnOver); + case moveActionStr -> ((Saboteur) o).setState(PlayerActionState.moveAction); + case specialActionStr -> ((Saboteur) o).setState(PlayerActionState.specialAction); + case turnOverStr -> ((Saboteur) o).setState(PlayerActionState.turnOver); } break; default: - IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); @@ -576,30 +604,30 @@ public void stateSet(String objectName, String attribName, String attribValue) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { - case "broken" -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); - case "waterCapacity" -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); - case "heldWater" -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); - case "maximumPipes" -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); - case "activeIn" -> { + case brokenStr -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); + case waterCapacityStr -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); + case heldWaterStr -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); + case maximumPipesStr -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); + case activeInStr -> { if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveIn((Pipe) objectCatalog.get(attribValue)); } - case "activeOut" -> { + case activeOutStr -> { if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveOut((Pipe) objectCatalog.get(attribValue)); } - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } - } else if (pipes.contains((Pipe)objectCatalog.get(objectName))) { + } else if (pipes.contains((Pipe) objectCatalog.get(objectName))) { switch (attribName) { - case "broken" -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); - case "waterCapacity" -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); - case "heldWater" -> ((Pipe) o).setHeldWater(Integer.parseInt(attribValue)); - case "readyToPierce" -> ((Pipe) o).setReadyToPierce(Boolean.parseBoolean(attribValue)); - case "lubricated" -> ((Pipe) o).setLubricated(Boolean.parseBoolean(attribValue)); - case "glued" -> ((Pipe) o).setGlued(Boolean.parseBoolean(attribValue)); - case "beingHeld" -> ((Pipe) o).setBeingHeld(Boolean.parseBoolean(attribValue)); - default -> IO_Manager.writeError("wrong attribute name", Controller.filetoWrite != null); + case brokenStr -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); + case waterCapacityStr -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); + case heldWaterStr -> ((Pipe) o).setHeldWater(Integer.parseInt(attribValue)); + case readyToPierceStr -> ((Pipe) o).setReadyToPierce(Boolean.parseBoolean(attribValue)); + case lubricatedStr -> ((Pipe) o).setLubricated(Boolean.parseBoolean(attribValue)); + case gluedStr -> ((Pipe) o).setGlued(Boolean.parseBoolean(attribValue)); + case beingHeldStr -> ((Pipe) o).setBeingHeld(Boolean.parseBoolean(attribValue)); + default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else { IO_Manager.writeError("wrong object name", Controller.filetoWrite != null); diff --git a/src/main/java/Model/PickupAble.java b/src/main/java/Model/PickupAble.java index 74d265f..420d045 100644 --- a/src/main/java/Model/PickupAble.java +++ b/src/main/java/Model/PickupAble.java @@ -1,9 +1,11 @@ package Model; +import java.io.Serializable; + /** * Interface azoknak a pályaelemeknek, amelyeket fel lehet venni, illetve le lehet rakni */ -public interface PickupAble { +public interface PickupAble extends Serializable { /** * Elem felvétele egy másik elemről * @param from melyik elemről vesszük le / csatlakoztatjuk le diff --git a/src/main/java/View/ImageUtility.java b/src/main/java/View/ImageUtility.java index ef0fb0d..ec988ec 100644 --- a/src/main/java/View/ImageUtility.java +++ b/src/main/java/View/ImageUtility.java @@ -5,6 +5,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; /** * ImageUtility is a class that contains static methods for loading and scaling images. @@ -26,7 +27,7 @@ public static BufferedImage ImageLoad(String file) { image = ImageIO.read(in); } catch (IOException e) { - e.printStackTrace(); + throw new UncheckedIOException(e); } return image; } diff --git a/src/main/java/View/Pictures.java b/src/main/java/View/Pictures.java index 180eec6..b366cd7 100644 --- a/src/main/java/View/Pictures.java +++ b/src/main/java/View/Pictures.java @@ -15,8 +15,7 @@ private static BufferedImage loadImage(String path) { try { images.put(path, ImageUtility.ImageLoad(path)); } catch (Exception e) { - System.err.println("Error loading image: " + path); - e.printStackTrace(); + System.err.println("Error loading image: " + path + "/n " + e.getMessage()); images.put(path, null); } } diff --git a/src/main/java/View/PipeView.java b/src/main/java/View/PipeView.java index b94affb..d99719b 100644 --- a/src/main/java/View/PipeView.java +++ b/src/main/java/View/PipeView.java @@ -212,8 +212,7 @@ public void update() { endX = endNode.x; endY = endNode.y; } catch (NullPointerException e) { - System.err.println("pipe start or end node is null"); - e.printStackTrace(); + System.err.println("pipe start or end node is null" +"/n"+ e.getMessage() ); } } From 6f66081da54b74a1eb72ebf60b20559e31968693 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 21:44:53 +0200 Subject: [PATCH 10/24] Add tests to PumpTest, Capitalize enums --- src/main/java/Controller/Controller.java | 40 +++++++++--------- src/main/java/Model/ActionType.java | 3 +- src/main/java/Model/Mechanic.java | 37 ++++++++-------- src/main/java/Model/Pipe.java | 10 ++--- src/main/java/Model/Player.java | 24 +++++------ src/main/java/Model/PlayerActionState.java | 6 +-- src/main/java/Model/Saboteur.java | 23 +++++----- src/main/java/View/AppFrame.java | 4 +- src/main/java/View/Button.java | 14 +++---- src/main/java/View/CisternView.java | 6 +-- src/main/java/View/GameView.java | 2 +- src/main/java/View/MechanicView.java | 4 +- src/main/java/View/MenuView.java | 4 +- src/main/java/View/MouseIn.java | 42 +++++++++---------- src/main/java/View/NewGameView.java | 6 +-- src/main/java/View/PipeView.java | 2 +- src/main/java/View/PopUpButton.java | 44 +++++++++---------- src/main/java/View/PumpView.java | 3 +- src/main/java/View/SaboteurView.java | 4 +- src/main/java/View/SpringView.java | 3 +- src/main/java/View/WindowOptions.java | 11 ++++- src/test/java/model/PumpTest.java | 49 +++++++++++++++++++++- 22 files changed, 195 insertions(+), 146 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index cfd2dae..ec20fca 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -164,9 +164,9 @@ public void run(){ */ public void update(){ switch (WindowOptions.windowOption) { - case menu -> menuView.update(); - case newgame -> newGameView.update(); - case game -> gameView.update(); + case MENU -> menuView.update(); + case NEWGAME -> newGameView.update(); + case GAME -> gameView.update(); default -> { throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); } @@ -179,9 +179,9 @@ public void update(){ */ public void paint(Graphics g) { switch (WindowOptions.windowOption) { - case menu -> menuView.paint(g); - case newgame -> newGameView.paint(g); - case game -> gameView.paint(g); + case MENU -> menuView.paint(g); + case NEWGAME -> newGameView.paint(g); + case GAME -> gameView.paint(g); default -> { throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); } @@ -199,8 +199,8 @@ public Player getActivePlayer() { * A passzolás kivitelezésére használt függvény */ public void pass(){ - if(turnOrder.getFirst().getState()==PlayerActionState.specialAction) { - turnOrder.getFirst().setState(PlayerActionState.turnOver); + if(turnOrder.getFirst().getState()==PlayerActionState.SPECIAL_ACTION) { + turnOrder.getFirst().setState(PlayerActionState.TURN_OVER); turnOver(); } } @@ -571,9 +571,9 @@ public void stateSet(String objectName, String attribName, String attribValue) { break; case stateStr: switch (attribValue) { - case moveActionStr -> ((Mechanic) o).setState(PlayerActionState.moveAction); - case specialActionStr -> ((Mechanic) o).setState(PlayerActionState.specialAction); - case turnOverStr -> ((Mechanic) o).setState(PlayerActionState.turnOver); + case moveActionStr -> ((Mechanic) o).setState(PlayerActionState.MOVE_ACTION); + case specialActionStr -> ((Mechanic) o).setState(PlayerActionState.SPECIAL_ACTION); + case turnOverStr -> ((Mechanic) o).setState(PlayerActionState.TURN_OVER); } break; default: @@ -590,9 +590,9 @@ public void stateSet(String objectName, String attribName, String attribValue) { case stateStr: switch (attribValue) { - case moveActionStr -> ((Saboteur) o).setState(PlayerActionState.moveAction); - case specialActionStr -> ((Saboteur) o).setState(PlayerActionState.specialAction); - case turnOverStr -> ((Saboteur) o).setState(PlayerActionState.turnOver); + case moveActionStr -> ((Saboteur) o).setState(PlayerActionState.MOVE_ACTION); + case specialActionStr -> ((Saboteur) o).setState(PlayerActionState.SPECIAL_ACTION); + case turnOverStr -> ((Saboteur) o).setState(PlayerActionState.TURN_OVER); } break; default: @@ -641,7 +641,7 @@ public void stateSet(String objectName, String attribName, String attribValue) { */ public void turnOver() { turnOrder.add(turnOrder.removeFirst()); - turnOrder.getFirst().setState(PlayerActionState.moveAction); + turnOrder.getFirst().setState(PlayerActionState.MOVE_ACTION); if (turnOrder.getFirst().isFellDown()) { turnOrder.getFirst().setFellDown(false); SecureRandom random = new SecureRandom(); @@ -650,11 +650,11 @@ public void turnOver() { Player.setIgnoreStates(true); turnOrder.getFirst().Move(nodes.get(chance)); Player.setIgnoreStates(false); - turnOrder.getFirst().setState(PlayerActionState.turnOver); + turnOrder.getFirst().setState(PlayerActionState.TURN_OVER); turnOver(); } if (!turnOrder.getFirst().getStandingOn().canMoveFromHere()) - turnOrder.getFirst().setState(PlayerActionState.specialAction); + turnOrder.getFirst().setState(PlayerActionState.SPECIAL_ACTION); nextTurn(); for (Pipe p : pipes) { if (!p.isReadyToPierce()) { @@ -668,7 +668,7 @@ public void turnOver() { getActivePlayer().setStuck(false); else { getActivePlayer().setGlueLength(getActivePlayer().getGlueLength() - 1); - getActivePlayer().setState(PlayerActionState.turnOver); + getActivePlayer().setState(PlayerActionState.TURN_OVER); turnOver(); } } @@ -837,9 +837,9 @@ public void startGame() { turnOrder.addAll(saboteurs); started = true; gameView.setStarted(true); - turnOrder.getFirst().setState(PlayerActionState.moveAction); + turnOrder.getFirst().setState(PlayerActionState.MOVE_ACTION); if (!turnOrder.getFirst().getStandingOn().canMoveFromHere()) - turnOrder.getFirst().setState(PlayerActionState.specialAction); + turnOrder.getFirst().setState(PlayerActionState.SPECIAL_ACTION); Player.setIgnoreStates(false); } diff --git a/src/main/java/Model/ActionType.java b/src/main/java/Model/ActionType.java index b875a1d..ffa4c19 100644 --- a/src/main/java/Model/ActionType.java +++ b/src/main/java/Model/ActionType.java @@ -4,5 +4,6 @@ * A különféle akciók enum-ja */ public enum ActionType { - move,redirect,pickupPipe,pickupPump,placedown,pierce,glue,lubricate,repair,pass + MOVE,REDIRECT, PICKUP_PIPE, PICKUP_PUMP, PLACEDOWN, PIERCE, GLUE, LUBRICATE, REPAIR, PASS } + diff --git a/src/main/java/Model/Mechanic.java b/src/main/java/Model/Mechanic.java index 79bb1d7..d469cf1 100644 --- a/src/main/java/Model/Mechanic.java +++ b/src/main/java/Model/Mechanic.java @@ -3,7 +3,6 @@ import Controller.Controller; import java.io.Serializable; -import java.util.List; /** * Szerelő megvalósítására használt osztály @@ -22,10 +21,10 @@ public boolean Repair() { if(isIgnoreStates()) { repaired = standingOn.Repaired(); } - else if(state == PlayerActionState.specialAction) { + else if(state == PlayerActionState.SPECIAL_ACTION) { repaired = standingOn.Repaired(); if (repaired) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } @@ -43,10 +42,10 @@ public boolean PickUp(PickupAble item) { if(isIgnoreStates()) { pickedup = standingOn.PickedUpFrom(item); } - else if(state == PlayerActionState.specialAction) { + else if(state == PlayerActionState.SPECIAL_ACTION) { pickedup = standingOn.PickedUpFrom(item); if (pickedup) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } @@ -70,10 +69,10 @@ public boolean PlaceDown() { if(isIgnoreStates()) { successful = heldItems.PlacedDown(standingOn); } - else if(state == PlayerActionState.specialAction) { + else if(state == PlayerActionState.SPECIAL_ACTION) { successful = heldItems.PlacedDown(standingOn); if (successful) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } @@ -89,37 +88,37 @@ else if(state == PlayerActionState.specialAction) { */ public ActionType[] availableActions(Steppable step){ ActionType[] actions = new ActionType[6]; - if(state.equals(PlayerActionState.moveAction)){ + if(state.equals(PlayerActionState.MOVE_ACTION)){ if(step.canMoveToHere(this)) { - actions[2] = ActionType.move; + actions[2] = ActionType.MOVE; return actions; } } - if(state.equals(PlayerActionState.specialAction)){ + if(state.equals(PlayerActionState.SPECIAL_ACTION)){ //2 if (step.canMoveToHere(this)) - actions[2] = ActionType.move; + actions[2] = ActionType.MOVE; else if (!standingOn.canMoveFromHere() || standingOn == step) - actions[2] = ActionType.pass; + actions[2] = ActionType.PASS; //1 if(step.canRedirect(this)) - actions[1] = ActionType.redirect; + actions[1] = ActionType.REDIRECT; //3 if(step.canGlue(this)) - actions[3] = ActionType.glue; + actions[3] = ActionType.GLUE; //4 if(step.canPickUpPipe(this)){ - actions[4] = ActionType.pickupPipe; + actions[4] = ActionType.PICKUP_PIPE; } else if (step.canPlaceDown(this)) { - actions[4] = ActionType.placedown; + actions[4] = ActionType.PLACEDOWN; } //5 if(step.canPickUpPump(this)){ - actions[5] = ActionType.pickupPump; + actions[5] = ActionType.PICKUP_PUMP; } else if (step.canRepair(this)) { - actions[5] = ActionType.repair; + actions[5] = ActionType.REPAIR; } else if (step.canPierce(this)) { - actions[5] = ActionType.pierce; + actions[5] = ActionType.PIERCE; } return actions; } diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index 9b22187..dce0d2d 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -137,10 +137,10 @@ else if(end == 2){ } Player.setIgnoreStates(ignoreState); players.remove(player); - if (player.getState() == PlayerActionState.moveAction) - player.setState(PlayerActionState.specialAction); - else if (player.getState() == PlayerActionState.specialAction) { - player.setState(PlayerActionState.turnOver); + if (player.getState() == PlayerActionState.MOVE_ACTION) + player.setState(PlayerActionState.SPECIAL_ACTION); + else if (player.getState() == PlayerActionState.SPECIAL_ACTION) { + player.setState(PlayerActionState.TURN_OVER); Controller.getInstance().turnOver(); } lubricated = false; @@ -151,7 +151,7 @@ else if (player.getState() == PlayerActionState.specialAction) { player.setStuck(true); player.setGlueLength(1); glued = false; - player.setState(PlayerActionState.turnOver); + player.setState(PlayerActionState.TURN_OVER); Controller.getInstance().turnOver(); } diff --git a/src/main/java/Model/Player.java b/src/main/java/Model/Player.java index 98d1c3a..0b85a27 100644 --- a/src/main/java/Model/Player.java +++ b/src/main/java/Model/Player.java @@ -39,7 +39,7 @@ public abstract class Player implements Serializable { /** * A játékos státusza(nem az ő köre/mozog/akciók) */ - PlayerActionState state =PlayerActionState.turnOver; + PlayerActionState state =PlayerActionState.TURN_OVER; /** * flag, hogy az actionstate-ket figyelembe kell-e venni. */ @@ -52,7 +52,7 @@ public abstract class Player implements Serializable { public boolean Move(Steppable to) { removed=false; - if(!ignoreStates && state==PlayerActionState.turnOver) + if(!ignoreStates && state==PlayerActionState.TURN_OVER) return false; if (fellDown) { @@ -68,10 +68,10 @@ public boolean Move(Steppable to) { if (to.PlayerEnter(this)) { if (standingOn != null) { - if (!ignoreStates && state == PlayerActionState.moveAction) - state = PlayerActionState.specialAction; - else if (!ignoreStates && state == PlayerActionState.specialAction) { - state = PlayerActionState.turnOver; + if (!ignoreStates && state == PlayerActionState.MOVE_ACTION) + state = PlayerActionState.SPECIAL_ACTION; + else if (!ignoreStates && state == PlayerActionState.SPECIAL_ACTION) { + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } standingOn.PlayerExit(this); @@ -103,11 +103,11 @@ public void RemovePlayer(){ * @param out kimeneti cső */ public boolean Redirect(Pipe in, Pipe out) { - if (state != PlayerActionState.specialAction) + if (state != PlayerActionState.SPECIAL_ACTION) return false; if (standingOn.PlayerRedirect(in, out)) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); return true; } @@ -123,10 +123,10 @@ public boolean Pierce() { if(ignoreStates) { pierced = standingOn.Pierced(); } - else if(state == PlayerActionState.specialAction) { + else if(state == PlayerActionState.SPECIAL_ACTION) { pierced = standingOn.Pierced(); if (pierced) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } @@ -141,10 +141,10 @@ public boolean Glue(){ if(ignoreStates) { glued = standingOn.Glued(); } - else if(state == PlayerActionState.specialAction) { + else if(state == PlayerActionState.SPECIAL_ACTION) { glued = standingOn.Glued(); if (glued) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } diff --git a/src/main/java/Model/PlayerActionState.java b/src/main/java/Model/PlayerActionState.java index 0e31d00..6a74b5d 100644 --- a/src/main/java/Model/PlayerActionState.java +++ b/src/main/java/Model/PlayerActionState.java @@ -5,7 +5,7 @@ * Enum osztály, az akciókezelés számára fontos, melyik játékosnak milyen az állapota az akciók szempontjából. */ public enum PlayerActionState implements Serializable { - moveAction, - specialAction, - turnOver, + MOVE_ACTION, + SPECIAL_ACTION, + TURN_OVER, } diff --git a/src/main/java/Model/Saboteur.java b/src/main/java/Model/Saboteur.java index 9929ad6..84f61b4 100644 --- a/src/main/java/Model/Saboteur.java +++ b/src/main/java/Model/Saboteur.java @@ -3,7 +3,6 @@ import Controller.Controller; import java.io.Serializable; -import java.util.List; /** * A Saboteur osztály valósítja meg a szabotőrrel kapcsolatos metódusokat @@ -19,10 +18,10 @@ public boolean Lubricate(){ if(isIgnoreStates()) { lubricated = standingOn.Lubricated(); } - else if(state == PlayerActionState.specialAction) { + else if(state == PlayerActionState.SPECIAL_ACTION) { lubricated = standingOn.Lubricated(); if (lubricated) { - state = PlayerActionState.turnOver; + state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } @@ -37,30 +36,30 @@ else if(state == PlayerActionState.specialAction) { */ public ActionType[] availableActions(Steppable step){ ActionType[] actions = new ActionType[6]; - if(state.equals(PlayerActionState.moveAction)){ + if(state.equals(PlayerActionState.MOVE_ACTION)){ if(step.canMoveToHere(this)) { - actions[2] = ActionType.move; + actions[2] = ActionType.MOVE; return actions; } } - if(state.equals(PlayerActionState.specialAction)){ + if(state.equals(PlayerActionState.SPECIAL_ACTION)){ //2 if (step.canMoveToHere(this)) - actions[2] = ActionType.move; + actions[2] = ActionType.MOVE; else if (!standingOn.canMoveFromHere() || standingOn == step) - actions[2] = ActionType.pass; + actions[2] = ActionType.PASS; //0 if(step.canLubricate(this)) - actions[0] = ActionType.lubricate; + actions[0] = ActionType.LUBRICATE; //1 if(step.canRedirect(this)) - actions[1] = ActionType.redirect; + actions[1] = ActionType.REDIRECT; //3 if(step.canGlue(this)) - actions[3] = ActionType.glue; + actions[3] = ActionType.GLUE; //5 if (step.canPierce(this)) - actions[5] = ActionType.pierce; + actions[5] = ActionType.PIERCE; return actions; } return actions; diff --git a/src/main/java/View/AppFrame.java b/src/main/java/View/AppFrame.java index bdfe919..d6edf58 100644 --- a/src/main/java/View/AppFrame.java +++ b/src/main/java/View/AppFrame.java @@ -1,7 +1,5 @@ package View; -import Controller.Controller; - import javax.swing.*; import java.awt.*; @@ -27,7 +25,7 @@ public AppFrame(AppPanel panel) { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //tesztelés - WindowOptions.windowOption = WindowOptions.menu; + WindowOptions.windowOption = WindowOptions.MENU; } /** diff --git a/src/main/java/View/Button.java b/src/main/java/View/Button.java index 51ff6cd..7ba2991 100644 --- a/src/main/java/View/Button.java +++ b/src/main/java/View/Button.java @@ -69,27 +69,27 @@ public boolean isIn(MouseEvent e) { @Override public void clickAction(MouseEvent e) { // kilépés megvalósítása - if(option == WindowOptions.exit) + if(option == WindowOptions.EXIT) System.exit(0); if (option == null) return; // map változtatása - if(this.option == WindowOptions.map1){ - this.option = WindowOptions.map2; + if(this.option == WindowOptions.MAP_1){ + this.option = WindowOptions.MAP_2; Controller.getInstance().getNewGameView().setMap(2); img = ImageUtility.scaleImage(getMapPreview2(), 200); return; } - if(this.option == WindowOptions.map2){ - this.option = WindowOptions.map1; + if(this.option == WindowOptions.MAP_2){ + this.option = WindowOptions.MAP_1; Controller.getInstance().getNewGameView().setMap(1); img = ImageUtility.scaleImage(getMapPrevButton(), 200); return; } // játék indítása WindowOptions.windowOption = option; - if(this.option == WindowOptions.game){ + if(this.option == WindowOptions.GAME){ if (Controller.getInstance().getMechanics().size() >= 2 && Controller.getInstance().getSaboteurs().size() >= 2) { @@ -100,7 +100,7 @@ public void clickAction(MouseEvent e) { Controller.getInstance().getGameView().mapSetup(System.getProperty("user.dir") + File.separator + "src" + File.separator + "Assets" + File.separator + "map2.txt"); } } else { - WindowOptions.windowOption = WindowOptions.newgame; + WindowOptions.windowOption = WindowOptions.NEWGAME; } } diff --git a/src/main/java/View/CisternView.java b/src/main/java/View/CisternView.java index 9f30a22..44ca29a 100644 --- a/src/main/java/View/CisternView.java +++ b/src/main/java/View/CisternView.java @@ -33,7 +33,7 @@ public CisternView(int x, int y, int r, Cistern c, Window v) { cistern = c; sprite = Pictures.getCisternFilledImg(); sprite = ImageUtility.scaleImage(sprite, 2*r); - if (WindowOptions.windowOption == WindowOptions.game) + if (WindowOptions.windowOption == WindowOptions.GAME) gameView = (GameView) v; } @@ -134,8 +134,8 @@ public boolean isDraggable() { */ public void displayCreated() { ActionType[] at = new ActionType[6]; - at[4] = ActionType.pickupPipe; - at[5] = ActionType.pickupPump; + at[4] = ActionType.PICKUP_PIPE; + at[5] = ActionType.PICKUP_PUMP; createPopUpBarWithActions(x, y, 100, view, this, at); } } diff --git a/src/main/java/View/GameView.java b/src/main/java/View/GameView.java index b886f45..d48fbf1 100644 --- a/src/main/java/View/GameView.java +++ b/src/main/java/View/GameView.java @@ -61,7 +61,7 @@ public GameView(AppFrame frame) { this.frame = frame; exit = new Button(frame.getWidth() - 80, 10, 50, 50, this); exit.img = ImageUtility.scaleImage(getExitButton(), 45); - exit.option = WindowOptions.exit; + exit.option = WindowOptions.EXIT; addDrawable(exit, true); addClickable(exit, true); } diff --git a/src/main/java/View/MechanicView.java b/src/main/java/View/MechanicView.java index 7b371ff..414f53f 100644 --- a/src/main/java/View/MechanicView.java +++ b/src/main/java/View/MechanicView.java @@ -24,7 +24,7 @@ public class MechanicView extends Drawable { public MechanicView(int x, int y, Mechanic m, Window v) { super(x, y, v); mechanic = m; - if (WindowOptions.windowOption == WindowOptions.game) + if (WindowOptions.windowOption == WindowOptions.GAME) gameView = (GameView) v; color = Color.BLUE; @@ -66,7 +66,7 @@ public void setNumber(int number) { @Override public void paint(Graphics g) { // ha a játék ablakban vagyunk, akkor a játékos színével rajzoljuk ki - if (WindowOptions.windowOption == WindowOptions.newgame) { + if (WindowOptions.windowOption == WindowOptions.NEWGAME) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int screenWidth = (int) screenSize.getWidth() * 3 / 4; int screenHeight = (int) screenSize.getHeight() * 3 / 4; diff --git a/src/main/java/View/MenuView.java b/src/main/java/View/MenuView.java index 84d38ae..0760c29 100644 --- a/src/main/java/View/MenuView.java +++ b/src/main/java/View/MenuView.java @@ -28,11 +28,11 @@ public MenuView() { newGame.text = "Új játék"; newGame.img = ImageUtility.scaleImage(getPlayButton(), 50); - newGame.option = WindowOptions.newgame; + newGame.option = WindowOptions.NEWGAME; exit.text = "Kilépés"; exit.img = ImageUtility.scaleImage(getExitButton(), 50); - exit.option = WindowOptions.exit; + exit.option = WindowOptions.EXIT; addDrawable(newGame, true); addClickable(newGame, true); addDrawable(exit, true); diff --git a/src/main/java/View/MouseIn.java b/src/main/java/View/MouseIn.java index 070bb7d..9c8add4 100644 --- a/src/main/java/View/MouseIn.java +++ b/src/main/java/View/MouseIn.java @@ -15,9 +15,9 @@ public class MouseIn implements MouseListener, MouseMotionListener { @Override public void mouseClicked(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mouseClicked(e); - case newgame -> Controller.getInstance().getNewGameView().mouseClicked(e); - case game -> Controller.getInstance().getGameView().mouseClicked(e); + case MENU -> Controller.getInstance().getMenuView().mouseClicked(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mouseClicked(e); + case GAME -> Controller.getInstance().getGameView().mouseClicked(e); } } @@ -28,9 +28,9 @@ public void mouseClicked(MouseEvent e) { @Override public void mousePressed(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mousePressed(e); - case newgame -> Controller.getInstance().getNewGameView().mousePressed(e); - case game -> Controller.getInstance().getGameView().mousePressed(e); + case MENU -> Controller.getInstance().getMenuView().mousePressed(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mousePressed(e); + case GAME -> Controller.getInstance().getGameView().mousePressed(e); } } @@ -41,9 +41,9 @@ public void mousePressed(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mouseReleased(e); - case newgame -> Controller.getInstance().getNewGameView().mouseReleased(e); - case game -> Controller.getInstance().getGameView().mouseReleased(e); + case MENU -> Controller.getInstance().getMenuView().mouseReleased(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mouseReleased(e); + case GAME -> Controller.getInstance().getGameView().mouseReleased(e); } } @@ -54,9 +54,9 @@ public void mouseReleased(MouseEvent e) { @Override public void mouseEntered(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mouseEntered(e); - case newgame -> Controller.getInstance().getNewGameView().mouseEntered(e); - case game -> Controller.getInstance().getGameView().mouseEntered(e); + case MENU -> Controller.getInstance().getMenuView().mouseEntered(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mouseEntered(e); + case GAME -> Controller.getInstance().getGameView().mouseEntered(e); } } @@ -67,9 +67,9 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mouseExited(e); - case newgame -> Controller.getInstance().getNewGameView().mouseExited(e); - case game -> Controller.getInstance().getGameView().mouseExited(e); + case MENU -> Controller.getInstance().getMenuView().mouseExited(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mouseExited(e); + case GAME -> Controller.getInstance().getGameView().mouseExited(e); } } @@ -80,9 +80,9 @@ public void mouseExited(MouseEvent e) { @Override public void mouseDragged(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mouseDragged(e); - case newgame -> Controller.getInstance().getNewGameView().mouseDragged(e); - case game -> Controller.getInstance().getGameView().mouseDragged(e); + case MENU -> Controller.getInstance().getMenuView().mouseDragged(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mouseDragged(e); + case GAME -> Controller.getInstance().getGameView().mouseDragged(e); } } @@ -93,9 +93,9 @@ public void mouseDragged(MouseEvent e) { @Override public void mouseMoved(MouseEvent e) { switch (WindowOptions.windowOption) { - case menu -> Controller.getInstance().getMenuView().mouseMoved(e); - case newgame -> Controller.getInstance().getNewGameView().mouseMoved(e); - case game -> Controller.getInstance().getGameView().mouseMoved(e); + case MENU -> Controller.getInstance().getMenuView().mouseMoved(e); + case NEWGAME -> Controller.getInstance().getNewGameView().mouseMoved(e); + case GAME -> Controller.getInstance().getGameView().mouseMoved(e); } } } diff --git a/src/main/java/View/NewGameView.java b/src/main/java/View/NewGameView.java index 4b33d47..680f2aa 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/View/NewGameView.java @@ -47,7 +47,7 @@ public NewGameView() { start = new Button(screenWidth - 200, 10, 50, 50, this); exit = new Button(screenWidth - 100, 10, 150, 150, this); map = new Button(50, screenHeight / 2, 500, 300, this); - map.option = WindowOptions.map1; + map.option = WindowOptions.MAP_1; map.img = ImageUtility.scaleImage(getMapPrevButton(), 200); int offset = 25; @@ -60,9 +60,9 @@ public NewGameView() { decrease = new ChangeMaxPointButton(screenWidth / 2 + 20 * 13, screenHeight / 6 - 8, 35, 35, this, -1); start.img = ImageUtility.scaleImage(getPlayButton(), 50); - start.option = WindowOptions.game; + start.option = WindowOptions.GAME; exit.img = ImageUtility.scaleImage(getExitButton(), 50); - exit.option = WindowOptions.exit; + exit.option = WindowOptions.EXIT; addMechanic.img = ImageUtility.scaleImage(getPlusButton(), 35); addSaboteur.img = ImageUtility.scaleImage(getPlusButton(), 35); increase.img = ImageUtility.scaleImage(getPlusButton(), 35); diff --git a/src/main/java/View/PipeView.java b/src/main/java/View/PipeView.java index d99719b..81c6f28 100644 --- a/src/main/java/View/PipeView.java +++ b/src/main/java/View/PipeView.java @@ -30,7 +30,7 @@ public PipeView(Drawable startNode, Drawable endNode, int width, Pipe p, Window this.endNode = endNode; pipe = p; - if (WindowOptions.windowOption == WindowOptions.game) + if (WindowOptions.windowOption == WindowOptions.GAME) gameView = (GameView) v; } public boolean selected; diff --git a/src/main/java/View/PopUpButton.java b/src/main/java/View/PopUpButton.java index d7e5a28..4c31ad6 100644 --- a/src/main/java/View/PopUpButton.java +++ b/src/main/java/View/PopUpButton.java @@ -15,15 +15,15 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr actiontype = a; switch (actiontype) { - case glue -> sprite = Pictures.getGlueImg(); - case lubricate -> sprite = Pictures.getLubricateImg(); - case move -> sprite = Pictures.getMoveImg(); - case pass -> sprite = Pictures.getPassImg(); - case pierce-> sprite = Pictures.getPierceImg(); - case repair -> sprite = Pictures.getRepairImg(); - case redirect -> sprite = Pictures.getRedirectImg(); - case placedown -> sprite = Pictures.getPlaceDownImg(); - case pickupPipe, pickupPump -> sprite = Pictures.getPickUpImg(); + case GLUE -> sprite = Pictures.getGlueImg(); + case LUBRICATE -> sprite = Pictures.getLubricateImg(); + case MOVE -> sprite = Pictures.getMoveImg(); + case PASS -> sprite = Pictures.getPassImg(); + case PIERCE -> sprite = Pictures.getPierceImg(); + case REPAIR -> sprite = Pictures.getRepairImg(); + case REDIRECT -> sprite = Pictures.getRedirectImg(); + case PLACEDOWN -> sprite = Pictures.getPlaceDownImg(); + case PICKUP_PIPE, PICKUP_PUMP -> sprite = Pictures.getPickUpImg(); } sprite = ImageUtility.scaleImage(sprite, 2*r); drawLoc = ImageUtility.centerImage(new Point(x, y), sprite); @@ -52,18 +52,18 @@ public void clickAction(MouseEvent e) { Player p = c.getActivePlayer(); Steppable s = creator.getCorrespondingModelSteppable(); switch (actiontype) { - case glue -> c.glue(c.getObjectName(p)); - case lubricate -> c.lubricate(c.getObjectName(p)); - case move -> c.move(c.getObjectName(p), c.getObjectName(s)); - case pass -> c.pass(); - case pierce -> c.pierce(c.getObjectName(p)); - case repair -> c.repair(c.getObjectName(p)); - case redirect -> { + case GLUE -> c.glue(c.getObjectName(p)); + case LUBRICATE -> c.lubricate(c.getObjectName(p)); + case MOVE -> c.move(c.getObjectName(p), c.getObjectName(s)); + case PASS -> c.pass(); + case PIERCE -> c.pierce(c.getObjectName(p)); + case REPAIR -> c.repair(c.getObjectName(p)); + case REDIRECT -> { waitingForParameter = true; paramClient = this; } - case placedown -> c.placedown(c.getObjectName(p)); - case pickupPipe -> { + case PLACEDOWN -> c.placedown(c.getObjectName(p)); + case PICKUP_PIPE -> { if (((GameView) view).cisterns.contains(creator)) { Cistern cis = (Cistern) s; Pipe pipe = cis.getGeneratedPipes().getFirst(); @@ -72,7 +72,7 @@ public void clickAction(MouseEvent e) { c.pickup(c.getObjectName(p), c.getObjectName(s)); } } - case pickupPump -> { + case PICKUP_PUMP -> { Cistern cis = (Cistern) s; Pump pump = cis.getGeneratedPumps().getFirst(); c.pickup(c.getObjectName(p), c.getObjectName(pump)); @@ -97,9 +97,9 @@ public synchronized void paint(Graphics g) { CisternView c = (CisternView) cd.getCreator(); g2d.setColor(Color.BLACK); g2d.setFont(new Font("Inter", Font.BOLD, 20)); - if (actiontype == ActionType.pickupPipe) + if (actiontype == ActionType.PICKUP_PIPE) g2d.drawString("csövek: " + ((Cistern)c.getCorrespondingModelElement()).getGeneratedPipes().size(), x + r + 15, y); - if (actiontype == ActionType.pickupPump) + if (actiontype == ActionType.PICKUP_PUMP) g2d.drawString("pumpák: " + ((Cistern)c.getCorrespondingModelElement()).getGeneratedPumps().size(), x + r + 15, y); } g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); @@ -124,7 +124,7 @@ public static void paramsReceived() { Controller c = Controller.getInstance(); Player p = c.getActivePlayer(); Steppable s = paramClient.creator.getCorrespondingModelSteppable(); - if (paramClient.actiontype == ActionType.redirect) { + if (paramClient.actiontype == ActionType.REDIRECT) { c.redirect(c.getObjectName(p), c.getObjectName(parameters.getFirst().getCorrespondingModelElement()), c.getObjectName(parameters.getLast().getCorrespondingModelElement())); } waitingForParameter = false; diff --git a/src/main/java/View/PumpView.java b/src/main/java/View/PumpView.java index 7242c97..5f67b31 100644 --- a/src/main/java/View/PumpView.java +++ b/src/main/java/View/PumpView.java @@ -8,7 +8,6 @@ import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; -import java.util.LinkedList; import static View.Pictures.*; import static java.awt.Color.BLACK; @@ -24,7 +23,7 @@ public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { arrowSprite = getPumpIndicatorImg(); arrowSprite = ImageUtility.scaleImage(arrowSprite, 20); - if (WindowOptions.windowOption == WindowOptions.game) + if (WindowOptions.windowOption == WindowOptions.GAME) gameView = (GameView) v; } private GameView gameView; diff --git a/src/main/java/View/SaboteurView.java b/src/main/java/View/SaboteurView.java index 7fed442..1aa440a 100644 --- a/src/main/java/View/SaboteurView.java +++ b/src/main/java/View/SaboteurView.java @@ -14,7 +14,7 @@ public class SaboteurView extends Drawable { public SaboteurView(int x, int y, Saboteur s, Window v) { super(x, y, v); saboteur = s; - if (WindowOptions.windowOption == WindowOptions.game) + if (WindowOptions.windowOption == WindowOptions.GAME) gameView = (GameView) v; color = Color.RED; } @@ -35,7 +35,7 @@ public void setNumber(int number) { } @Override public void paint(Graphics g) { - if(WindowOptions.windowOption==WindowOptions.newgame) + if(WindowOptions.windowOption==WindowOptions.NEWGAME) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int screenWidth = (int) screenSize.getWidth() * 3 / 4; diff --git a/src/main/java/View/SpringView.java b/src/main/java/View/SpringView.java index 9181f79..68d478f 100644 --- a/src/main/java/View/SpringView.java +++ b/src/main/java/View/SpringView.java @@ -8,7 +8,6 @@ import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; -import java.nio.Buffer; import static View.Pictures.*; @@ -32,7 +31,7 @@ public SpringView(int x, int y, int r, Spring s, Window v) { sprite = ImageUtility.scaleImage(sprite, 2*r); arrowSprite = getPumpIndicatorImg(); arrowSprite = ImageUtility.scaleImage(arrowSprite, 20); - if (WindowOptions.windowOption == WindowOptions.game) + if (WindowOptions.windowOption == WindowOptions.GAME) gameView = (GameView) v; } private GameView gameView; diff --git a/src/main/java/View/WindowOptions.java b/src/main/java/View/WindowOptions.java index 1f44501..9597fa3 100644 --- a/src/main/java/View/WindowOptions.java +++ b/src/main/java/View/WindowOptions.java @@ -4,6 +4,13 @@ * Játékállapotok */ public enum WindowOptions { - menu, newgame, game, map1,map2, load, save, exit; - public static WindowOptions windowOption=menu; + MENU, + NEWGAME, + GAME, + MAP_1, + MAP_2, + LOAD, + SAVE, + EXIT; + public static WindowOptions windowOption= MENU; } diff --git a/src/test/java/model/PumpTest.java b/src/test/java/model/PumpTest.java index 5188df1..0ea1dfc 100644 --- a/src/test/java/model/PumpTest.java +++ b/src/test/java/model/PumpTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.*; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; @@ -73,4 +73,51 @@ void testWaterFlowWhenEmpty() { verify(mockActiveOut, never()).GainWater(anyInt()); verify(mockActiveIn).LoseWater(1); } + + @Test + void testWaterFlow_WithMaxCapacity() { + // Arrange + pump.setHeldWater(20); + when(mockActiveOut.GainWater(anyInt())).thenReturn(1); + when(mockActiveIn.LoseWater(anyInt())).thenReturn(1); + + // Act + pump.WaterFlow(); + + // Assert + assertEquals(20, pump.getHeldWater()); + verify(mockActiveOut).GainWater(1); + verify(mockActiveIn).LoseWater(1); + verify(mockActiveIn).GainWater(0); + } + + @Test + void testAddPipe() { + // Arrange + Pipe mockPipe = Mockito.mock(Pipe.class); + + // Act + boolean success = pump.AddPipe(mockPipe); + + // Assert + assertTrue(success); + assertTrue(pump.getPipes().contains(mockPipe)); + } + + @Test + void testAddPipe_MaximumPipesReached() { + // Arrange + for (int i = 0; i < 10; i++) { + pump.AddPipe(Mockito.mock(Pipe.class)); + } + Pipe mockPipe = Mockito.mock(Pipe.class); + + // Act + boolean success = pump.AddPipe(mockPipe); + + // Assert + assertFalse(success); + assertFalse(pump.getPipes().contains(mockPipe)); + } + } \ No newline at end of file From b3266fd50a5fc6111f89d1e704260c92f1fc3810 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 22:37:49 +0200 Subject: [PATCH 11/24] More high severity Issue fixed, Complex methods to smaller ones --- src/main/java/Controller/Controller.java | 58 +++-- src/main/java/Controller/Main.java | 295 +++++++++++++---------- src/main/java/Model/Pipe.java | 64 ++--- src/main/java/Model/Pump.java | 4 +- src/main/java/View/AppPanel.java | 3 +- src/main/java/View/CisternView.java | 4 +- src/main/java/View/GameView.java | 12 +- src/main/java/View/Window.java | 2 +- 8 files changed, 255 insertions(+), 187 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index ec20fca..a284367 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -29,6 +29,9 @@ static public Controller getInstance() { return controller; } final String WrongAttr = "wrong attribute name"; + final String WrongPipe = "wrong pipe name"; + final String WrongPlayer = "wrong player name"; + final String WrongMech = "wrong mechanic name"; final String fellDownStr = "fellDown"; final String stuckStr = "stuck"; final String standingOnStr = "standingOn"; @@ -279,7 +282,7 @@ public void create(String name, String type,int x, int y) { public void connect(String pipeName, String wNodeName) { if (!pipes.contains((Pipe)objectCatalog.get(pipeName))) { - IO_Manager.writeError("wrong pipe name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); return; } Pipe p = (Pipe) objectCatalog.get(pipeName); @@ -305,7 +308,7 @@ public void connect(String pipeName, String wNodeName) { public void move(String playerName, String steppableName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -336,7 +339,7 @@ public void move(String playerName, String steppableName) { public void pierce(String playerName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -353,7 +356,7 @@ public void pierce(String playerName) { public void glue(String playerName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -388,7 +391,7 @@ public void lubricate(String saboteurName) { public void repair(String mechanicName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError("wrong mechanic name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -411,19 +414,19 @@ public void repair(String mechanicName) { public void redirect(String playerName, String inPipeName, String outPipeName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError("wrong player name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); if (!pipes.contains((Pipe)objectCatalog.get(inPipeName))) { - IO_Manager.writeError("wrong pipe name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); return; } Pipe in = (Pipe) objectCatalog.get(inPipeName); if (!pipes.contains((Pipe)objectCatalog.get(outPipeName))) { - IO_Manager.writeError("wrong pipe name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); return; } Pipe out = (Pipe) objectCatalog.get(outPipeName); @@ -443,7 +446,7 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { public void pickup(String mechanicName, String pickupName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError("wrong mechanic name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -467,7 +470,7 @@ public void pickup(String mechanicName, String pickupName) { public void placedown(String mechanicName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError("wrong mechanic name", Controller.filetoWrite != null); + IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -745,12 +748,25 @@ public void waterFlow(String wNodeName) { * @param filename - a fájl amibe mentünk */ public void save(String filename) { + ObjectOutputStream oos = null; + FileOutputStream fops = null; try { - FileOutputStream fops = new FileOutputStream("program.txt"); - ObjectOutputStream oos = new ObjectOutputStream(fops); + fops = new FileOutputStream("program.txt"); + oos = new ObjectOutputStream(fops); oos.writeObject(this); } catch (Exception e) { System.err.println("Error saving state to " + filename + ": " + e.getMessage()); + } finally { + try { + if (oos != null) { + oos.close(); + } + if (fops != null) { + fops.close(); + } + } catch (IOException e) { + System.err.println("Error closing output streams: " + e.getMessage()); + } } IO_Manager.write("saved state to program.txt", Controller.filetoWrite != null); } @@ -760,16 +776,30 @@ public void save(String filename) { * @param filename - a fájl amiből betöltünk */ public void load(String filename) { + ObjectInputStream ois = null; + FileInputStream fis = null; try { - FileInputStream fis = new FileInputStream("program.txt"); - ObjectInputStream ois = new ObjectInputStream(fis); + fis = new FileInputStream("program.txt"); + ois = new ObjectInputStream(fis); controller = (Controller) ois.readObject(); } catch (Exception e) { System.err.println("Error loading state from " + filename + ": " + e.getMessage()); + } finally { + try { + if (ois != null) { + ois.close(); + } + if (fis != null) { + fis.close(); + } + } catch (IOException e) { + System.err.println("Error closing input streams: " + e.getMessage()); + } } IO_Manager.write("loaded state from program.txt", Controller.filetoWrite != null); } + /** * A játék végét lefuttató függvény */ diff --git a/src/main/java/Controller/Main.java b/src/main/java/Controller/Main.java index 9b248cc..047cfef 100644 --- a/src/main/java/Controller/Main.java +++ b/src/main/java/Controller/Main.java @@ -1,8 +1,6 @@ package Controller; import Model.IO_Manager; -import View.AppFrame; -import View.AppPanel; import java.io.File; import java.util.ConcurrentModificationException; @@ -19,8 +17,6 @@ public static void main(String[] args) { String fileToRead = null; String fileToWrite = null; - AppFrame frame; - AppPanel panel; for (int i = 0; i < args.length; i++) { switch (args[i]) { @@ -94,139 +90,172 @@ private static void processCommand(String command, boolean toFile) { for (String s : cmd) s = s.trim(); switch (cmd[0]) { - case "create" -> { - if (cmd.length != 5 && cmd.length !=3) - IO_Manager.writeError("create requires 2 or 4 parameters", Controller.filetoWrite != null); - else - if(cmd[2].equals("pump") || cmd[2].equals("cistern") || cmd[2].equals("spring")){ - if(cmd.length !=5) - IO_Manager.writeError("creating nodes requires 4 parameters", Controller.filetoWrite != null); - else - controller.create(cmd[1], cmd[2], Integer.parseInt(cmd[3]), Integer.parseInt(cmd[4])); - } - else { - if (cmd.length != 3) - IO_Manager.writeError("creating pipes or players requires 2 parameters", Controller.filetoWrite != null); - else - controller.create(cmd[1], cmd[2], 0,0); + case "create" -> processCreateCommand(controller, cmd); + case "connect" -> processConnectCommand(controller, cmd); + case "move" -> processMoveCommand(controller, cmd); + case "pierce" -> processPierceCommand(controller, cmd); + case "glue" -> processGlueCommand(controller, cmd); + case "lubricate" -> processLubricateCommand(controller, cmd); + case "repair" -> processRepairCommand(controller, cmd); + case "redirect" -> processRedirectCommand(controller, cmd); + case "pickup" -> processPickupCommand(controller, cmd); + case "placedown" -> processPlaceDownCommand(controller, cmd); + case "state" -> processStateCommand(controller, cmd); + case "nextTurn" -> processNextTurnCommand(controller, cmd); + case "generate" -> processGenerateCommand(controller, cmd); + case "waterFlow" -> processWaterFlowCommand(controller, cmd); + case "save" -> processSaveCommand(controller, cmd); + case "load" -> processLoadCommand(controller, cmd); + case "endGame" -> processEndGameCommand(controller, cmd); + case "startGame" -> processStartGameCommand(controller, cmd); + default -> IO_Manager.writeError("Unknown command: " + cmd[0], Controller.filetoWrite != null); + } + } - } - } - case "connect" -> { - if (cmd.length != 3) - IO_Manager.writeError("connect requires 2 parameters", Controller.filetoWrite != null); - else - controller.connect(cmd[1], cmd[2]); - } - case "move" -> { - if (cmd.length != 3) - IO_Manager.writeError("move requires 2 parameters", Controller.filetoWrite != null); - else - controller.move(cmd[1], cmd[2]); - } - case "pierce" -> { - if (cmd.length != 2) - IO_Manager.writeError("pierce requires 1 parameter", Controller.filetoWrite != null); - else - controller.pierce(cmd[1]); - } - case "glue" -> { - if (cmd.length != 2) - IO_Manager.writeError("glue requires 1 parameter", Controller.filetoWrite != null); - else - controller.glue(cmd[1]); - } - case "lubricate" -> { - if (cmd.length != 2) - IO_Manager.writeError("lubricate requires 1 parameter", Controller.filetoWrite != null); - else - controller.lubricate(cmd[1]); - } - case "repair" -> { - if (cmd.length != 2) - IO_Manager.writeError("repair requires 1 parameter", Controller.filetoWrite != null); - else - controller.repair(cmd[1]); - } - case "redirect" -> { - if (cmd.length != 4) - IO_Manager.writeError("redirect requires 3 parameters", Controller.filetoWrite != null); - else - controller.redirect(cmd[1], cmd[2], cmd[3]); - } - case "pickup" -> { - if (cmd.length != 3) - IO_Manager.writeError("pickup requires 2 parameters", Controller.filetoWrite != null); - else - controller.pickup(cmd[1], cmd[2]); - } - case "placedown" -> { - if (cmd.length != 2) - IO_Manager.writeError("placedown requires 1 parameter", Controller.filetoWrite != null); - else - controller.placedown(cmd[1]); - } - case "state" -> { - if (cmd.length < 2) - IO_Manager.writeError("available commands are:\tstate get\tstate set", Controller.filetoWrite != null); - else if (cmd[1].equals("get")) - if (cmd.length != 4) - IO_Manager.writeError("state get requires 2 parameters", Controller.filetoWrite != null); - else - controller.stateGet(cmd[2], cmd[3]); - else if (cmd[1].equals("set")) - if (cmd.length != 5) - IO_Manager.writeError("state set requires 3 parameters", Controller.filetoWrite != null); - else - controller.stateSet(cmd[2], cmd[3], cmd[4]); - else - IO_Manager.writeError("available commands are:\tstate get\tstate set", Controller.filetoWrite != null); - } - case "nextTurn" -> { - if (cmd.length != 1) - IO_Manager.writeError("nextTurn requires no parameters", Controller.filetoWrite != null); - else - controller.nextTurn(); - } - case "generate" -> { - if (cmd.length != 4) - IO_Manager.writeError("generate requires 3 parameters", Controller.filetoWrite != null); - else - controller.generate(cmd[1], cmd[2], cmd[3]); - } - case "waterFlow" -> { - if (cmd.length != 2) - IO_Manager.writeError("waterFlow requires no parameters", Controller.filetoWrite != null); - else - controller.waterFlow(cmd[1]); - } - case "save" -> { - if (cmd.length != 2) - IO_Manager.writeError("save requires 1 parameter", Controller.filetoWrite != null); - else - controller.save(cmd[1]); - } - case "load" -> { - if (cmd.length != 2) - IO_Manager.writeError("load requires 1 parameter", Controller.filetoWrite != null); - else - controller.load(cmd[1]); - } - case "endGame" -> { - if (cmd.length != 1) - IO_Manager.writeError("endGame requires no parameters", Controller.filetoWrite != null); - else - controller.endGame(); - } - case "startGame" -> { - if (cmd.length != 1) - IO_Manager.writeError("startGame requires no parameters", Controller.filetoWrite != null); - else - controller.startGame(); - } + private static void processCreateCommand(Controller controller, String[] cmd) { + if (cmd.length != 5 && cmd.length != 3) + IO_Manager.writeError("create requires 2 or 4 parameters", Controller.filetoWrite != null); + else if (cmd[2].equals("pump") || cmd[2].equals("cistern") || cmd[2].equals("spring")) { + if (cmd.length != 5) + IO_Manager.writeError("creating nodes requires 4 parameters", Controller.filetoWrite != null); + else + controller.create(cmd[1], cmd[2], Integer.parseInt(cmd[3]), Integer.parseInt(cmd[4])); + } else { + if (cmd.length != 3) + IO_Manager.writeError("creating pipes or players requires 2 parameters", Controller.filetoWrite != null); + else + controller.create(cmd[1], cmd[2], 0, 0); } } + private static void processConnectCommand(Controller controller, String[] cmd) { + if (cmd.length != 3) + IO_Manager.writeError("connect requires 2 parameters", Controller.filetoWrite != null); + else + controller.connect(cmd[1], cmd[2]); + } + + private static void processMoveCommand(Controller controller, String[] cmd) { + if (cmd.length != 3) + IO_Manager.writeError("move requires 2 parameters", Controller.filetoWrite != null); + else + controller.move(cmd[1], cmd[2]); + } + private static void processPierceCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("pierce requires 1 parameter", Controller.filetoWrite != null); + else + controller.pierce(cmd[1]); + } + + private static void processGlueCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("glue requires 1 parameter", Controller.filetoWrite != null); + else + controller.glue(cmd[1]); + } + + private static void processLubricateCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("lubricate requires 1 parameter", Controller.filetoWrite != null); + else + controller.lubricate(cmd[1]); + } + + private static void processRepairCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("repair requires 1 parameter", Controller.filetoWrite != null); + else + controller.repair(cmd[1]); + } + + private static void processRedirectCommand(Controller controller, String[] cmd) { + if (cmd.length != 4) + IO_Manager.writeError("redirect requires 3 parameters", Controller.filetoWrite != null); + else + controller.redirect(cmd[1], cmd[2], cmd[3]); + } + + private static void processPickupCommand(Controller controller, String[] cmd) { + if (cmd.length != 3) + IO_Manager.writeError("pickup requires 2 parameters", Controller.filetoWrite != null); + else + controller.pickup(cmd[1], cmd[2]); + } + + private static void processPlaceDownCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("placedown requires 1 parameter", Controller.filetoWrite != null); + else + controller.placedown(cmd[1]); + } + + private static void processStateCommand(Controller controller, String[] cmd) { + if (cmd.length < 2) + IO_Manager.writeError("available commands are:\tstate get\tstate set", Controller.filetoWrite != null); + else if (cmd[1].equals("get")) { + if (cmd.length != 4) + IO_Manager.writeError("state get requires 2 parameters", Controller.filetoWrite != null); + else + controller.stateGet(cmd[2], cmd[3]); + } else if (cmd[1].equals("set")) { + if (cmd.length != 5) + IO_Manager.writeError("state set requires 3 parameters", Controller.filetoWrite != null); + else + controller.stateSet(cmd[2], cmd[3], cmd[4]); + } else { + IO_Manager.writeError("available commands are:\tstate get\tstate set", Controller.filetoWrite != null); + } + } + + private static void processNextTurnCommand(Controller controller, String[] cmd) { + if (cmd.length != 1) + IO_Manager.writeError("nextTurn requires no parameters", Controller.filetoWrite != null); + else + controller.nextTurn(); + } + + private static void processGenerateCommand(Controller controller, String[] cmd) { + if (cmd.length != 4) + IO_Manager.writeError("generate requires 3 parameters", Controller.filetoWrite != null); + else + controller.generate(cmd[1], cmd[2], cmd[3]); + } + + private static void processWaterFlowCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("waterFlow requires no parameters", Controller.filetoWrite != null); + else + controller.waterFlow(cmd[1]); + } + + private static void processSaveCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("save requires 1 parameter", Controller.filetoWrite != null); + else + controller.save(cmd[1]); + } + + private static void processLoadCommand(Controller controller, String[] cmd) { + if (cmd.length != 2) + IO_Manager.writeError("load requires 1 parameter", Controller.filetoWrite != null); + else + controller.load(cmd[1]); + } + + private static void processEndGameCommand(Controller controller, String[] cmd) { + if (cmd.length != 1) + IO_Manager.writeError("endGame requires no parameters", Controller.filetoWrite != null); + else + controller.endGame(); + } + + private static void processStartGameCommand(Controller controller, String[] cmd) { + if (cmd.length != 1) + IO_Manager.writeError("startGame requires no parameters", Controller.filetoWrite != null); + else + controller.startGame(); + } } diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index dce0d2d..fb5b8b9 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -121,44 +121,52 @@ public boolean PlayerEnter(Player player) { players.add(player); if (lubricated){ - SecureRandom random = new SecureRandom(); - int end = random.nextInt(1,2); - boolean ignoreState = Player.isIgnoreStates(); - Player.setIgnoreStates(true); - if(end == 1){ - player.getStandingOn().PlayerExit(player); - player.setStandingOn(null); - player.Move(nodes.getFirst()); - } - else if(end == 2){ - player.getStandingOn().PlayerExit(player); - player.setStandingOn(null); - player.Move(nodes.getLast()); - } - Player.setIgnoreStates(ignoreState); - players.remove(player); - if (player.getState() == PlayerActionState.MOVE_ACTION) - player.setState(PlayerActionState.SPECIAL_ACTION); - else if (player.getState() == PlayerActionState.SPECIAL_ACTION) { - player.setState(PlayerActionState.TURN_OVER); - Controller.getInstance().turnOver(); - } - lubricated = false; + handleLubricatedPlayer(player); successful = false; } if (glued) { - player.setStuck(true); - player.setGlueLength(1); - glued = false; - player.setState(PlayerActionState.TURN_OVER); - Controller.getInstance().turnOver(); + handleGluedPlayer(player); } } return successful; } + private void handleLubricatedPlayer(Player player) { + SecureRandom random = new SecureRandom(); + int end = random.nextInt(1, 3); // 1 or 2 + boolean ignoreState = Player.isIgnoreStates(); + Player.setIgnoreStates(true); + + player.getStandingOn().PlayerExit(player); + player.setStandingOn(null); + + if (end == 1) { + player.Move(nodes.getFirst()); + } else { + player.Move(nodes.getLast()); + } + + Player.setIgnoreStates(ignoreState); + players.remove(player); + if (player.getState() == PlayerActionState.MOVE_ACTION) { + player.setState(PlayerActionState.SPECIAL_ACTION); + } else if (player.getState() == PlayerActionState.SPECIAL_ACTION) { + player.setState(PlayerActionState.TURN_OVER); + Controller.getInstance().turnOver(); + } + lubricated = false; + } + + private void handleGluedPlayer(Player player) { + player.setStuck(true); + player.setGlueLength(1); + glued = false; + player.setState(PlayerActionState.TURN_OVER); + Controller.getInstance().turnOver(); + } + /** * Amennyiben a játékos leléphet a csőről, akkor * lekerül róla, és az eltávolítja a players attribútumából. diff --git a/src/main/java/Model/Pump.java b/src/main/java/Model/Pump.java index b07145e..64b6d58 100644 --- a/src/main/java/Model/Pump.java +++ b/src/main/java/Model/Pump.java @@ -53,7 +53,9 @@ public void setController(Controller controller) { * @param from melyik elemről vesszük le / csatlakoztatjuk le a pumpát */ @Override - public void PickedUp(Steppable from) {} + public void PickedUp(Steppable from) { + throw new UnsupportedOperationException(); + } /** * Pumpa letétele diff --git a/src/main/java/View/AppPanel.java b/src/main/java/View/AppPanel.java index 3dfd06f..dd670f8 100644 --- a/src/main/java/View/AppPanel.java +++ b/src/main/java/View/AppPanel.java @@ -10,14 +10,13 @@ */ public class AppPanel extends JPanel { - private MouseIn mouseIn=new MouseIn(); - /** * Konstruktor, beállítja a paramétereket */ public AppPanel(){ setFocusable(true); requestFocusInWindow(); + MouseIn mouseIn = new MouseIn(); addMouseListener(mouseIn); addMouseMotionListener(mouseIn); } diff --git a/src/main/java/View/CisternView.java b/src/main/java/View/CisternView.java index 44ca29a..31fd20b 100644 --- a/src/main/java/View/CisternView.java +++ b/src/main/java/View/CisternView.java @@ -14,8 +14,8 @@ */ public class CisternView extends Drawable implements Clickable, CreatePopUpBar, SteppableView { - private Cistern cistern; - private int r; + private final Cistern cistern; + private final int r; private GameView gameView = null; private BufferedImage sprite = null; diff --git a/src/main/java/View/GameView.java b/src/main/java/View/GameView.java index d48fbf1..bcccaf2 100644 --- a/src/main/java/View/GameView.java +++ b/src/main/java/View/GameView.java @@ -7,6 +7,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; +import java.io.Serializable; import java.util.LinkedList; import static View.Pictures.*; @@ -15,7 +16,7 @@ /** * A játék nézetét megvalósító osztály. */ -public class GameView extends Window { +public class GameView extends Window implements Serializable { /** * Map beállítása. @@ -38,7 +39,7 @@ public void mapSetup(String file) { protected PopUpBar popUpBar = null; protected PopUpBar cisternDisplay = null; private boolean ended = false; - private Button exit; + private final Button exit; private AppFrame frame; @@ -76,7 +77,7 @@ public void setStarted(boolean started) { } - private Object sync = new Object(); + private final Object sync = new Object(); /** * kirajzolás megvalósítása. @@ -134,7 +135,6 @@ else if (PointCounter.getInstance().GetMechanicPoints() == PointCounter.getInsta Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.BLACK); g2d.setFont(new Font("Inter", Font.BOLD, 20)); - AppFrame f = Controller.getInstance().getFrame(); g2d.drawString("Válaszd ki a két átirányítandó csövet!", 40, 40); } } @@ -194,12 +194,12 @@ public void mouseReleased(MouseEvent e) { @Override public void mouseEntered(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseExited(MouseEvent e) { - + // Not used, intentionally left blank } @Override diff --git a/src/main/java/View/Window.java b/src/main/java/View/Window.java index 36a72b3..fc2878f 100644 --- a/src/main/java/View/Window.java +++ b/src/main/java/View/Window.java @@ -14,7 +14,7 @@ /** * A játék ablakát reprezentáló osztály */ -public abstract class Window { +public abstract class Window implements Serializable { protected LinkedList drawables = new LinkedList<>(); protected LinkedList clickables = new LinkedList<>(); protected LinkedList components = new LinkedList<>(); From 877e6b482e6f0ef9f49523905ae40c45f163fa63 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Mon, 20 May 2024 23:06:38 +0200 Subject: [PATCH 12/24] More test to PumpTest and little renames --- src/main/java/Controller/Controller.java | 102 ++++++++--------- src/main/java/Model/Cistern.java | 22 ++-- src/main/java/Model/IO_Manager.java | 38 +++---- src/main/java/Model/Mechanic.java | 20 ++-- src/main/java/Model/PickupAble.java | 4 +- src/main/java/Model/Pipe.java | 74 ++++++------ src/main/java/Model/Player.java | 26 ++--- src/main/java/Model/PointCounter.java | 10 +- src/main/java/Model/Pump.java | 30 ++--- src/main/java/Model/Saboteur.java | 6 +- src/main/java/Model/Spring.java | 16 +-- src/main/java/Model/Steppable.java | 22 ++-- src/main/java/Model/WaterNode.java | 16 +-- src/main/java/View/AddPlayerButton.java | 2 - src/main/java/View/ChangeMaxPointButton.java | 4 +- src/main/java/View/GameView.java | 10 +- src/main/java/View/NewGameView.java | 2 +- src/test/java/model/PipeTest.java | 21 ++-- src/test/java/model/PumpTest.java | 112 +++++++++++++++---- 19 files changed, 298 insertions(+), 239 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index a284367..76e7877 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -28,35 +28,35 @@ static public Controller getInstance() { return controller; } - final String WrongAttr = "wrong attribute name"; - final String WrongPipe = "wrong pipe name"; - final String WrongPlayer = "wrong player name"; - final String WrongMech = "wrong mechanic name"; - final String fellDownStr = "fellDown"; - final String stuckStr = "stuck"; - final String standingOnStr = "standingOn"; - final String stateStr = "state"; - final String heldItemsStr = "heldItems"; - final String pipesStr = "pipes"; - final String createdPickupablesStr = "createdPickupables"; - final String playersStr = "players"; - final String saboteurPointsStr = "saboteurPoints"; - final String mechanicPointsStr = "mechanicPoints"; - final String pointsToWinStr = "pointsToWin"; - final String moveActionStr = "moveAction"; - final String specialActionStr = "specialAction"; - final String turnOverStr = "turnOver"; - final String brokenStr = "broken"; - final String waterCapacityStr = "waterCapacity"; - final String heldWaterStr = "heldWater"; - final String maximumPipesStr = "maximumPipes"; - final String activeInStr = "activeIn"; - final String activeOutStr = "activeOut"; - final String readyToPierceStr = "readyToPierce"; - final String lubricatedStr = "lubricated"; - final String gluedStr = "glued"; - final String beingHeldStr = "beingHeld"; - final String nodesStr = "nodes"; + final static String WrongAttr = "wrong attribute name"; + final static String WrongPipe = "wrong pipe name"; + final static String WrongPlayer = "wrong player name"; + final static String WrongMech = "wrong mechanic name"; + final static String fellDownStr = "fellDown"; + final static String stuckStr = "stuck"; + final static String standingOnStr = "standingOn"; + final static String stateStr = "state"; + final static String heldItemsStr = "heldItems"; + final static String pipesStr = "pipes"; + final static String createdPickupablesStr = "createdPickupables"; + final static String playersStr = "players"; + final static String saboteurPointsStr = "saboteurPoints"; + final static String mechanicPointsStr = "mechanicPoints"; + final static String pointsToWinStr = "pointsToWin"; + final static String moveActionStr = "moveAction"; + final static String specialActionStr = "specialAction"; + final static String turnOverStr = "turnOver"; + final static String brokenStr = "broken"; + final static String waterCapacityStr = "waterCapacity"; + final static String heldWaterStr = "heldWater"; + final static String maximumPipesStr = "maximumPipes"; + final static String activeInStr = "activeIn"; + final static String activeOutStr = "activeOut"; + final static String readyToPierceStr = "readyToPierce"; + final static String lubricatedStr = "lubricated"; + final static String gluedStr = "glued"; + final static String beingHeldStr = "beingHeld"; + final static String nodesStr = "nodes"; /** * Játék elkezdését mutató boolean */ @@ -293,7 +293,7 @@ public void connect(String pipeName, String wNodeName) { } WaterNode w = (WaterNode) objectCatalog.get(wNodeName); - if (w.AddPipe(p) && p.AddWaterNode(w)) { + if (w.addPipe(p) && p.addWaterNode(w)) { IO_Manager.write(pipeName + ".nodes = " + listWrite(p.getNodes()), Controller.filetoWrite != null); IO_Manager.write(wNodeName + ".pipes = " + listWrite(w.getPipes()), Controller.filetoWrite != null); } @@ -320,7 +320,7 @@ public void move(String playerName, String steppableName) { Steppable s = (Steppable) objectCatalog.get(steppableName); Steppable prev = p.getStandingOn(); - if (p.Move(s)) { + if (p.move(s)) { IO_Manager.write(steppableName + ".players = " + listWrite(s.getPlayers()), Controller.filetoWrite != null); IO_Manager.write(playerName + ".standingOn = " + steppableName, Controller.filetoWrite != null); if (prev != null) @@ -344,7 +344,7 @@ public void pierce(String playerName) { } Player p = (Player) objectCatalog.get(playerName); - if (p.Pierce()) + if (p.pierce()) IO_Manager.write(playerName + ".standingOn.broken = " + "true", Controller.filetoWrite != null); @@ -361,7 +361,7 @@ public void glue(String playerName) { } Player p = (Player) objectCatalog.get(playerName); - if (p.Glue()) + if (p.glue()) IO_Manager.write(playerName + ".standingOn.glued = " + "true", Controller.filetoWrite != null); @@ -380,7 +380,7 @@ public void lubricate(String saboteurName) { } Saboteur s = (Saboteur) objectCatalog.get(saboteurName); - if (s.Lubricate()) + if (s.lubricate()) IO_Manager.write(saboteurName + ".standingOn.lubricated = " + "true", Controller.filetoWrite != null); } @@ -396,7 +396,7 @@ public void repair(String mechanicName) { } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); - if (m.Repair()) { + if (m.repair()) { IO_Manager.write(mechanicName + ".standingOn.broken = false", Controller.filetoWrite != null); if (pipes.contains((Pipe) m.getStandingOn())) { IO_Manager.write(mechanicName + ".standingOn.readyToPierce = false", Controller.filetoWrite != null); @@ -431,7 +431,7 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { } Pipe out = (Pipe) objectCatalog.get(outPipeName); - if (p.Redirect(in, out)) { + if (p.redirect(in, out)) { IO_Manager.write(playerName + ".standingOn.activeIn = " + inPipeName, Controller.filetoWrite != null); IO_Manager.write(playerName + ".standingOn.activeOut = " + outPipeName, Controller.filetoWrite != null); } @@ -457,7 +457,7 @@ public void pickup(String mechanicName, String pickupName) { } PickupAble p = (PickupAble) objectCatalog.get(pickupName); - if (m.PickUp(p)) { + if (m.pickUp(p)) { IO_Manager.write(mechanicName + ".heldItems = " + pickupName, Controller.filetoWrite != null); } @@ -475,7 +475,7 @@ public void placedown(String mechanicName) { } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); - if (m.PlaceDown()) + if (m.placeDown()) IO_Manager.write(mechanicName + ".heldItems = null", Controller.filetoWrite != null); } @@ -544,9 +544,9 @@ public void stateGet(String objectName, String attribName) { } } else if (objectName.equals("counter")) { switch (attribName) { - case saboteurPointsStr -> output += Integer.toString(PointCounter.getInstance().GetSaboteurPoints()); - case mechanicPointsStr -> output += Integer.toString(PointCounter.getInstance().GetMechanicPoints()); - case pointsToWinStr -> output += Integer.toString(PointCounter.getInstance().GetPointsToWin()); + case saboteurPointsStr -> output += Integer.toString(PointCounter.getInstance().getSaboteurPoints()); + case mechanicPointsStr -> output += Integer.toString(PointCounter.getInstance().getMechanicPoints()); + case pointsToWinStr -> output += Integer.toString(PointCounter.getInstance().getPointsToWin()); default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); } } else { @@ -651,7 +651,7 @@ public void turnOver() { int chance = random.nextInt(0, nodes.size()); boolean ignoreStates = Player.isIgnoreStates(); Player.setIgnoreStates(true); - turnOrder.getFirst().Move(nodes.get(chance)); + turnOrder.getFirst().move(nodes.get(chance)); Player.setIgnoreStates(false); turnOrder.getFirst().setState(PlayerActionState.TURN_OVER); turnOver(); @@ -684,10 +684,10 @@ public void turnOver() { */ public void nextTurn() { for (WaterNode node : nodes) { - node.WaterFlow(); + node.waterFlow(); } for (Cistern cistern : cisterns) { - cistern.GeneratePickupables(); + cistern.generatePickupables(); } if (!deterministic) { for (Pump pump : pumps) { @@ -701,7 +701,7 @@ public void nextTurn() { } //end of game? if (started) { - if (counter.GetMechanicPoints() >= counter.GetPointsToWin() || counter.GetSaboteurPoints() >= counter.GetPointsToWin()) + if (counter.getMechanicPoints() >= counter.getPointsToWin() || counter.getSaboteurPoints() >= counter.getPointsToWin()) endGame(); } } @@ -719,7 +719,7 @@ public void generate(String cisternName, String pipeName, String pumpName) { } Cistern c = (Cistern) objectCatalog.get(cisternName); - c.GeneratePickupables(); + c.generatePickupables(); IO_Manager.write("This is pipe:" + pipeName); IO_Manager.write("This is pump:" + pumpName); @@ -738,7 +738,7 @@ public void waterFlow(String wNodeName) { } WaterNode w = (WaterNode) objectCatalog.get(wNodeName); - w.WaterFlow(); + w.waterFlow(); } @@ -807,8 +807,8 @@ public void endGame() { started = false; gameView.end(); IO_Manager.write("game over", Controller.filetoWrite != null); - IO_Manager.write("saboteurPoints = " + counter.GetSaboteurPoints(), Controller.filetoWrite != null); - IO_Manager.write("mechanicPoints = " + counter.GetMechanicPoints(), Controller.filetoWrite != null); + IO_Manager.write("saboteurPoints = " + counter.getSaboteurPoints(), Controller.filetoWrite != null); + IO_Manager.write("mechanicPoints = " + counter.getMechanicPoints(), Controller.filetoWrite != null); } /** @@ -845,10 +845,10 @@ public void startGame() { return; } for (Player p : players) { - p.RemovePlayer(); + p.removePlayer(); SecureRandom random = new SecureRandom(); int chance = random.nextInt(0, nodes.size()); - p.Move(nodes.get(chance)); + p.move(nodes.get(chance)); } for (Pipe p : pipes) { if (p.getNodes().getFirst() == null || p.getNodes().getLast() == null) { diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 77be89c..25166d0 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -44,7 +44,7 @@ public Cistern() { * @return a felvétel eredménye */ @Override - public boolean PickedUpFrom(PickupAble pickup) { + public boolean pickedUpFrom(PickupAble pickup) { generatedPumps.remove(pickup); generatedPipes.remove(pickup); boolean result = createdPickupables.remove(pickup); @@ -60,10 +60,10 @@ public boolean PickedUpFrom(PickupAble pickup) { * @return a felvétel eredménye(mivel ciszternára lehet csövet kötni ezért ez mindig kivitelezhető) */ @Override - public boolean PlacedDownTo(Pipe pickup) { + public boolean placedDownTo(Pipe pickup) { - AddPipe(pickup); - pickup.AddWaterNode(this); + addPipe(pickup); + pickup.addWaterNode(this); return true; } @@ -74,7 +74,7 @@ public boolean PlacedDownTo(Pipe pickup) { * @return a felvétel eredménye(mivel ciszternára nem lehet pumpát kötni ezért ez sose kivitelezhető) */ @Override - public boolean PlacedDownTo(Pump pickup) { + public boolean placedDownTo(Pump pickup) { IO_Manager.writeInfo("Can't place it here", Controller.filetoWrite != null); return false; } @@ -87,10 +87,10 @@ public boolean PlacedDownTo(Pump pickup) { * szerelők pontszáma. */ @Override - public void WaterFlow() { + public void waterFlow() { for (Pipe p : pipes) { - int lost = p.LoseWater(1); - counter.AddMechanicPoints(lost); + int lost = p.loseWater(1); + counter.addMechanicPoints(lost); IO_Manager.write(Controller.getInstance().getObjectName(p) + " lost " + lost, Controller.filetoWrite != null); } } @@ -98,7 +98,7 @@ public void WaterFlow() { /** * A generálás függvénye, ami random generál egy pumpát vagy csövet. Ha már van 3 generált akkor nem készít többet */ - public void GeneratePickupables() { + public void generatePickupables() { if (createdPickupables.size() > 3) return; SecureRandom rand = new SecureRandom(); @@ -115,8 +115,8 @@ public void GeneratePickupables() { Pipe pi = (Pipe) Controller.getInstance().getObjectCatalog().get(pipeName); createdPickupables.add(pi); generatedPipes.add(pi); - pi.AddWaterNode(this); - AddPipe(pi); + pi.addWaterNode(this); + addPipe(pi); GameView gameView = Controller.getInstance().getGameView(); PipeView pipeView = new PipeView( diff --git a/src/main/java/Model/IO_Manager.java b/src/main/java/Model/IO_Manager.java index 5b04c62..76e529f 100644 --- a/src/main/java/Model/IO_Manager.java +++ b/src/main/java/Model/IO_Manager.java @@ -6,35 +6,35 @@ //A ki és bemenet fájlba, illetve konzolra kiírásáért, beolvasásáért felelős osztály. public class IO_Manager { - static private FileWriter fw = null; - static private Scanner scanner = null; - static private Scanner stdScanner = null; + private static FileWriter fw = null; + private static Scanner scanner = null; + private static Scanner stdScanner = null; - static public boolean speak = true; + public static boolean speak = true; //Kiírja a text-et - static public void write(String text) { + public static void write(String text) { if (!speak) return; System.out.println("> " + text); } //Kiírja az erromessage-t - static public void writeError(String errorMessage) { + public static void writeError(String errorMessage) { if (!speak) return; System.out.println("ERROR: \"" + errorMessage + "\"" ); } //Kiírja a writeinfo-t - static public void writeInfo(String info) { + public static void writeInfo(String info) { if (!speak) return; System.out.println("INFO: \"" + info + "\"" ); } //Fájlba írja a text-et. - static public void writeFile(String text) { + public static void writeFile(String text) { if (!speak) return; try { @@ -44,7 +44,7 @@ static public void writeFile(String text) { } } - static public void writeErrorFile(String errorMessage) { + public static void writeErrorFile(String errorMessage) { if (!speak) return; try { @@ -54,7 +54,7 @@ static public void writeErrorFile(String errorMessage) { } } - static public void writeInfoFile(String info) { + public static void writeInfoFile(String info) { if (!speak) return; try { @@ -65,19 +65,19 @@ static public void writeInfoFile(String info) { } //Beolvas egy sort. - static public String readLine() { + public static String readLine() { if (stdScanner == null) stdScanner = new Scanner(System.in); return stdScanner.nextLine(); } //Befejezi az olvasást. - static public void endReading() { + public static void endReading() { stdScanner.close(); } //Beolvas egy sort a fájlból. - static public String readLineFile() { + public static String readLineFile() { if (scanner.hasNext()) return scanner.nextLine(); else @@ -85,7 +85,7 @@ static public String readLineFile() { } //A FileWriter létrehozása. - static public void openFileWrite(String filename) { + public static void openFileWrite(String filename) { try { fw = new FileWriter(filename); } catch (IOException ioe) { @@ -94,7 +94,7 @@ static public void openFileWrite(String filename) { } //A fájl becsukása. - static public void closeFile() { + public static void closeFile() { try { if (fw != null) { fw.close(); @@ -111,7 +111,7 @@ static public void closeFile() { } //Megnyitja a fájlt olvasásra. - static public void openFileRead(String filename) { + public static void openFileRead(String filename) { try { scanner = new Scanner(new File(filename)); } catch (FileNotFoundException e) { @@ -119,7 +119,7 @@ static public void openFileRead(String filename) { } } - static public void write(String text, boolean toFile) { + public static void write(String text, boolean toFile) { if (!speak) return; if (toFile) @@ -128,7 +128,7 @@ static public void write(String text, boolean toFile) { write(text); } - static public void writeInfo(String info, boolean toFile) { + public static void writeInfo(String info, boolean toFile) { if (!speak) return; if (toFile) @@ -137,7 +137,7 @@ static public void writeInfo(String info, boolean toFile) { writeInfo(info); } - static public void writeError(String errorMessage, boolean toFile) { + public static void writeError(String errorMessage, boolean toFile) { if (!speak) return; if (toFile) diff --git a/src/main/java/Model/Mechanic.java b/src/main/java/Model/Mechanic.java index d469cf1..fe5c9cf 100644 --- a/src/main/java/Model/Mechanic.java +++ b/src/main/java/Model/Mechanic.java @@ -16,13 +16,13 @@ public class Mechanic extends Player implements Serializable { /** * Pályaelem megjavítására használt függvény, ha specialAction-ben van a játékos, akkor javít. */ - public boolean Repair() { + public boolean repair() { boolean repaired=false; if(isIgnoreStates()) { - repaired = standingOn.Repaired(); + repaired = standingOn.repaired(); } else if(state == PlayerActionState.SPECIAL_ACTION) { - repaired = standingOn.Repaired(); + repaired = standingOn.repaired(); if (repaired) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); @@ -37,20 +37,20 @@ else if(state == PlayerActionState.SPECIAL_ACTION) { * Pályaelem felvételére használt függvény, a felvett pályaelemet a játékosnak beadjuk, és csak akkor tudja felvenni ha mellette áll * @param item - felvett pályaelem */ - public boolean PickUp(PickupAble item) { + public boolean pickUp(PickupAble item) { boolean pickedup=false; if(isIgnoreStates()) { - pickedup = standingOn.PickedUpFrom(item); + pickedup = standingOn.pickedUpFrom(item); } else if(state == PlayerActionState.SPECIAL_ACTION) { - pickedup = standingOn.PickedUpFrom(item); + pickedup = standingOn.pickedUpFrom(item); if (pickedup) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } if (pickedup) { - item.PickedUp(standingOn); + item.pickedUp(standingOn); heldItems = item; } else @@ -63,14 +63,14 @@ else if(state == PlayerActionState.SPECIAL_ACTION) { * Pályaelem lerakására használt függvény. * Változott az előző dokumentum óta, nem kell paraméter hiszen csak saját attribútumot kezel. */ - public boolean PlaceDown() { + public boolean placeDown() { boolean successful = false; if(isIgnoreStates()) { - successful = heldItems.PlacedDown(standingOn); + successful = heldItems.placedDown(standingOn); } else if(state == PlayerActionState.SPECIAL_ACTION) { - successful = heldItems.PlacedDown(standingOn); + successful = heldItems.placedDown(standingOn); if (successful) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); diff --git a/src/main/java/Model/PickupAble.java b/src/main/java/Model/PickupAble.java index 420d045..c8cb73e 100644 --- a/src/main/java/Model/PickupAble.java +++ b/src/main/java/Model/PickupAble.java @@ -10,14 +10,14 @@ public interface PickupAble extends Serializable { * Elem felvétele egy másik elemről * @param from melyik elemről vesszük le / csatlakoztatjuk le */ - void PickedUp(Steppable from); + void pickedUp(Steppable from); /** * Elem letétele egy másik elemre, az előző dokumentumhoz képest van visszatérési értéke * @param to melyik elemre tesszük le / csatlakoztatjuk rá * @return a letétel sikeressége */ - boolean PlacedDown(Steppable to); + boolean placedDown(Steppable to); /** * Elemet fel lehet-e venni onnan amit átadunk diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index fb5b8b9..91b7341 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -69,7 +69,7 @@ public Pipe(PointCounter pointCounter) { * @param from melyik elemről vesszük le / csatlakoztatjuk le */ @Override - public void PickedUp(Steppable from) { + public void pickedUp(Steppable from) { if(nodes.contains(from)) { int pickupIdx = nodes.indexOf(from); if (pickupIdx != -1) { @@ -80,7 +80,7 @@ public void PickedUp(Steppable from) { IO_Manager.writeInfo(Controller.getInstance().getObjectName(players.getFirst()) + " is fallen off", Controller.filetoWrite != null); players.getFirst().setFellDown(true); } - counter.AddSaboteurPoints(heldWater); + counter.addSaboteurPoints(heldWater); heldWater = 0; } } @@ -93,8 +93,8 @@ public void PickedUp(Steppable from) { * @return igaz, ha sikeres a letétel */ @Override - public boolean PlacedDown(Steppable to) { - if (to.PlacedDownTo(this)) { + public boolean placedDown(Steppable to) { + if (to.placedDownTo(this)) { beingHeld = false; return true; } @@ -109,7 +109,7 @@ public boolean PlacedDown(Steppable to) { * @return a lépés sikeressége */ @Override - public boolean PlayerEnter(Player player) { + public boolean playerEnter(Player player) { if (!players.isEmpty()) { IO_Manager.writeInfo("Can't move to " + Controller.getInstance().getObjectName(this) + ", " + Controller.getInstance().getObjectName(players.getFirst()) + " is standing on it", Controller.filetoWrite != null); @@ -139,13 +139,13 @@ private void handleLubricatedPlayer(Player player) { boolean ignoreState = Player.isIgnoreStates(); Player.setIgnoreStates(true); - player.getStandingOn().PlayerExit(player); + player.getStandingOn().playerExit(player); player.setStandingOn(null); if (end == 1) { - player.Move(nodes.getFirst()); + player.move(nodes.getFirst()); } else { - player.Move(nodes.getLast()); + player.move(nodes.getLast()); } Player.setIgnoreStates(ignoreState); @@ -173,7 +173,7 @@ private void handleGluedPlayer(Player player) { * @param player a mezőről lelépő játékos */ @Override - public void PlayerExit(Player player) { + public void playerExit(Player player) { players.remove(player); } @@ -183,7 +183,7 @@ public void PlayerExit(Player player) { * @return mindig hamis, mivel csőről nem vehetünk fel semmit */ @Override - public boolean PickedUpFrom(PickupAble pickup) { + public boolean pickedUpFrom(PickupAble pickup) { return false; } @@ -195,8 +195,8 @@ public boolean PickedUpFrom(PickupAble pickup) { * @return lerakás sikeressége */ @Override - public boolean PlacedDownTo(Pump pickup) { - CutInHalf(pickup); + public boolean placedDownTo(Pump pickup) { + cutInHalf(pickup); return true; } @@ -207,7 +207,7 @@ public boolean PlacedDownTo(Pump pickup) { * @return hamis, mivel nem lehet csövet csőre rakni */ @Override - public boolean PlacedDownTo(Pipe pickup) { + public boolean placedDownTo(Pipe pickup) { return false; } @@ -217,7 +217,7 @@ public boolean PlacedDownTo(Pipe pickup) { * @param pump lerakandó pumpa */ @Override - public void CutInHalf(Pump pump) { + public void cutInHalf(Pump pump) { String newP1="GenPipe"+ Controller.getInstance().createdPipeNumber++; String newP2="GenPipe"+Controller.getInstance().createdPipeNumber++; @@ -226,11 +226,11 @@ public void CutInHalf(Pump pump) { Pipe newPipe1 =((Pipe)Controller.getInstance().getObjectCatalog().get(newP1)); Pipe newPipe2 =((Pipe)Controller.getInstance().getObjectCatalog().get(newP2)); - newPipe1.AddWaterNode(pump); - newPipe2.AddWaterNode(pump); + newPipe1.addWaterNode(pump); + newPipe2.addWaterNode(pump); - pump.AddPipe(newPipe1); - pump.AddPipe(newPipe2); + pump.addPipe(newPipe1); + pump.addPipe(newPipe2); Player player=players.getFirst(); int x=Controller.getInstance().getGameView().getDrawableByCorrespondingModel(player).getX(); @@ -243,14 +243,14 @@ public void CutInHalf(Pump pump) { WaterNode node1 = nodes.getFirst(); WaterNode node2 = nodes.getLast(); - node1.RemovePipe(this); - node1.AddPipe(newPipe1); + node1.removePipe(this); + node1.addPipe(newPipe1); - node2.AddPipe(newPipe2); - node2.RemovePipe(this); + node2.addPipe(newPipe2); + node2.removePipe(this); - newPipe1.AddWaterNode(node1); - newPipe2.AddWaterNode(node2); + newPipe1.addWaterNode(node1); + newPipe2.addWaterNode(node2); Pipe node1activeIn = node1.getActiveIn(); Pipe node1activeOut = node1.getActiveOut(); @@ -286,7 +286,7 @@ public void CutInHalf(Pump pump) { boolean ignoreStates = Player.isIgnoreStates(); Player.setIgnoreStates(true); - player.Move(newPipe1); + player.move(newPipe1); Player.setIgnoreStates(ignoreStates); Controller.getInstance().removeObject(this); @@ -321,7 +321,7 @@ public void CutInHalf(Pump pump) { * @return igaz, ha nem volt eleve törött a cső */ @Override - public boolean Pierced() { + public boolean pierced() { if (broken) { IO_Manager.writeInfo(Controller.getInstance().getObjectName(this) + " is already broken", Controller.filetoWrite != null); return false; @@ -342,10 +342,10 @@ public boolean Pierced() { * @param amount beérkező víz mennyiség * @return amennyivel ténylegesen nőtt a cső tartalma */ - public int GainWater(int amount) { + public int gainWater(int amount) { if (broken || beingHeld) { - counter.AddSaboteurPoints(amount); + counter.addSaboteurPoints(amount); return 0; } else { @@ -363,7 +363,7 @@ public int GainWater(int amount) { * @param amount csökkenteni kívánt mennyiség * @return ténylegesen vesztett vízmennyiség */ - public int LoseWater(int amount) { + public int loseWater(int amount) { int lost = Math.min(heldWater, amount); heldWater -= lost; return lost; @@ -375,7 +375,7 @@ public int LoseWater(int amount) { * @param w hozzáadandó elem * @return igaz, ha sikeres a hozzáadás */ - public boolean AddWaterNode(WaterNode w) { + public boolean addWaterNode(WaterNode w) { if (nodes.size() > 1) { return false; } @@ -384,19 +384,11 @@ public boolean AddWaterNode(WaterNode w) { } - /** - * Végpont lecsatolása a csőről - * @param w lecsatolandó elem - */ - public void RemoveWaterNode(WaterNode w) { - nodes.remove(w); - } - /** * Ragasztáskor lefutó függvény, ami megmondja hogy lehetett-e ragasztani * @return sikeresség */ - public boolean Glued(){ + public boolean glued(){ if(glued){ return false; } @@ -409,7 +401,7 @@ public boolean Glued(){ * Csúszósításkor lefutó függvény, ami megmondja hogy lehetett-e csúszósítani * @return sikeresség */ - public boolean Lubricated(){ + public boolean lubricated(){ if(lubricated){ return false; } @@ -433,7 +425,7 @@ public boolean canMoveFromHere() { * @return sikeres-e a javítás */ @Override - public boolean Repaired(){ + public boolean repaired(){ if(broken){ broken = false; readyToPierce = false; diff --git a/src/main/java/Model/Player.java b/src/main/java/Model/Player.java index 0b85a27..0073645 100644 --- a/src/main/java/Model/Player.java +++ b/src/main/java/Model/Player.java @@ -49,7 +49,7 @@ public abstract class Player implements Serializable { * Mozgás egyik elemről a másik, szomszédosra, figyelembe véve az ignoreStates flaget, és azt, hogy a játékos action-t végezhet * @param to amire szeretni lépni */ - public boolean Move(Steppable to) { + public boolean move(Steppable to) { removed=false; if(!ignoreStates && state==PlayerActionState.TURN_OVER) @@ -65,7 +65,7 @@ public boolean Move(Steppable to) { return false; } - if (to.PlayerEnter(this)) { + if (to.playerEnter(this)) { if (standingOn != null) { if (!ignoreStates && state == PlayerActionState.MOVE_ACTION) @@ -74,7 +74,7 @@ else if (!ignoreStates && state == PlayerActionState.SPECIAL_ACTION) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } - standingOn.PlayerExit(this); + standingOn.playerExit(this); } standingOn = to; @@ -89,9 +89,9 @@ else if (!ignoreStates && state == PlayerActionState.SPECIAL_ACTION) { /** * Játékos eltávolítása a pályáról(CutInHalf-hez is) */ - public void RemovePlayer(){ + public void removePlayer(){ if(standingOn != null){ - standingOn.PlayerExit(this); + standingOn.playerExit(this); } standingOn = null; removed=true; @@ -102,11 +102,11 @@ public void RemovePlayer(){ * @param in bemeneti cső * @param out kimeneti cső */ - public boolean Redirect(Pipe in, Pipe out) { + public boolean redirect(Pipe in, Pipe out) { if (state != PlayerActionState.SPECIAL_ACTION) return false; - if (standingOn.PlayerRedirect(in, out)) { + if (standingOn.playerRedirect(in, out)) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); return true; @@ -118,13 +118,13 @@ public boolean Redirect(Pipe in, Pipe out) { /** * Kilyukasztja (amennyiben nem lyukas, és lyukasztható) azt az elemet, amin jelenleg a szabotőr áll */ - public boolean Pierce() { + public boolean pierce() { boolean pierced=false; if(ignoreStates) { - pierced = standingOn.Pierced(); + pierced = standingOn.pierced(); } else if(state == PlayerActionState.SPECIAL_ACTION) { - pierced = standingOn.Pierced(); + pierced = standingOn.pierced(); if (pierced) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); @@ -136,13 +136,13 @@ else if(state == PlayerActionState.SPECIAL_ACTION) { /** * Ragacsossá teszi (amennyiben nem ragacsos) azt az elemet, amin jelenleg a szabotőr áll */ - public boolean Glue(){ + public boolean glue(){ boolean glued = false; if(ignoreStates) { - glued = standingOn.Glued(); + glued = standingOn.glued(); } else if(state == PlayerActionState.SPECIAL_ACTION) { - glued = standingOn.Glued(); + glued = standingOn.glued(); if (glued) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); diff --git a/src/main/java/Model/PointCounter.java b/src/main/java/Model/PointCounter.java index 58a0151..993b1cd 100644 --- a/src/main/java/Model/PointCounter.java +++ b/src/main/java/Model/PointCounter.java @@ -34,14 +34,14 @@ static public PointCounter getInstance() { /** * @param amount az a mennyiség, amivel a szabotőrök pontjai nőnek */ - public void AddSaboteurPoints(int amount) { + public void addSaboteurPoints(int amount) { saboteurPoints+=amount; } /** * @param amount az a mennyiség, amivel a szerelők pontjai nőnek */ - public void AddMechanicPoints(int amount) { + public void addMechanicPoints(int amount) { mechanicPoints+=amount; } @@ -49,7 +49,7 @@ public void AddMechanicPoints(int amount) { * A szabotőrök pontjainak gettere * @return a pontok */ - public int GetSaboteurPoints(){ + public int getSaboteurPoints(){ return saboteurPoints; } @@ -57,7 +57,7 @@ public int GetSaboteurPoints(){ * A szerelők pontjainak gettere * @return a pontok */ - public int GetMechanicPoints(){ + public int getMechanicPoints(){ return mechanicPoints; } @@ -65,7 +65,7 @@ public int GetMechanicPoints(){ * A győzelemhez szükséges pontok gettere * @return a pontok */ - public int GetPointsToWin(){ return pointsToWin;} + public int getPointsToWin(){ return pointsToWin;} /** * A győzelemhez szükséges pontok settere diff --git a/src/main/java/Model/Pump.java b/src/main/java/Model/Pump.java index 64b6d58..4431fa4 100644 --- a/src/main/java/Model/Pump.java +++ b/src/main/java/Model/Pump.java @@ -53,7 +53,7 @@ public void setController(Controller controller) { * @param from melyik elemről vesszük le / csatlakoztatjuk le a pumpát */ @Override - public void PickedUp(Steppable from) { + public void pickedUp(Steppable from) { throw new UnsupportedOperationException(); } @@ -63,8 +63,8 @@ public void PickedUp(Steppable from) { * @return ha sikerül letenni, akkor true-val tér vissza, különben false-szal */ @Override - public boolean PlacedDown(Steppable to) { - return to.PlacedDownTo(this); + public boolean placedDown(Steppable to) { + return to.placedDownTo(this); } /** * A pickup felvétele a pumpárópl @@ -72,7 +72,7 @@ public boolean PlacedDown(Steppable to) { * @return amennyiben az elemet sikeresen felvették true-val tér vissza, különben false-szal */ @Override - public boolean PickedUpFrom(PickupAble pickup) { + public boolean pickedUpFrom(PickupAble pickup) { int pickupIdx = pipes.indexOf(pickup); if (pickupIdx != -1) { @@ -95,10 +95,10 @@ public boolean PickedUpFrom(PickupAble pickup) { * @return amennyiben sikeresen le lehet helyezni a csövet a pumpára true-val tér vissza, különben false-szal */ @Override - public boolean PlacedDownTo(Pipe pickup) { - boolean successful = AddPipe(pickup); + public boolean placedDownTo(Pipe pickup) { + boolean successful = addPipe(pickup); if (successful) - pickup.AddWaterNode(this); + pickup.addWaterNode(this); return successful; } @@ -108,7 +108,7 @@ public boolean PlacedDownTo(Pipe pickup) { * @return mindig false-szal tér vissza, hiszen pump-ra nem lehet másik pump-ot helyezni */ @Override - public boolean PlacedDownTo(Pump pickup) { + public boolean placedDownTo(Pump pickup) { IO_Manager.writeInfo("Can't place it here", Controller.filetoWrite != null); return false; } @@ -117,7 +117,7 @@ public boolean PlacedDownTo(Pump pickup) { * a vízfolyás függvénye, először átadja a vizet a kimenő csőnek, ha a pumpa nem romlott, vagy a tárolója nem üres, majd elveszi a vizet a bemeneti csőtől */ @Override - public void WaterFlow() { + public void waterFlow() { if (broken) { IO_Manager.writeInfo(controller.getObjectName(this) + " is broken", controller.filetoWrite != null); @@ -125,7 +125,7 @@ public void WaterFlow() { int gained=0; if(!broken && heldWater != 0 && activeOut != null) { - gained= activeOut.GainWater(1); + gained= activeOut.gainWater(1); if(gained==1){ heldWater--; } @@ -136,9 +136,9 @@ public void WaterFlow() { if (activeIn != null) { - int lost = activeIn.LoseWater(1); + int lost = activeIn.loseWater(1); int excess = (heldWater + lost > waterCapacity) ? (heldWater + lost - waterCapacity) : 0; - activeIn.GainWater(excess); + activeIn.gainWater(excess); heldWater +=lost-excess; IO_Manager.write(controller.getObjectName(activeIn) + " lost " + (lost - excess), controller.filetoWrite != null); } @@ -152,7 +152,7 @@ public void WaterFlow() { * különben false-szal */ @Override - public boolean PlayerRedirect(Pipe in, Pipe out) { + public boolean playerRedirect(Pipe in, Pipe out) { if(pipes.contains(in) && pipes.contains(out)) { activeIn = in; activeOut = out; @@ -227,7 +227,7 @@ boolean canBePlacedDown(Pump p) { * @return ha sikerült a csövet a pumpára kötni, akkor true-val tér vissza, különben false-szal */ @Override - public boolean AddPipe(Pipe p) { + public boolean addPipe(Pipe p) { boolean valid = pipes.size() < maximumPipes; if(valid) pipes.add(p); @@ -243,7 +243,7 @@ public boolean AddPipe(Pipe p) { * @return sikeresség */ @Override - public boolean Repaired(){ + public boolean repaired(){ if(broken){ broken = false; return true; diff --git a/src/main/java/Model/Saboteur.java b/src/main/java/Model/Saboteur.java index 84f61b4..7bd8fdb 100644 --- a/src/main/java/Model/Saboteur.java +++ b/src/main/java/Model/Saboteur.java @@ -13,13 +13,13 @@ public class Saboteur extends Player implements Serializable { * Csúszóssá teszi azt amin áll, ha tudja, meghívja azon pályaelem Lubricated függvényét. * @return sikeresség */ - public boolean Lubricate(){ + public boolean lubricate(){ boolean lubricated=false; if(isIgnoreStates()) { - lubricated = standingOn.Lubricated(); + lubricated = standingOn.lubricated(); } else if(state == PlayerActionState.SPECIAL_ACTION) { - lubricated = standingOn.Lubricated(); + lubricated = standingOn.lubricated(); if (lubricated) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); diff --git a/src/main/java/Model/Spring.java b/src/main/java/Model/Spring.java index 2779606..f011665 100644 --- a/src/main/java/Model/Spring.java +++ b/src/main/java/Model/Spring.java @@ -15,7 +15,7 @@ public class Spring extends WaterNode implements Serializable { * @return amennyiben az adott elemet fel lehet venni a forrásról true-val tér vissza, különben false-szal */ @Override - public boolean PickedUpFrom(PickupAble pickup) { + public boolean pickedUpFrom(PickupAble pickup) { int pickupIdx = pipes.indexOf(pickup); if (pickupIdx != -1) { @@ -31,10 +31,10 @@ public boolean PickedUpFrom(PickupAble pickup) { * @return amennyiben sikeresen le lehet helyezni a forrásra a csövet, true-val tér vissza, különben false-szal */ @Override - public boolean PlacedDownTo(Pipe pickup) { - boolean successful = AddPipe(pickup); + public boolean placedDownTo(Pipe pickup) { + boolean successful = addPipe(pickup); if (successful) - pickup.AddWaterNode(this); + pickup.addWaterNode(this); return successful; } @@ -45,7 +45,7 @@ public boolean PlacedDownTo(Pipe pickup) { * @return false-szal tér vissza, mivel egy forrásra nem lehet pumpát helyezni */ @Override - public boolean PlacedDownTo(Pump pickup) { + public boolean placedDownTo(Pump pickup) { IO_Manager.writeInfo("Can't place it here", Controller.filetoWrite != null); return false; } @@ -87,9 +87,9 @@ public boolean canPlaceDown(Mechanic m){ * A vízfolyással foglalkozik, a rákötött csőnek ad egy egységnyi vizet */ @Override - public void WaterFlow() { + public void waterFlow() { if(pipes.getFirst()!=null) { - int gained = pipes.getFirst().GainWater(1); + int gained = pipes.getFirst().gainWater(1); IO_Manager.write(Controller.getInstance().getObjectName(pipes.get(0)) + " gained " + gained, Controller.filetoWrite != null); } } @@ -99,7 +99,7 @@ public void WaterFlow() { * @return ha a forrásra még nincsen cső kötve, akkor rákötik a forrásra, és visszatér true-val, különben false-szal */ @Override - public boolean AddPipe(Pipe p) { + public boolean addPipe(Pipe p) { boolean valid = pipes.size() < 1; if (valid) pipes.add(p); diff --git a/src/main/java/Model/Steppable.java b/src/main/java/Model/Steppable.java index c35bb7b..d709928 100644 --- a/src/main/java/Model/Steppable.java +++ b/src/main/java/Model/Steppable.java @@ -18,13 +18,13 @@ public abstract class Steppable implements Serializable { * @return sikeres / sikertelen a belépési kísérlet * Alapesetben false-szal tér vissza, a leszármazottakban overrideolva van. */ - public boolean PlayerEnter(Player player) { return false; } + public boolean playerEnter(Player player) { return false; } /** * A függvény az adott játékos lelépési szándékát adja meg, leszármazottakban történik a megvalósítása. * @param player a mezőről lelépő játékos */ - public void PlayerExit(Player player) {} + public void playerExit(Player player) {} /** * Az adott elem ki- és bemeneti állapotát állítja be, leszármazottakban megvalósítás. @@ -33,7 +33,7 @@ public void PlayerExit(Player player) {} * @param out kimeneti állapot * @return az átirányítás sikeressége */ - public boolean PlayerRedirect(Pipe in, Pipe out) { + public boolean playerRedirect(Pipe in, Pipe out) { return false; } @@ -43,7 +43,7 @@ public boolean PlayerRedirect(Pipe in, Pipe out) { * @return sikeres / sikertelen volt az elem felvétele a pályáról * Absztrakt függvény, leszármazottakban van a megvalósítása. */ - public abstract boolean PickedUpFrom(PickupAble pickup); + public abstract boolean pickedUpFrom(PickupAble pickup); /** * Pipe letétele erre az objektumra @@ -51,14 +51,14 @@ public boolean PlayerRedirect(Pipe in, Pipe out) { * @return lerakás sikeressége * Absztrakt, leszármazottakban van a megvalósítása. */ - public abstract boolean PlacedDownTo(Pipe pickup); + public abstract boolean placedDownTo(Pipe pickup); /** * Pump letétele erre az objektumra * @param pickup a Pump amit le akarunk rakni * @return lerakás sikeressége */ - public abstract boolean PlacedDownTo(Pump pickup); + public abstract boolean placedDownTo(Pump pickup); //oopsie, itt amúgy a paraméter Pump, nem Pipe ahogy a doksiban van @@ -66,19 +66,19 @@ public boolean PlayerRedirect(Pipe in, Pipe out) { * Leszármazottban valósul meg a funkciója * @param pump lerakandó pumpa */ - public void CutInHalf(Pump pump) {} + public void cutInHalf(Pump pump) {} //Pályelem lyukasztása, alapesetben false-szal tér vissza, Pipe osztályban overrideolva van. - public boolean Pierced() { return false; } + public boolean pierced() { return false; } //Pályaelem megjavítása, mindig false-szal tér vissza, a Cistern és Spring osztályok kivételével overrideolva van a leszármazottakban. - public boolean Repaired() { return false; } + public boolean repaired() { return false; } //Ragacsossá tétel függvénye, ami itt mindig hamissal tér vissza, a Pipe osztályban override-olva van. - public boolean Glued(){return false;} + public boolean glued(){return false;} //Csúszóssá tétel függvénye, ami itt mindig hamissal tér vissza, a Pipe osztályban override-olva van. - public boolean Lubricated(){return false;} + public boolean lubricated(){return false;} /** * Aktív bemenet megadása diff --git a/src/main/java/Model/WaterNode.java b/src/main/java/Model/WaterNode.java index 3718f09..2cfa186 100644 --- a/src/main/java/Model/WaterNode.java +++ b/src/main/java/Model/WaterNode.java @@ -21,7 +21,7 @@ public abstract class WaterNode extends Steppable implements Serializable { * @return a lépés sikeressége */ @Override - public boolean PlayerEnter(Player player) { + public boolean playerEnter(Player player) { boolean successful = pipes.contains(player.getStandingOn()) || player.getStandingOn() == null; if (successful) @@ -38,7 +38,7 @@ public boolean PlayerEnter(Player player) { * @param player a mezőről lelépő játékos */ @Override - public void PlayerExit(Player player) { + public void playerExit(Player player) { players.remove(player); } @@ -48,33 +48,33 @@ public void PlayerExit(Player player) { * @param pickup az adott elem, amit fel akarunk venni * @return ha sikerült felvenni, akkor true-val tér vissza, különben false-sal */ - public abstract boolean PickedUpFrom(PickupAble pickup); + public abstract boolean pickedUpFrom(PickupAble pickup); /** * Egy cső letétele erre az objektumra. Létezik pumpa letételére is ez a függvény. * @param pickup a Pipe amit le akarunk rakni * @return ha sikerült lerakni, akkor true-val tér vissza, különben false-sal */ - public abstract boolean PlacedDownTo(Pipe pickup); + public abstract boolean placedDownTo(Pipe pickup); /** * Egy pumpa letétele erre az objektumra. Létezik cső letételére is ez a függvény. * @param pickup a Pump amit le akarunk rakni * @return ha sikerült lerakni, akkor true-val tér vissza, különben false-sal */ - public abstract boolean PlacedDownTo(Pump pickup); + public abstract boolean placedDownTo(Pump pickup); /** * Víz folyatása ebben a végpontban, absztrakt metódus. */ - public abstract void WaterFlow(); + public abstract void waterFlow(); /** * Cső hozzáadása a WaterNode-hoz * @param p hozzáadandó cső * @return ha sikerült hozzáadni a csövet a WaterNode-hoz, akkor true-val tér vissza, különben false-sal */ - public boolean AddPipe(Pipe p) { + public boolean addPipe(Pipe p) { pipes.add(p); return true; @@ -84,7 +84,7 @@ public boolean AddPipe(Pipe p) { * Cső leválasztása a WaterNode-ról * @param p leválasztandó cső */ - public void RemovePipe(Pipe p) { + public void removePipe(Pipe p) { pipes.remove(p); } diff --git a/src/main/java/View/AddPlayerButton.java b/src/main/java/View/AddPlayerButton.java index d5cc643..59b9ebd 100644 --- a/src/main/java/View/AddPlayerButton.java +++ b/src/main/java/View/AddPlayerButton.java @@ -1,8 +1,6 @@ package View; import Controller.Controller; -import Model.PointCounter; - import java.awt.event.MouseEvent; /** diff --git a/src/main/java/View/ChangeMaxPointButton.java b/src/main/java/View/ChangeMaxPointButton.java index df6d4dd..e9ba306 100644 --- a/src/main/java/View/ChangeMaxPointButton.java +++ b/src/main/java/View/ChangeMaxPointButton.java @@ -34,10 +34,10 @@ public void clickAction(MouseEvent e) { int increment = 10; if (type == 1) { // ha növelni kell - int temp = PointCounter.getInstance().GetPointsToWin() + type * increment; + int temp = PointCounter.getInstance().getPointsToWin() + type * increment; PointCounter.getInstance().setPointsToWin(temp); } else if (type == -1) { // ha csökkenteni kell - int temp = PointCounter.getInstance().GetPointsToWin() + type * increment; + int temp = PointCounter.getInstance().getPointsToWin() + type * increment; if (temp > 0) { // ha a pontszám nem negatív PointCounter.getInstance().setPointsToWin(temp); } diff --git a/src/main/java/View/GameView.java b/src/main/java/View/GameView.java index bcccaf2..2d7b0dd 100644 --- a/src/main/java/View/GameView.java +++ b/src/main/java/View/GameView.java @@ -97,11 +97,11 @@ public void paint(Graphics g) { graphics2D.fillRect(Controller.getInstance().getFrame().getWidth() - 1100 + 2, -20, 1100, 98); g.setColor(Color.ORANGE); g.setFont(new Font("Inter", Font.BOLD, 50)); - if (PointCounter.getInstance().GetMechanicPoints() > PointCounter.getInstance().GetSaboteurPoints()) + if (PointCounter.getInstance().getMechanicPoints() > PointCounter.getInstance().getSaboteurPoints()) g.drawString("A SZERELŐK NYERTEK!", Controller.getInstance().getFrame().getWidth() - 1050, 55); - else if (PointCounter.getInstance().GetMechanicPoints() < PointCounter.getInstance().GetSaboteurPoints()) + else if (PointCounter.getInstance().getMechanicPoints() < PointCounter.getInstance().getSaboteurPoints()) g.drawString("A SZABOTŐRÖK NYERTEK!", Controller.getInstance().getFrame().getWidth() - 1050, 55); - else if (PointCounter.getInstance().GetMechanicPoints() == PointCounter.getInstance().GetSaboteurPoints()) + else if (PointCounter.getInstance().getMechanicPoints() == PointCounter.getInstance().getSaboteurPoints()) g.drawString("DÖNTETLEN", Controller.getInstance().getFrame().getWidth() - 1050, 55); } else { @@ -112,9 +112,9 @@ else if (PointCounter.getInstance().GetMechanicPoints() == PointCounter.getInsta } g.setColor(Color.BLACK); g.setFont(new Font("Inter", Font.BOLD, 50)); - g.drawString(Integer.toString(PointCounter.getInstance().GetMechanicPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 50, 55); + g.drawString(Integer.toString(PointCounter.getInstance().getMechanicPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 50, 55); g.drawImage(ImageUtility.scaleImage(getScoreDivider(), 35), Controller.getInstance().getFrame().getWidth() - 300, 20, null); - g.drawString(Integer.toString(PointCounter.getInstance().GetSaboteurPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 200, 55); + g.drawString(Integer.toString(PointCounter.getInstance().getSaboteurPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 200, 55); for (Drawable d : drawables) { d.paint(g); diff --git a/src/main/java/View/NewGameView.java b/src/main/java/View/NewGameView.java index 680f2aa..81841fc 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/View/NewGameView.java @@ -111,7 +111,7 @@ public void paint(Graphics g) { graphics2D.drawRect(map.x-30, map.y-50, map.img.getWidth()+60, map.img.getHeight()+100); //Célpontszám kiralzolása String pointsToWin = "Célpontszám: "; - String points = "" + PointCounter.getInstance().GetPointsToWin(); + String points = "" + PointCounter.getInstance().getPointsToWin(); g.drawString(points, screenWidth / 2 + 75, screenHeight / 6 + 25); g.drawString(pointsToWin, screenWidth / 2, screenHeight / 6 - 35); // betűméret és típus beállítása diff --git a/src/test/java/model/PipeTest.java b/src/test/java/model/PipeTest.java index 51d2387..22e74eb 100644 --- a/src/test/java/model/PipeTest.java +++ b/src/test/java/model/PipeTest.java @@ -1,16 +1,13 @@ package model; -import Model.IO_Manager; import Model.Pipe; import Model.PointCounter; import Model.WaterNode; import junit.framework.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import static junit.framework.Assert.*; -import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; public class PipeTest { @@ -32,42 +29,42 @@ public void constructorTest() { @Test public void gainWaterTestWhenPipeIsFree() { - pipe.GainWater(10); + pipe.gainWater(10); verifyNoInteractions(pointCounter); } @Test public void gainWaterTestWhenPipeIsBroken() { pipe.setBroken(true); - pipe.GainWater(10); + pipe.gainWater(10); - verify(pointCounter).AddSaboteurPoints(10); + verify(pointCounter).addSaboteurPoints(10); } @Test public void loseWaterTest() { pipe.setHeldWater(20); - pipe.LoseWater(12); + pipe.loseWater(12); assertEquals(8, pipe.getHeldWater()); - pipe.LoseWater(10); + pipe.loseWater(10); assertEquals(0, pipe.getHeldWater()); } @Test public void AddWaterNodeShouldOnlySucceedIfPipeHasFreeNode() { - assertTrue(pipe.AddWaterNode(mock(WaterNode.class))); - assertTrue(pipe.AddWaterNode(mock(WaterNode.class))); - assertFalse(pipe.AddWaterNode(mock(WaterNode.class))); + assertTrue(pipe.addWaterNode(mock(WaterNode.class))); + assertTrue(pipe.addWaterNode(mock(WaterNode.class))); + assertFalse(pipe.addWaterNode(mock(WaterNode.class))); } @Test public void repairedTestWhenBroken() { pipe.setBroken(true); - pipe.Repaired(); + pipe.repaired(); assertFalse(pipe.isBroken()); } diff --git a/src/test/java/model/PumpTest.java b/src/test/java/model/PumpTest.java index 0ea1dfc..1801419 100644 --- a/src/test/java/model/PumpTest.java +++ b/src/test/java/model/PumpTest.java @@ -2,12 +2,15 @@ import Model.Pump; import Model.Pipe; +import Model.PickupAble; import Controller.Controller; +import Model.Steppable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static junit.framework.Assert.*; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; @@ -30,22 +33,91 @@ public void init() { pump.setActiveOut(mockActiveOut); } + @Test + void testGetController() { + assertEquals(mockController, pump.getController()); + } + + @Test + void testSetController() { + Controller newController = Mockito.mock(Controller.class); + pump.setController(newController); + assertEquals(newController, pump.getController()); + } + + @Test + void testPickedUp() { + Steppable mockSteppable = Mockito.mock(Steppable.class); + assertThrows(UnsupportedOperationException.class, () -> pump.pickedUp(mockSteppable)); + } + + @Test + void testPlacedDown() { + Steppable mockSteppable = Mockito.mock(Steppable.class); + when(mockSteppable.placedDownTo(any(Pump.class))).thenReturn(true); + + boolean result = pump.placedDown(mockSteppable); + + assertTrue(result); + verify(mockSteppable).placedDownTo(pump); + } + + @Test + void testPickedUpFrom() { + pump.addPipe(mockActiveIn); + + boolean result = pump.pickedUpFrom(mockActiveIn); + + assertTrue(result); + assertFalse(pump.getPipes().contains(mockActiveIn)); + } + + @Test + void testPickedUpFromNonExistingPipe() { + PickupAble mockPickup = Mockito.mock(PickupAble.class); + + boolean result = pump.pickedUpFrom(mockPickup); + + assertFalse(result); + } + + @Test + void testPlacedDownToPipe() { + Pipe mockPipe = Mockito.mock(Pipe.class); + when(mockPipe.addWaterNode(any(Pump.class))).thenReturn(true); + + boolean result = pump.placedDownTo(mockPipe); + + assertTrue(result); + assertTrue(pump.getPipes().contains(mockPipe)); + verify(mockPipe).addWaterNode(pump); + } + + @Test + void testPlacedDownToPump() { + Pump mockPump = Mockito.mock(Pump.class); + + boolean result = pump.placedDownTo(mockPump); + + assertFalse(result); + } + @Test void testWaterFlow() { // Arrange pump.setHeldWater(10); - when(mockActiveOut.GainWater(anyInt())).thenReturn(1); - when(mockActiveIn.LoseWater(anyInt())).thenReturn(1); + when(mockActiveOut.gainWater(anyInt())).thenReturn(1); + when(mockActiveIn.loseWater(anyInt())).thenReturn(1); when(mockController.getObjectName(any())).thenReturn("Pipe"); // Act - pump.WaterFlow(); + pump.waterFlow(); // Assert assertEquals(10, pump.getHeldWater()); - verify(mockActiveOut).GainWater(1); - verify(mockActiveIn).LoseWater(1); - verify(mockActiveIn).GainWater(0); + verify(mockActiveOut).gainWater(1); + verify(mockActiveIn).loseWater(1); + verify(mockActiveIn).gainWater(0); } @Test @@ -54,10 +126,10 @@ void testWaterFlowWhenBroken() { pump.setBroken(true); // Act - pump.WaterFlow(); + pump.waterFlow(); // Assert - verify(mockActiveOut, never()).GainWater(1); + verify(mockActiveOut, never()).gainWater(1); assertEquals(0, pump.getHeldWater()); } @@ -67,28 +139,28 @@ void testWaterFlowWhenEmpty() { pump.setHeldWater(0); // Act - pump.WaterFlow(); + pump.waterFlow(); // Assert - verify(mockActiveOut, never()).GainWater(anyInt()); - verify(mockActiveIn).LoseWater(1); + verify(mockActiveOut, never()).gainWater(anyInt()); + verify(mockActiveIn).loseWater(1); } @Test void testWaterFlow_WithMaxCapacity() { // Arrange pump.setHeldWater(20); - when(mockActiveOut.GainWater(anyInt())).thenReturn(1); - when(mockActiveIn.LoseWater(anyInt())).thenReturn(1); + when(mockActiveOut.gainWater(anyInt())).thenReturn(1); + when(mockActiveIn.loseWater(anyInt())).thenReturn(1); // Act - pump.WaterFlow(); + pump.waterFlow(); // Assert assertEquals(20, pump.getHeldWater()); - verify(mockActiveOut).GainWater(1); - verify(mockActiveIn).LoseWater(1); - verify(mockActiveIn).GainWater(0); + verify(mockActiveOut).gainWater(1); + verify(mockActiveIn).loseWater(1); + verify(mockActiveIn).gainWater(0); } @Test @@ -97,7 +169,7 @@ void testAddPipe() { Pipe mockPipe = Mockito.mock(Pipe.class); // Act - boolean success = pump.AddPipe(mockPipe); + boolean success = pump.addPipe(mockPipe); // Assert assertTrue(success); @@ -108,12 +180,12 @@ void testAddPipe() { void testAddPipe_MaximumPipesReached() { // Arrange for (int i = 0; i < 10; i++) { - pump.AddPipe(Mockito.mock(Pipe.class)); + pump.addPipe(Mockito.mock(Pipe.class)); } Pipe mockPipe = Mockito.mock(Pipe.class); // Act - boolean success = pump.AddPipe(mockPipe); + boolean success = pump.addPipe(mockPipe); // Assert assertFalse(success); From f55f7a261ed0470507644e98bdc6f44524ed21d0 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Tue, 21 May 2024 00:38:07 +0200 Subject: [PATCH 13/24] Duplicate fixes --- src/main/java/Assets/Strings.java | 33 ++++ src/main/java/Controller/Controller.java | 194 ++++++++++------------ src/main/java/Model/Cistern.java | 12 +- src/main/java/Model/Pipe.java | 33 ++-- src/main/java/Model/Pump.java | 3 +- src/main/java/Model/Spring.java | 2 +- src/main/java/Model/WaterNode.java | 10 +- src/main/java/View/AddPlayerButton.java | 7 - src/main/java/View/CharacterCreation.java | 2 +- src/main/java/View/CisternView.java | 9 +- src/main/java/View/Clickable.java | 6 +- src/main/java/View/ColorPicker.java | 5 +- src/main/java/View/CreatePopUpBar.java | 8 +- src/main/java/View/Drawable.java | 25 +++ src/main/java/View/ImageUtility.java | 2 +- src/main/java/View/MechanicView.java | 17 +- src/main/java/View/MenuView.java | 4 +- src/main/java/View/MouseIn.java | 7 + src/main/java/View/NewGameView.java | 9 - src/main/java/View/PipeView.java | 75 +++------ src/main/java/View/PopUpBar.java | 10 +- src/main/java/View/PopUpButton.java | 14 +- src/main/java/View/PumpView.java | 61 +++---- src/main/java/View/SaboteurView.java | 16 +- src/main/java/View/SpringView.java | 20 +-- src/main/java/View/SteppableView.java | 8 +- src/main/java/View/Window.java | 9 - 27 files changed, 274 insertions(+), 327 deletions(-) create mode 100644 src/main/java/Assets/Strings.java diff --git a/src/main/java/Assets/Strings.java b/src/main/java/Assets/Strings.java new file mode 100644 index 0000000..1cffdb0 --- /dev/null +++ b/src/main/java/Assets/Strings.java @@ -0,0 +1,33 @@ +package Assets; + +public class Strings { + public final static String WRONG_ATTR = "wrong attribute name"; + public final static String WRONG_PIPE = "wrong pipe name"; + public final static String WRONG_PLAYER = "wrong player name"; + public final static String WRONG_MECH = "wrong mechanic name"; + public final static String FELL_DOWN_STR = "fellDown"; + public final static String STUCK_STR = "stuck"; + public final static String STANDING_ON_STR = "standingOn"; + public final static String STATE_STR = "state"; + public final static String HELD_ITEMS_STR = "heldItems"; + public final static String PIPES_STR = "pipes"; + public final static String CREATED_PICKUPABLES_STR = "createdPickupables"; + public final static String PLAYERS_STR = "players"; + public final static String SABOTEUR_POINTS_STR = "saboteurPoints"; + public final static String MECHANIC_POINTS_STR = "mechanicPoints"; + public final static String POINTS_TO_WIN_STR = "pointsToWin"; + public final static String MOVE_ACTION_STR = "moveAction"; + public final static String SPECIAL_ACTION_STR = "specialAction"; + public final static String TURN_OVER_STR = "turnOver"; + public final static String BROKEN_STR = "broken"; + public final static String WATER_CAPACITY_STR = "waterCapacity"; + public final static String HELD_WATER_STR = "heldWater"; + public final static String MAXIMUM_PIPES_STR = "maximumPipes"; + public final static String ACTIVE_IN_STR = "activeIn"; + public final static String ACTIVE_OUT_STR = "activeOut"; + public final static String READY_TO_PIERCE_STR = "readyToPierce"; + public final static String LUBRICATED_STR = "lubricated"; + public final static String GLUED_STR = "glued"; + public final static String BEING_HELD_STR = "beingHeld"; + public final static String NODES_STR = "nodes"; +} diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 76e7877..133ff1f 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -1,5 +1,6 @@ package Controller; +import static Assets.Strings.*; import Model.*; import View.*; @@ -10,6 +11,7 @@ import java.util.LinkedList; import java.util.Map; + /** * A modell és a view egymással való működésében segít, a control funkciót látja el, singleton osztály */ @@ -28,35 +30,7 @@ static public Controller getInstance() { return controller; } - final static String WrongAttr = "wrong attribute name"; - final static String WrongPipe = "wrong pipe name"; - final static String WrongPlayer = "wrong player name"; - final static String WrongMech = "wrong mechanic name"; - final static String fellDownStr = "fellDown"; - final static String stuckStr = "stuck"; - final static String standingOnStr = "standingOn"; - final static String stateStr = "state"; - final static String heldItemsStr = "heldItems"; - final static String pipesStr = "pipes"; - final static String createdPickupablesStr = "createdPickupables"; - final static String playersStr = "players"; - final static String saboteurPointsStr = "saboteurPoints"; - final static String mechanicPointsStr = "mechanicPoints"; - final static String pointsToWinStr = "pointsToWin"; - final static String moveActionStr = "moveAction"; - final static String specialActionStr = "specialAction"; - final static String turnOverStr = "turnOver"; - final static String brokenStr = "broken"; - final static String waterCapacityStr = "waterCapacity"; - final static String heldWaterStr = "heldWater"; - final static String maximumPipesStr = "maximumPipes"; - final static String activeInStr = "activeIn"; - final static String activeOutStr = "activeOut"; - final static String readyToPierceStr = "readyToPierce"; - final static String lubricatedStr = "lubricated"; - final static String gluedStr = "glued"; - final static String beingHeldStr = "beingHeld"; - final static String nodesStr = "nodes"; + /** * Játék elkezdését mutató boolean */ @@ -241,7 +215,7 @@ public void create(String name, String type,int x, int y) { pumps.add(pump); pickupables.add(pump); objectCatalog.put(name, pump); - PumpView pumpView = new PumpView(x,y,25,pump,null,gameView); + PumpView pumpView = new PumpView(x,y,25,pump, gameView); gameView.addPumpView(pumpView); } case "spring" -> { @@ -282,7 +256,7 @@ public void create(String name, String type,int x, int y) { public void connect(String pipeName, String wNodeName) { if (!pipes.contains((Pipe)objectCatalog.get(pipeName))) { - IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe p = (Pipe) objectCatalog.get(pipeName); @@ -308,7 +282,7 @@ public void connect(String pipeName, String wNodeName) { public void move(String playerName, String steppableName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -339,7 +313,7 @@ public void move(String playerName, String steppableName) { public void pierce(String playerName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -356,7 +330,7 @@ public void pierce(String playerName) { public void glue(String playerName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -391,7 +365,7 @@ public void lubricate(String saboteurName) { public void repair(String mechanicName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_MECH, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -414,19 +388,19 @@ public void repair(String mechanicName) { public void redirect(String playerName, String inPipeName, String outPipeName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); if (!pipes.contains((Pipe)objectCatalog.get(inPipeName))) { - IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe in = (Pipe) objectCatalog.get(inPipeName); if (!pipes.contains((Pipe)objectCatalog.get(outPipeName))) { - IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe out = (Pipe) objectCatalog.get(outPipeName); @@ -446,7 +420,7 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { public void pickup(String mechanicName, String pickupName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_MECH, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -470,7 +444,7 @@ public void pickup(String mechanicName, String pickupName) { public void placedown(String mechanicName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_MECH, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -489,65 +463,65 @@ public void stateGet(String objectName, String attribName) { Object o = objectCatalog.get(objectName); if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr -> output += Boolean.toString(((Mechanic) o).isFellDown()); - case stuckStr -> output += Boolean.toString(((Mechanic) o).isStuck()); - case standingOnStr -> output += getObjectName(((Mechanic) o).getStandingOn()); - case stateStr -> output += getObjectName(((Mechanic) o).getState()); - case heldItemsStr -> output += getObjectName(((Mechanic) o).getHeldItems()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case FELL_DOWN_STR -> output += Boolean.toString(((Mechanic) o).isFellDown()); + case STUCK_STR -> output += Boolean.toString(((Mechanic) o).isStuck()); + case STANDING_ON_STR -> output += getObjectName(((Mechanic) o).getStandingOn()); + case STATE_STR -> output += getObjectName(((Mechanic) o).getState()); + case HELD_ITEMS_STR -> output += getObjectName(((Mechanic) o).getHeldItems()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr -> output += Boolean.toString(((Saboteur) o).isFellDown()); - case stuckStr -> output += Boolean.toString(((Saboteur) o).isStuck()); - case standingOnStr -> output += getObjectName(((Saboteur) o).getStandingOn()); - case stateStr -> output += getObjectName(((Saboteur) o).getState()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case FELL_DOWN_STR -> output += Boolean.toString(((Saboteur) o).isFellDown()); + case STUCK_STR -> output += Boolean.toString(((Saboteur) o).isStuck()); + case STANDING_ON_STR -> output += getObjectName(((Saboteur) o).getStandingOn()); + case STATE_STR -> output += getObjectName(((Saboteur) o).getState()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { switch (attribName) { - case createdPickupablesStr -> output += listWrite(((Cistern) o).getCreatedPickupables()); - case pipesStr -> output += listWrite(((Cistern) o).getPipes()); - case playersStr -> output += listWrite(((Cistern) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case CREATED_PICKUPABLES_STR -> output += listWrite(((Cistern) o).getCreatedPickupables()); + case PIPES_STR -> output += listWrite(((Cistern) o).getPipes()); + case PLAYERS_STR -> output += listWrite(((Cistern) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (springs.contains((Spring) objectCatalog.get(objectName))) { switch (attribName) { - case pipesStr -> output += listWrite(((Spring) o).getPipes()); - case playersStr -> output += listWrite(((Spring) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case PIPES_STR -> output += listWrite(((Spring) o).getPipes()); + case PLAYERS_STR -> output += listWrite(((Spring) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> output += Boolean.toString(((Pump) o).isBroken()); - case waterCapacityStr -> output += Integer.toString(((Pump) o).getWaterCapacity()); - case heldWaterStr -> output += Integer.toString(((Pump) o).getHeldWater()); - case maximumPipesStr -> output += Integer.toString(((Pump) o).getMaximumPipes()); - case activeInStr -> output += getObjectName(((Pump) o).getActiveIn()); - case activeOutStr -> output += getObjectName(((Pump) o).getActiveOut()); - case pipesStr -> output += listWrite(((Pump) o).getPipes()); - case playersStr -> output += listWrite(((Pump) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case BROKEN_STR -> output += Boolean.toString(((Pump) o).isBroken()); + case WATER_CAPACITY_STR -> output += Integer.toString(((Pump) o).getWaterCapacity()); + case HELD_WATER_STR -> output += Integer.toString(((Pump) o).getHeldWater()); + case MAXIMUM_PIPES_STR -> output += Integer.toString(((Pump) o).getMaximumPipes()); + case ACTIVE_IN_STR -> output += getObjectName(((Pump) o).getActiveIn()); + case ACTIVE_OUT_STR -> output += getObjectName(((Pump) o).getActiveOut()); + case PIPES_STR -> output += listWrite(((Pump) o).getPipes()); + case PLAYERS_STR -> output += listWrite(((Pump) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (pipes.contains((Pipe) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> output += Boolean.toString(((Pipe) o).isBroken()); - case waterCapacityStr -> output += Integer.toString(((Pipe) o).getWaterCapacity()); - case heldWaterStr -> output += Integer.toString(((Pipe) o).getHeldWater()); - case readyToPierceStr -> output += Boolean.toString(((Pipe) o).isReadyToPierce()); - case lubricatedStr -> output += Boolean.toString(((Pipe) o).isLubricated()); - case gluedStr -> output += Boolean.toString(((Pipe) o).isGlued()); - case beingHeldStr -> output += Boolean.toString(((Pipe) o).isBeingHeld()); - case nodesStr -> output += listWrite(((Pipe) o).getNodes()); - case playersStr -> output += listWrite(((Pipe) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case BROKEN_STR -> output += Boolean.toString(((Pipe) o).isBroken()); + case WATER_CAPACITY_STR -> output += Integer.toString(((Pipe) o).getWaterCapacity()); + case HELD_WATER_STR -> output += Integer.toString(((Pipe) o).getHeldWater()); + case READY_TO_PIERCE_STR -> output += Boolean.toString(((Pipe) o).isReadyToPierce()); + case LUBRICATED_STR -> output += Boolean.toString(((Pipe) o).isLubricated()); + case GLUED_STR -> output += Boolean.toString(((Pipe) o).isGlued()); + case BEING_HELD_STR -> output += Boolean.toString(((Pipe) o).isBeingHeld()); + case NODES_STR -> output += listWrite(((Pipe) o).getNodes()); + case PLAYERS_STR -> output += listWrite(((Pipe) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (objectName.equals("counter")) { switch (attribName) { - case saboteurPointsStr -> output += Integer.toString(PointCounter.getInstance().getSaboteurPoints()); - case mechanicPointsStr -> output += Integer.toString(PointCounter.getInstance().getMechanicPoints()); - case pointsToWinStr -> output += Integer.toString(PointCounter.getInstance().getPointsToWin()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case SABOTEUR_POINTS_STR -> output += Integer.toString(PointCounter.getInstance().getSaboteurPoints()); + case MECHANIC_POINTS_STR -> output += Integer.toString(PointCounter.getInstance().getMechanicPoints()); + case POINTS_TO_WIN_STR -> output += Integer.toString(PointCounter.getInstance().getPointsToWin()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else { IO_Manager.writeError("wrong object name", Controller.filetoWrite != null); @@ -566,40 +540,40 @@ public void stateSet(String objectName, String attribName, String attribValue) { Object o = objectCatalog.get(objectName); if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr: + case FELL_DOWN_STR: ((Mechanic) o).setFellDown(Boolean.parseBoolean(attribValue)); break; - case stuckStr: + case STUCK_STR: ((Mechanic) o).setStuck(Boolean.parseBoolean(attribValue)); break; - case stateStr: + case STATE_STR: switch (attribValue) { - case moveActionStr -> ((Mechanic) o).setState(PlayerActionState.MOVE_ACTION); - case specialActionStr -> ((Mechanic) o).setState(PlayerActionState.SPECIAL_ACTION); - case turnOverStr -> ((Mechanic) o).setState(PlayerActionState.TURN_OVER); + case MOVE_ACTION_STR -> ((Mechanic) o).setState(PlayerActionState.MOVE_ACTION); + case SPECIAL_ACTION_STR -> ((Mechanic) o).setState(PlayerActionState.SPECIAL_ACTION); + case TURN_OVER_STR -> ((Mechanic) o).setState(PlayerActionState.TURN_OVER); } break; default: - IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr: + case FELL_DOWN_STR: ((Saboteur) o).setFellDown(Boolean.parseBoolean(attribValue)); break; - case stuckStr: + case STUCK_STR: ((Saboteur) o).setStuck(Boolean.parseBoolean(attribValue)); break; - case stateStr: + case STATE_STR: switch (attribValue) { - case moveActionStr -> ((Saboteur) o).setState(PlayerActionState.MOVE_ACTION); - case specialActionStr -> ((Saboteur) o).setState(PlayerActionState.SPECIAL_ACTION); - case turnOverStr -> ((Saboteur) o).setState(PlayerActionState.TURN_OVER); + case MOVE_ACTION_STR -> ((Saboteur) o).setState(PlayerActionState.MOVE_ACTION); + case SPECIAL_ACTION_STR -> ((Saboteur) o).setState(PlayerActionState.SPECIAL_ACTION); + case TURN_OVER_STR -> ((Saboteur) o).setState(PlayerActionState.TURN_OVER); } break; default: - IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); @@ -607,30 +581,30 @@ public void stateSet(String objectName, String attribName, String attribValue) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); - case waterCapacityStr -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); - case heldWaterStr -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); - case maximumPipesStr -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); - case activeInStr -> { + case BROKEN_STR -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); + case WATER_CAPACITY_STR -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); + case HELD_WATER_STR -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); + case MAXIMUM_PIPES_STR -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); + case ACTIVE_IN_STR -> { if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveIn((Pipe) objectCatalog.get(attribValue)); } - case activeOutStr -> { + case ACTIVE_OUT_STR -> { if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveOut((Pipe) objectCatalog.get(attribValue)); } - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (pipes.contains((Pipe) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); - case waterCapacityStr -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); - case heldWaterStr -> ((Pipe) o).setHeldWater(Integer.parseInt(attribValue)); - case readyToPierceStr -> ((Pipe) o).setReadyToPierce(Boolean.parseBoolean(attribValue)); - case lubricatedStr -> ((Pipe) o).setLubricated(Boolean.parseBoolean(attribValue)); - case gluedStr -> ((Pipe) o).setGlued(Boolean.parseBoolean(attribValue)); - case beingHeldStr -> ((Pipe) o).setBeingHeld(Boolean.parseBoolean(attribValue)); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case BROKEN_STR -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); + case WATER_CAPACITY_STR -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); + case HELD_WATER_STR -> ((Pipe) o).setHeldWater(Integer.parseInt(attribValue)); + case READY_TO_PIERCE_STR -> ((Pipe) o).setReadyToPierce(Boolean.parseBoolean(attribValue)); + case LUBRICATED_STR -> ((Pipe) o).setLubricated(Boolean.parseBoolean(attribValue)); + case GLUED_STR -> ((Pipe) o).setGlued(Boolean.parseBoolean(attribValue)); + case BEING_HELD_STR -> ((Pipe) o).setBeingHeld(Boolean.parseBoolean(attribValue)); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else { IO_Manager.writeError("wrong object name", Controller.filetoWrite != null); diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 25166d0..89ffbe4 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -15,15 +15,15 @@ public class Cistern extends WaterNode implements Serializable { /** * Ciszternáról felvehető elemek, amik generálódtak rajta */ - private LinkedList createdPickupables = new LinkedList<>(); + private final LinkedList createdPickupables = new LinkedList<>(); /** * Ciszternán keletkezett csövek listája */ - private LinkedList generatedPipes = new LinkedList<>(); + private final LinkedList generatedPipes = new LinkedList<>(); /** * Ciszternán keletkezett pumpák listája */ - private LinkedList generatedPumps = new LinkedList<>(); + private final LinkedList generatedPumps = new LinkedList<>(); /** * Pontszámításhoz használt singleton @@ -176,8 +176,10 @@ public boolean canPlaceDown(Mechanic m){ public boolean canMoveFromHere() { boolean canMove=false; for(Pipe p:pipes){ - if(p.players.isEmpty() && !generatedPipes.contains(p)) - canMove=true; + if (p.players.isEmpty() && !generatedPipes.contains(p)) { + canMove = true; + break; + } } return canMove; } diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index 91b7341..5d71634 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -211,6 +211,17 @@ public boolean placedDownTo(Pipe pickup) { return false; } + private Pipe setPipesAttr(Pipe newPipe){ + newPipe.waterCapacity = this.waterCapacity; + newPipe.heldWater = this.heldWater; + newPipe.broken = this.broken; + newPipe.readyToPierce = this.readyToPierce; + newPipe.lubricated = this.lubricated; + newPipe.glued = this.glued; + newPipe.beingHeld = this.beingHeld; + newPipe.readyToPierceTimer = this.readyToPierceTimer; + return newPipe; + } /** * Akkor hívódik meg, amikor egy pumpát a szerelő lehelyez * a csőre, a kettévágást kezeli. @@ -266,23 +277,9 @@ public void cutInHalf(Pump pump) { if (node2activeOut == this) node2.setActiveOut(newPipe2); - newPipe1.waterCapacity=this.waterCapacity; - newPipe1.heldWater=this.heldWater; - newPipe1.broken= this.broken; - newPipe1.readyToPierce=this.readyToPierce; - newPipe1.lubricated=this.lubricated; - newPipe1.glued=this.glued; - newPipe1.beingHeld= this.beingHeld; - newPipe1.readyToPierceTimer=this.readyToPierceTimer; - - newPipe2.waterCapacity=this.waterCapacity; - newPipe2.heldWater=this.heldWater; - newPipe2.broken= this.broken; - newPipe2.readyToPierce=this.readyToPierce; - newPipe2.lubricated=this.lubricated; - newPipe2.glued=this.glued; - newPipe2.beingHeld= this.beingHeld; - newPipe2.readyToPierceTimer=this.readyToPierceTimer; + newPipe1 = setPipesAttr(newPipe1); + + newPipe2 = setPipesAttr(newPipe2); boolean ignoreStates = Player.isIgnoreStates(); Player.setIgnoreStates(true); @@ -293,7 +290,7 @@ public void cutInHalf(Pump pump) { Controller.getInstance().getGameView().remove(Controller.getInstance().getGameView().getPipeViewByCorrespondingModel(this)); Controller.getInstance().getGameView().remove(Controller.getInstance().getGameView().getDrawableByCorrespondingModel(pump)); - PumpView pumpView = new PumpView(x,y,25,pump,null,Controller.getInstance().getGameView()); + PumpView pumpView = new PumpView(x,y,25,pump, Controller.getInstance().getGameView()); Controller.getInstance().getGameView().addPumpView(pumpView); PipeView pipeView1 = new PipeView( diff --git a/src/main/java/Model/Pump.java b/src/main/java/Model/Pump.java index 4431fa4..a5c6702 100644 --- a/src/main/java/Model/Pump.java +++ b/src/main/java/Model/Pump.java @@ -122,10 +122,9 @@ public void waterFlow() { if (broken) { IO_Manager.writeInfo(controller.getObjectName(this) + " is broken", controller.filetoWrite != null); } - int gained=0; if(!broken && heldWater != 0 && activeOut != null) { - gained= activeOut.gainWater(1); + int gained = activeOut.gainWater(1); if(gained==1){ heldWater--; } diff --git a/src/main/java/Model/Spring.java b/src/main/java/Model/Spring.java index f011665..addc7eb 100644 --- a/src/main/java/Model/Spring.java +++ b/src/main/java/Model/Spring.java @@ -100,7 +100,7 @@ public void waterFlow() { */ @Override public boolean addPipe(Pipe p) { - boolean valid = pipes.size() < 1; + boolean valid = pipes.isEmpty(); if (valid) pipes.add(p); else diff --git a/src/main/java/Model/WaterNode.java b/src/main/java/Model/WaterNode.java index 2cfa186..021f35a 100644 --- a/src/main/java/Model/WaterNode.java +++ b/src/main/java/Model/WaterNode.java @@ -23,7 +23,7 @@ public abstract class WaterNode extends Steppable implements Serializable { @Override public boolean playerEnter(Player player) { - boolean successful = pipes.contains(player.getStandingOn()) || player.getStandingOn() == null; + boolean successful = pipes.contains((Pipe) player.getStandingOn()) || player.getStandingOn() == null; if (successful) players.add(player); else @@ -101,8 +101,10 @@ public LinkedList getPipes() { public boolean canMoveFromHere() { boolean canMove=false; for(Pipe p:pipes){ - if(p.players.isEmpty()) - canMove=true; + if (p.players.isEmpty()) { + canMove = true; + break; + } } return canMove; } @@ -114,6 +116,6 @@ public boolean canMoveFromHere() { */ @Override public boolean canMoveToHere(Player p){ - return pipes.contains(p.getStandingOn()); + return pipes.contains((Pipe) p.getStandingOn()); } } diff --git a/src/main/java/View/AddPlayerButton.java b/src/main/java/View/AddPlayerButton.java index 59b9ebd..54b3c8b 100644 --- a/src/main/java/View/AddPlayerButton.java +++ b/src/main/java/View/AddPlayerButton.java @@ -42,13 +42,6 @@ public void clickAction(MouseEvent e) { // karakter nevének és színének megadása cc = new CharacterCreation(temp, name); } - - } else if (type == -1) { - if (name.equals("mechanic")) { - - } else if (name.equals("saboteur")) { - - } } diff --git a/src/main/java/View/CharacterCreation.java b/src/main/java/View/CharacterCreation.java index 4f62b7e..5adcb3d 100644 --- a/src/main/java/View/CharacterCreation.java +++ b/src/main/java/View/CharacterCreation.java @@ -20,7 +20,7 @@ public class CharacterCreation { - private ColorPicker characterCreationPanel; + private final ColorPicker characterCreationPanel; /** * constructor - creates the frame and sets up the layout (a color picker, a text field for the player's name, and a button for saving the data and return to the main menu) diff --git a/src/main/java/View/CisternView.java b/src/main/java/View/CisternView.java index 31fd20b..6f80ba3 100644 --- a/src/main/java/View/CisternView.java +++ b/src/main/java/View/CisternView.java @@ -17,7 +17,7 @@ public class CisternView extends Drawable implements Clickable, CreatePopUpBar, private final Cistern cistern; private final int r; private GameView gameView = null; - private BufferedImage sprite = null; + private BufferedImage sprite; /** * CisternView konstruktor @@ -106,13 +106,8 @@ public Point getRotationCenter() { * @param p - játékos * @return - játékos szöge */ - @Override public double getPlayerAngle(Player p) { - double[] angles = new double[cistern.getPlayers().size()]; - for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; - } - return angles[cistern.getPlayers().indexOf(p)]; + return super.getPlayerAngle(p, cistern.getPlayers()); } @Override diff --git a/src/main/java/View/Clickable.java b/src/main/java/View/Clickable.java index 5dcc660..46635fe 100644 --- a/src/main/java/View/Clickable.java +++ b/src/main/java/View/Clickable.java @@ -12,17 +12,17 @@ public interface Clickable { * @return - igaz, ha a kattintható objektumon belül van az egér */ - public boolean isIn(MouseEvent e); + boolean isIn(MouseEvent e); /** * clickAction - kattintás eseménye * @param e - egérkattintás */ - public void clickAction(MouseEvent e); + void clickAction(MouseEvent e); /** * isDraggable - megadja, hogy a kattintható objektum húzható-e * @return - igaz, ha mozgatható */ - public boolean isDraggable(); + boolean isDraggable(); } diff --git a/src/main/java/View/ColorPicker.java b/src/main/java/View/ColorPicker.java index 8803571..1bbc99f 100644 --- a/src/main/java/View/ColorPicker.java +++ b/src/main/java/View/ColorPicker.java @@ -42,8 +42,7 @@ * Java Color Picker */ public class ColorPicker extends JPanel { - private JColorChooser tcc; - private JTextField userName; + private final JColorChooser tcc; /** * constructor - creates a text field for the username, a color picker area @@ -52,7 +51,7 @@ public ColorPicker() { super(new BorderLayout()); // creating a text field for the player's name - userName = new JTextField("User"); + JTextField userName = new JTextField("User"); userName.setBounds(new Rectangle(300, 100)); JPanel userNamePanel = new JPanel(new BorderLayout()); userNamePanel.setBorder(BorderFactory.createTitledBorder("Username:")); diff --git a/src/main/java/View/CreatePopUpBar.java b/src/main/java/View/CreatePopUpBar.java index aeb9f03..bc95541 100644 --- a/src/main/java/View/CreatePopUpBar.java +++ b/src/main/java/View/CreatePopUpBar.java @@ -16,7 +16,7 @@ public interface CreatePopUpBar { * @param view - ablak * @param creator - létrehozó */ - public default void createPopUpBar(int x, int y, int r, Window view, SteppableView creator){ + default void createPopUpBar(int x, int y, int r, Window view, SteppableView creator){ GameView gameView = (GameView) view; PopUpBar p = new PopUpBar(x, y, r, view, creator, null); @@ -24,8 +24,10 @@ public default void createPopUpBar(int x, int y, int r, Window view, SteppableVi boolean notNull = false; for (ActionType a : Controller.getInstance().getActivePlayer().availableActions(creator.getCorrespondingModelSteppable())) { - if (a != null) + if (a != null) { notNull = true; + break; + } } if (!notNull) gameView.removePopUpBar(); @@ -41,7 +43,7 @@ public default void createPopUpBar(int x, int y, int r, Window view, SteppableVi * @param creator - létrehozó * @param at - akciók */ - public default void createPopUpBarWithActions(int x, int y, int r, Window view, SteppableView creator, ActionType[] at) { + default void createPopUpBarWithActions(int x, int y, int r, Window view, SteppableView creator, ActionType[] at) { GameView gameView = (GameView) view; PopUpBar p = new PopUpBar(x, y, r, view, creator, at); gameView.addCisternDisplay(p); diff --git a/src/main/java/View/Drawable.java b/src/main/java/View/Drawable.java index e7ec078..7de8704 100644 --- a/src/main/java/View/Drawable.java +++ b/src/main/java/View/Drawable.java @@ -1,7 +1,10 @@ package View; +import Model.Player; + import javax.swing.*; import java.awt.*; +import java.util.LinkedList; /** * Drawable - kirajzolható objektumok absztrakt ősosztálya, leszármazottja a JComponent osztály @@ -47,4 +50,26 @@ public void paintOnPlayer(int x, int y, Graphics2D graphics2D){ } + public double getPlayerAngle(Player p, LinkedList players) { + double[] angles = new double[players.size()]; + for (int i = 0; i < angles.length; ++i) { + angles[i] = i * 20 - (angles.length - 1) * 10; + } + return angles[players.indexOf(p)]; + } + public int[] setCapX(int x){ + int[] capX = new int[3]; + capX[0] = x; + capX[1] = x-8; + capX[2] = x+8; + return capX; + } + + public int[] setCapY(int y) { + int[] capY = new int[3]; + capY[0] = y - 22; + capY[1] = y - 15; + capY[2] = y - 15; + return capY; + } } diff --git a/src/main/java/View/ImageUtility.java b/src/main/java/View/ImageUtility.java index ec988ec..fc851d7 100644 --- a/src/main/java/View/ImageUtility.java +++ b/src/main/java/View/ImageUtility.java @@ -18,7 +18,7 @@ public class ImageUtility { * @return The loaded image. */ public static BufferedImage ImageLoad(String file) { - BufferedImage image = null; + BufferedImage image; try { String nameOfFile = System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" diff --git a/src/main/java/View/MechanicView.java b/src/main/java/View/MechanicView.java index 414f53f..ee724d2 100644 --- a/src/main/java/View/MechanicView.java +++ b/src/main/java/View/MechanicView.java @@ -31,7 +31,7 @@ public MechanicView(int x, int y, Mechanic m, Window v) { } private GameView gameView; - private Mechanic mechanic; + private final Mechanic mechanic; private Color color; private double angle; private Point rotationCenter = new Point(0, 0); @@ -68,13 +68,12 @@ public void paint(Graphics g) { // ha a játék ablakban vagyunk, akkor a játékos színével rajzoljuk ki if (WindowOptions.windowOption == WindowOptions.NEWGAME) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int screenWidth = (int) screenSize.getWidth() * 3 / 4; int screenHeight = (int) screenSize.getHeight() * 3 / 4; AppFrame.setGraphicQuality(g); Graphics2D graphics2D = (Graphics2D) g.create(); graphics2D.setColor(color); graphics2D.setFont(new Font("Inter", Font.BOLD, 30)); - graphics2D.drawString("" + color.getRed() + "/" + color.getGreen() + "/" + color.getBlue(), 50 + imageForScale.getWidth(null) + 100, screenHeight / 2 + 20 + number * 50); + graphics2D.drawString(color.getRed() + "/" + color.getGreen() + "/" + color.getBlue(), 50 + imageForScale.getWidth(null) + 100, screenHeight / 2 + 20 + number * 50); } // ha a mechanic még nincs eltávolítva @@ -83,20 +82,14 @@ public void paint(Graphics g) { int[] pointsX = new int[3]; int[] pointsY = new int[3]; pointsX[0] = x; - pointsY[0] = y + 12 + 1; + pointsY[0] = y + 13; pointsX[1] = x - 8 + 1; pointsY[1] = y - 10 - 1; pointsX[2] = x + 8 + 1; pointsY[2] = y - 10 - 1; - int[] capX = new int[3]; - int[] capY = new int[3]; - capX[0] = x; - capY[0] = y - 22; - capX[1] = x - 8; - capY[1] = y - 15; - capX[2] = x + 8; - capY[2] = y - 15; + int[] capX = super.setCapX(x); + int[] capY = super.setCapY(y); g.setColor(color); Graphics2D graphics2D = (Graphics2D) g.create(); diff --git a/src/main/java/View/MenuView.java b/src/main/java/View/MenuView.java index 0760c29..8792693 100644 --- a/src/main/java/View/MenuView.java +++ b/src/main/java/View/MenuView.java @@ -13,8 +13,8 @@ public class MenuView extends Window { Button newGame, exit; - private BufferedImage background = ImageUtility.backgroundScale(getBackground()); - private BufferedImage bgText = ImageUtility.scaleImage(getMenuTitle(), 250); + private final BufferedImage background = ImageUtility.backgroundScale(getBackground()); + private final BufferedImage bgText = ImageUtility.scaleImage(getMenuTitle(), 250); /** * Konstruktor diff --git a/src/main/java/View/MouseIn.java b/src/main/java/View/MouseIn.java index 9c8add4..f7702d9 100644 --- a/src/main/java/View/MouseIn.java +++ b/src/main/java/View/MouseIn.java @@ -18,6 +18,7 @@ public void mouseClicked(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseClicked(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseClicked(e); case GAME -> Controller.getInstance().getGameView().mouseClicked(e); + default -> {} } } @@ -31,6 +32,7 @@ public void mousePressed(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mousePressed(e); case NEWGAME -> Controller.getInstance().getNewGameView().mousePressed(e); case GAME -> Controller.getInstance().getGameView().mousePressed(e); + default -> {} } } @@ -44,6 +46,7 @@ public void mouseReleased(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseReleased(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseReleased(e); case GAME -> Controller.getInstance().getGameView().mouseReleased(e); + default -> {} } } @@ -57,6 +60,7 @@ public void mouseEntered(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseEntered(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseEntered(e); case GAME -> Controller.getInstance().getGameView().mouseEntered(e); + default -> {} } } @@ -70,6 +74,7 @@ public void mouseExited(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseExited(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseExited(e); case GAME -> Controller.getInstance().getGameView().mouseExited(e); + default -> {} } } @@ -83,6 +88,7 @@ public void mouseDragged(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseDragged(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseDragged(e); case GAME -> Controller.getInstance().getGameView().mouseDragged(e); + default -> {} } } @@ -96,6 +102,7 @@ public void mouseMoved(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseMoved(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseMoved(e); case GAME -> Controller.getInstance().getGameView().mouseMoved(e); + default -> {} } } } diff --git a/src/main/java/View/NewGameView.java b/src/main/java/View/NewGameView.java index 81841fc..fdcaaff 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/View/NewGameView.java @@ -2,7 +2,6 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import Model.PointCounter; @@ -148,14 +147,6 @@ public void update() { } - /** - * A billentyűlenyomásokat kezeli - * @param e leütött billentyű - */ - public void keyTyped(KeyEvent e) { - - } - @Override public void mousePressed(MouseEvent e) { diff --git a/src/main/java/View/PipeView.java b/src/main/java/View/PipeView.java index 81c6f28..434f2d4 100644 --- a/src/main/java/View/PipeView.java +++ b/src/main/java/View/PipeView.java @@ -35,12 +35,12 @@ public PipeView(Drawable startNode, Drawable endNode, int width, Pipe p, Window } public boolean selected; private GameView gameView; - private Pipe pipe; + private final Pipe pipe; private int endX; private int endY; - private int width; - private Drawable startNode = null; - private Drawable endNode = null; + private final int width; + private Drawable startNode; + private Drawable endNode; /** * Cső kirajzolása @@ -57,14 +57,14 @@ public void paint(Graphics g) { double unitNormY = pipeNormal.y / getLength(); int x1 = (int) Math.ceil(unitNormX * width *1.4) + x; int y1 = (int) Math.ceil(unitNormY * width *1.4) + y; - int x2 = (int) Math.ceil(-unitNormX * width *1.4) + x;; + int x2 = (int) Math.ceil(-unitNormX * width *1.4) + x; int y2 = (int) Math.ceil(-unitNormY * width *1.4) + y; - int x3 = (int) Math.ceil(unitNormX * width *1.4) + endX; - int y3 = (int) Math.ceil(unitNormY * width *1.4) + endY; - int x4 = (int) Math.ceil(-unitNormX * width *1.4) + endX; - int y4 = (int) Math.ceil(-unitNormY * width *1.4) + endY; + int x3 = x1 -x +endX; + int y3 = y1-y +endY; + int x4 = x2 -x +endX; + int y4 = y2 -y +endY; - Color mainColor = BLACK; + Color mainColor; Color brokenColor = RED; Color miscColor = CYAN; boolean drawBroken = false; @@ -83,54 +83,25 @@ public void paint(Graphics g) { if (pipe.getHeldWater() == 1) { mainColor = new Color(47, 178, 245); - if (pipe.isBroken()) { - drawBroken = true; - } - - if (pipe.isGlued()) { - drawMisc = true; - miscColor = new Color(61, 153, 3); - } else if (pipe.isLubricated()) { - drawMisc = true; - miscColor = new Color(44, 121, 131); - } - } else if ( pipe.getNodes().getFirst().getActiveIn() != pipe && pipe.getNodes().getFirst().getActiveOut() != pipe && pipe.getNodes().getLast().getActiveIn() != pipe && pipe.getNodes().getLast().getActiveOut() != pipe) - { - mainColor = LIGHT_GRAY; - - if (pipe.isBroken()) { - drawBroken = true; - } - - if (pipe.isGlued()) { - drawMisc = true; - miscColor = new Color(61, 153, 3); - } else if (pipe.isLubricated()) { - drawMisc = true; - miscColor = new Color(44, 121, 131); - } - - } else { - - mainColor = BLACK; + {mainColor = LIGHT_GRAY;} + else {mainColor = BLACK;} - if (pipe.isBroken()) { - drawBroken = true; - } + if (pipe.isBroken()) { + drawBroken = true; + } - if (pipe.isGlued()) { - drawMisc = true; - miscColor = new Color(61, 153, 3); - } else if (pipe.isLubricated()) { - drawMisc = true; - miscColor = new Color(44, 121, 131); - } + if (pipe.isGlued()) { + drawMisc = true; + miscColor = new Color(61, 153, 3); + } else if (pipe.isLubricated()) { + drawMisc = true; + miscColor = new Color(44, 121, 131); } if (drawBroken) { @@ -232,7 +203,7 @@ public boolean isIn(MouseEvent e) { int[] pointsY = new int[4]; pointsX[0] = (int) Math.ceil(unitNormX * width * 4) + x; pointsY[0] = (int) Math.ceil(unitNormY * width * 4) + y; - pointsX[1] = (int) Math.ceil(-unitNormX * width * 4) + x;; + pointsX[1] = (int) Math.ceil(-unitNormX * width * 4) + x; pointsY[1] = (int) Math.ceil(-unitNormY * width * 4) + y; pointsX[2] = (int) Math.ceil(-unitNormX * width * 4) + endX; pointsY[2] = (int) Math.ceil(-unitNormY * width * 4) + endY; @@ -276,7 +247,7 @@ public Steppable getCorrespondingModelSteppable() { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni - * @return + * @return a pont */ @Override public Point getDefaultPlayerPosition() { diff --git a/src/main/java/View/PopUpBar.java b/src/main/java/View/PopUpBar.java index 66ec013..7b10244 100644 --- a/src/main/java/View/PopUpBar.java +++ b/src/main/java/View/PopUpBar.java @@ -22,9 +22,8 @@ public class PopUpBar extends Drawable { */ public PopUpBar(int x, int y, int r, Window v, SteppableView creator, ActionType[] at) { super(x, y, v); - this.r = r; - buttonLocations = new Point[6]; + Point[] buttonLocations = new Point[6]; for (int i = 0; i < buttonLocations.length; ++i) { buttonLocations[i] = new Point(); buttonLocations[i].x = (int) (Math.cos(Math.toRadians(i * -60 - 90)) * r + x); @@ -48,16 +47,13 @@ public PopUpBar(int x, int y, int r, Window v, SteppableView creator, ActionType this.creator = creator; } - private SteppableView creator; + private final SteppableView creator; public SteppableView getCreator() { return creator; } - private Point[] buttonLocations; - private int r; - - private List buttons = new LinkedList(); + private final List buttons = new LinkedList<>(); /** * A popup menü kirajzolása * @param g Graphics diff --git a/src/main/java/View/PopUpButton.java b/src/main/java/View/PopUpButton.java index 4c31ad6..d614903 100644 --- a/src/main/java/View/PopUpButton.java +++ b/src/main/java/View/PopUpButton.java @@ -29,10 +29,10 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr drawLoc = ImageUtility.centerImage(new Point(x, y), sprite); this.creator = creator; } - private SteppableView creator; - private ActionType actiontype; + private final SteppableView creator; + private final ActionType actiontype; private BufferedImage sprite = null; - private int r; + private final int r; Point drawLoc; public static boolean waitingForParameter = false; public static LinkedList parameters = new LinkedList<>(); @@ -40,10 +40,7 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr private float opacity = 0.0f; @Override public boolean isIn(MouseEvent e) { - if (Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r) { - return true; - } - return false; + return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; } @Override @@ -64,7 +61,7 @@ public void clickAction(MouseEvent e) { } case PLACEDOWN -> c.placedown(c.getObjectName(p)); case PICKUP_PIPE -> { - if (((GameView) view).cisterns.contains(creator)) { + if (((GameView) view).cisterns.contains((CisternView) creator)) { Cistern cis = (Cistern) s; Pipe pipe = cis.getGeneratedPipes().getFirst(); c.pickup(c.getObjectName(p), c.getObjectName(pipe)); @@ -123,7 +120,6 @@ public boolean isDraggable() { public static void paramsReceived() { Controller c = Controller.getInstance(); Player p = c.getActivePlayer(); - Steppable s = paramClient.creator.getCorrespondingModelSteppable(); if (paramClient.actiontype == ActionType.REDIRECT) { c.redirect(c.getObjectName(p), c.getObjectName(parameters.getFirst().getCorrespondingModelElement()), c.getObjectName(parameters.getLast().getCorrespondingModelElement())); } diff --git a/src/main/java/View/PumpView.java b/src/main/java/View/PumpView.java index 5f67b31..518dee0 100644 --- a/src/main/java/View/PumpView.java +++ b/src/main/java/View/PumpView.java @@ -14,11 +14,10 @@ public class PumpView extends Drawable implements Clickable, CreatePopUpBar, SteppableView { - public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { + public PumpView(int x, int y, int r, Pump p, Window v) { super(x, y, v); this.r = r; pump = p; - gen = c; arrowSprite = getPumpIndicatorImg(); arrowSprite = ImageUtility.scaleImage(arrowSprite, 20); @@ -27,13 +26,11 @@ public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { gameView = (GameView) v; } private GameView gameView; - private Pump pump; - private boolean generated; - private CisternView gen; - private int r; + private final Pump pump; + private final int r; private PipeView outPipe = null; - private BufferedImage arrowSprite = null; + private BufferedImage arrowSprite; private int arrowLocX; private int arrowLocY; private double arrowAngle; @@ -42,24 +39,12 @@ public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { @Override public void paint(Graphics g) { AppFrame.setGraphicQuality(g); - Color color=new Color(0,0,0); - if(pump.isBroken()) - color=new Color(250,100,100); - else { - if(pump.getHeldWater()<=pump.getWaterCapacity()*0.25 && pump.getHeldWater()!=0) - color=new Color(0,0,150); - if(pump.getHeldWater()<=pump.getWaterCapacity()*0.5 && pump.getHeldWater()>=pump.getWaterCapacity()*0.25) - color=new Color(0,0,200); - if(pump.getHeldWater()<=pump.getWaterCapacity()*0.75 && pump.getHeldWater()>=pump.getWaterCapacity()*0.5) - color=new Color(20,20,255); - if(pump.getHeldWater()<=pump.getWaterCapacity() && pump.getHeldWater()>=pump.getWaterCapacity()*0.75) - color=new Color(60,170,255); - } + Color color = getColor(); if (outPipe != null) { AffineTransform at = new AffineTransform(); at.translate(arrowLocX, arrowLocY); at.rotate(Math.toRadians(-arrowAngle)); - at.translate(-arrowSprite.getWidth() / 2, -arrowSprite.getHeight() / 2); + at.translate((double) -arrowSprite.getWidth() / 2, (double) -arrowSprite.getHeight() / 2); Graphics2D g2 = (Graphics2D) g.create(); g2.drawImage(arrowSprite, at, null); g2.setTransform(new AffineTransform()); @@ -79,6 +64,23 @@ public void paint(Graphics g) { g.drawString( Integer.toString(pump.getWaterCapacity()), x + 5, y+5); } + private Color getColor() { + Color color=new Color(0,0,0); + if(pump.isBroken()) + color=new Color(250,100,100); + else { + if(pump.getHeldWater()<=pump.getWaterCapacity()*0.25 && pump.getHeldWater()!=0) + color=new Color(0,0,150); + if(pump.getHeldWater()<=pump.getWaterCapacity()*0.5 && pump.getHeldWater()>=pump.getWaterCapacity()*0.25) + color=new Color(0,0,200); + if(pump.getHeldWater()<=pump.getWaterCapacity()*0.75 && pump.getHeldWater()>=pump.getWaterCapacity()*0.5) + color=new Color(20,20,255); + if(pump.getHeldWater()<=pump.getWaterCapacity() && pump.getHeldWater()>=pump.getWaterCapacity()*0.75) + color=new Color(60,170,255); + } + return color; + } + @Override public void paintOnPlayer(int x,int y, Graphics2D graphics2D){ graphics2D.setColor(BLACK); @@ -120,10 +122,7 @@ public void update() { @Override public boolean isIn(MouseEvent e) { - if (Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r) { - return true; - } - return false; + return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; } @Override @@ -143,8 +142,6 @@ public Steppable getCorrespondingModelSteppable() { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni - * - * @return */ @Override public Point getDefaultPlayerPosition() { @@ -154,17 +151,11 @@ public Point getDefaultPlayerPosition() { public Point getRotationCenter() { //meg kéne nézni hány játékos van rajta - Point ret = new Point(x, y); - return ret; + return new Point(x, y); } - @Override public double getPlayerAngle(Player p) { - double[] angles = new double[pump.getPlayers().size()]; - for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; - } - return angles[pump.getPlayers().indexOf(p)]; + return super.getPlayerAngle(p, pump.getPlayers()); } @Override diff --git a/src/main/java/View/SaboteurView.java b/src/main/java/View/SaboteurView.java index 1aa440a..bec2043 100644 --- a/src/main/java/View/SaboteurView.java +++ b/src/main/java/View/SaboteurView.java @@ -20,7 +20,7 @@ public SaboteurView(int x, int y, Saboteur s, Window v) { } private GameView gameView; private Color color; - private Saboteur saboteur; + private final Saboteur saboteur; private double angle; private Point rotationCenter = new Point(0, 0); @@ -44,7 +44,7 @@ public void paint(Graphics g) { Graphics2D graphics2D = (Graphics2D) g.create(); graphics2D.setColor(color); graphics2D.setFont(new Font("Inter",Font.BOLD,30)); - graphics2D.drawString(""+color.getRed()+"/"+color.getGreen()+"/"+color.getBlue(),50+imageForScale.getWidth(null)+100+220, screenHeight/2+20+number*50); + graphics2D.drawString(color.getRed()+"/"+color.getGreen()+"/"+color.getBlue(),50+imageForScale.getWidth(null)+100+220, screenHeight/2+20+number*50); } if (!saboteur.isRemoved()) { AppFrame.setGraphicQuality(g); @@ -56,14 +56,10 @@ public void paint(Graphics g) { pointsY[1] = y - 8; pointsX[2] = x + 6; pointsY[2] = y - 8; - int[] capX = new int[3]; - int[] capY = new int[3]; - capX[0] = x; - capY[0] = y - 22; - capX[1] = x - 8; - capY[1] = y - 15; - capX[2] = x + 8; - capY[2] = y - 15; + + int[] capX = super.setCapX(x); + int[] capY = super.setCapY(y); + Graphics2D graphics2D = (Graphics2D) g.create(); graphics2D.setStroke(new BasicStroke(3)); AffineTransform at = new AffineTransform(); diff --git a/src/main/java/View/SpringView.java b/src/main/java/View/SpringView.java index 68d478f..c98ed3b 100644 --- a/src/main/java/View/SpringView.java +++ b/src/main/java/View/SpringView.java @@ -35,14 +35,14 @@ public SpringView(int x, int y, int r, Spring s, Window v) { gameView = (GameView) v; } private GameView gameView; - private BufferedImage sprite = null; - private Spring spring; - private int r; + private BufferedImage sprite; + private final Spring spring; + private final int r; private int arrowLocX; private int arrowLocY; private double arrowAngle; private PipeView outPipe = null; - private BufferedImage arrowSprite = null; + private BufferedImage arrowSprite; /** * A forrás kirajzolásáért felelős függvény @@ -55,7 +55,7 @@ public void paint(Graphics g) { AffineTransform at = new AffineTransform(); at.translate(arrowLocX, arrowLocY); at.rotate(Math.toRadians(-arrowAngle)); - at.translate(-arrowSprite.getWidth()/2, -arrowSprite.getHeight()/2); + at.translate((double) -arrowSprite.getWidth() /2, (double) -arrowSprite.getHeight() /2); Graphics2D g2 = (Graphics2D) g; g2.drawImage(arrowSprite, at, null); } @@ -123,17 +123,11 @@ public Point getDefaultPlayerPosition() { public Point getRotationCenter() { //meg kéne nézni hány játékos van rajta - Point ret = new Point(x, y); - return ret; + return new Point(x, y); } - @Override public double getPlayerAngle(Player p) { - double[] angles = new double[spring.getPlayers().size()]; - for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; - } - return angles[spring.getPlayers().indexOf(p)]; + return super.getPlayerAngle(p, spring.getPlayers()); } @Override diff --git a/src/main/java/View/SteppableView.java b/src/main/java/View/SteppableView.java index 9d775eb..6bcd51d 100644 --- a/src/main/java/View/SteppableView.java +++ b/src/main/java/View/SteppableView.java @@ -13,19 +13,19 @@ public interface SteppableView { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni */ - public Point getDefaultPlayerPosition(); + Point getDefaultPlayerPosition(); /** * Játékos szögének meghatározása * @param p - játékos * @return - szög */ - public double getPlayerAngle(Player p); + double getPlayerAngle(Player p); /** * Forgatás középpontjának lekérdezése * @return - forgatás középpontja */ - public Point getRotationCenter(); + Point getRotationCenter(); - public Steppable getCorrespondingModelSteppable(); + Steppable getCorrespondingModelSteppable(); } diff --git a/src/main/java/View/Window.java b/src/main/java/View/Window.java index fc2878f..f03bf2a 100644 --- a/src/main/java/View/Window.java +++ b/src/main/java/View/Window.java @@ -1,14 +1,9 @@ package View; -import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.*; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.LinkedList; -import java.awt.image.BufferedImage; import java.io.*; /** @@ -52,10 +47,6 @@ public void addClickable(Clickable c, boolean highClickPriority) { clickables.add(c); } - public void addComponent(JComponent component) { - components.add(component); - } - public void remove(Object o) { drawables.remove(o); clickables.remove(o); From 1a28181afcbd832709f8b997e672069b2087094d Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 11:39:57 +0200 Subject: [PATCH 14/24] Started CisternTest --- src/main/java/Controller/Controller.java | 2 +- src/main/java/Model/Cistern.java | 25 +++++++- src/main/java/View/GameView.java | 13 ---- src/main/java/View/MenuView.java | 10 +-- src/main/java/View/NewGameView.java | 14 ++-- src/test/java/model/CisternTest.java | 81 ++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 29 deletions(-) create mode 100644 src/test/java/model/CisternTest.java diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 133ff1f..dae850d 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -228,7 +228,7 @@ public void create(String name, String type,int x, int y) { gameView.addSpringView(springView); } case "cistern" -> { - Cistern cistern = new Cistern(); + Cistern cistern = new Cistern(Controller.getInstance(),PointCounter.getInstance()); steppables.add(cistern); nodes.add(cistern); cisterns.add(cistern); diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 89ffbe4..9bd27e4 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -29,12 +29,21 @@ public class Cistern extends WaterNode implements Serializable { * Pontszámításhoz használt singleton */ private final PointCounter counter; - + private Controller controller; /** * Ciszterna konstruktora */ - public Cistern() { - counter = PointCounter.getInstance(); + public Cistern(Controller controller, PointCounter counter) { + this.controller= controller; + this.counter = counter; + } + + public Controller getController() { + return controller; + } + + public void setController(Controller controller) { + this.controller = controller; } /** @@ -144,6 +153,8 @@ public LinkedList getCreatedPickupables() { */ @Override public boolean canPickUpPump(Mechanic m){ + + System.out.println(generatedPumps); return m.standingOn==this && !generatedPumps.isEmpty() && m.getHeldItems()==null; } /** @@ -153,6 +164,8 @@ public boolean canPickUpPump(Mechanic m){ */ @Override public boolean canPickUpPipe(Mechanic m){ + + System.out.println(m.getHeldItems()); return m.standingOn==this && !generatedPipes.isEmpty() && m.getHeldItems()==null; } @@ -211,6 +224,9 @@ boolean canBePlacedDown(Pump p) { public LinkedList getGeneratedPipes() { return generatedPipes; } + public void addGeneratedPipe(Pipe p) { + generatedPipes.add(p); + } /** * A generált pumpák listájának gettere * @return a lista @@ -219,5 +235,8 @@ public LinkedList getGeneratedPumps() { return generatedPumps; } + public void addGeneratedPump(Pump p) { + generatedPumps.add(p); + } } diff --git a/src/main/java/View/GameView.java b/src/main/java/View/GameView.java index 2d7b0dd..1ed4e7d 100644 --- a/src/main/java/View/GameView.java +++ b/src/main/java/View/GameView.java @@ -41,25 +41,12 @@ public void mapSetup(String file) { private boolean ended = false; private final Button exit; - - private AppFrame frame; - - /** - * Frame beállítása. - * - * @param frame - a beállítandó frame. - */ - public void setFrame(AppFrame frame) { - this.frame = frame; - } - /** * Konstruktor. * * @param frame - a frame, amelyen a játék nézet megjelenik. */ public GameView(AppFrame frame) { - this.frame = frame; exit = new Button(frame.getWidth() - 80, 10, 50, 50, this); exit.img = ImageUtility.scaleImage(getExitButton(), 45); exit.option = WindowOptions.EXIT; diff --git a/src/main/java/View/MenuView.java b/src/main/java/View/MenuView.java index 8792693..35a24ad 100644 --- a/src/main/java/View/MenuView.java +++ b/src/main/java/View/MenuView.java @@ -80,27 +80,27 @@ public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseEntered(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseExited(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseDragged(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseMoved(MouseEvent e) { - + // Not used, intentionally left blank } /** diff --git a/src/main/java/View/NewGameView.java b/src/main/java/View/NewGameView.java index fdcaaff..d1474a8 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/View/NewGameView.java @@ -144,37 +144,37 @@ public void paint(Graphics g) { */ @Override public void update() { - + // Not used, intentionally left blank } @Override public void mousePressed(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseReleased(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseEntered(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseExited(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseDragged(MouseEvent e) { - + // Not used, intentionally left blank } @Override public void mouseMoved(MouseEvent e) { - + // Not used, intentionally left blank } /** diff --git a/src/test/java/model/CisternTest.java b/src/test/java/model/CisternTest.java new file mode 100644 index 0000000..6b0a9ef --- /dev/null +++ b/src/test/java/model/CisternTest.java @@ -0,0 +1,81 @@ +package model; + +import Controller.Controller; +import Model.Cistern; +import Model.PointCounter; +import Model.Pipe; +import Model.Mechanic; +import Model.Pump; +import View.GameView; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; + +import java.security.SecureRandom; +import java.util.LinkedList; + +import static junit.framework.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +public class CisternTest { + + private Cistern cistern; + private Controller mockController; + private PointCounter mockPointCounter; + private GameView mockGameView; + + @BeforeEach + public void setUp() { + mockController = mock(Controller.class); + mockPointCounter = mock(PointCounter.class); + mockGameView = mock(GameView.class); + + cistern = new Cistern(mockController, mockPointCounter); + } + + @Test + void testGetController() { + assertEquals(mockController, cistern.getController()); + } + + @Test + void testSetController() { + Controller newController = Mockito.mock(Controller.class); + cistern.setController(newController); + assertEquals(newController, cistern.getController()); + } + + @Test + public void testPickedUpFrom() { + Pipe mockPipe = mock(Pipe.class); + cistern.getCreatedPickupables().add(mockPipe); + + assertTrue(cistern.pickedUpFrom(mockPipe)); + assertFalse(cistern.getCreatedPickupables().contains(mockPipe)); + } + + @Test + public void testPlacedDownToPipe() { + Pipe mockPipe = mock(Pipe.class); + + assertTrue(cistern.placedDownTo(mockPipe)); + assertTrue(cistern.getPipes().contains(mockPipe)); + verify(mockPipe).addWaterNode(cistern); + } + + @Test + public void testWaterFlow() { + Pipe mockPipe = mock(Pipe.class); + cistern.getPipes().add(mockPipe); + when(mockPipe.loseWater(1)).thenReturn(1); + + cistern.waterFlow(); + + verify(mockPipe, times(1)).loseWater(1); + verify(mockPointCounter, times(1)).addMechanicPoints(1); + } + +} + From b34b815906cac0c26dd82d7417fce26313c0c669 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 11:43:09 +0200 Subject: [PATCH 15/24] Fix Test --- src/test/java/model/CisternTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/model/CisternTest.java b/src/test/java/model/CisternTest.java index 6b0a9ef..23be0b6 100644 --- a/src/test/java/model/CisternTest.java +++ b/src/test/java/model/CisternTest.java @@ -24,7 +24,6 @@ public class CisternTest { private Cistern cistern; private Controller mockController; private PointCounter mockPointCounter; - private GameView mockGameView; @BeforeEach public void setUp() { @@ -68,8 +67,10 @@ public void testPlacedDownToPipe() { @Test public void testWaterFlow() { Pipe mockPipe = mock(Pipe.class); - cistern.getPipes().add(mockPipe); + cistern.addPipe(mockPipe); + cistern.setActiveIn(mockPipe); when(mockPipe.loseWater(1)).thenReturn(1); + when(mockController.getObjectName(any())).thenReturn("Pipe"); cistern.waterFlow(); From 59efb3ff225ea32a3778fed2103fa3c3f7c7cbcc Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 11:44:21 +0200 Subject: [PATCH 16/24] Delete gameview from test --- src/test/java/model/CisternTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/model/CisternTest.java b/src/test/java/model/CisternTest.java index 23be0b6..fef087e 100644 --- a/src/test/java/model/CisternTest.java +++ b/src/test/java/model/CisternTest.java @@ -29,7 +29,6 @@ public class CisternTest { public void setUp() { mockController = mock(Controller.class); mockPointCounter = mock(PointCounter.class); - mockGameView = mock(GameView.class); cistern = new Cistern(mockController, mockPointCounter); } From 38f47c20622f6b3437afc3ddafa04120d4f20b00 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 11:56:43 +0200 Subject: [PATCH 17/24] Fix CisternTest 2 --- src/main/java/Model/Cistern.java | 6 ------ src/test/java/model/CisternTest.java | 27 ++++++++------------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 9bd27e4..00b8fee 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -224,9 +224,6 @@ boolean canBePlacedDown(Pump p) { public LinkedList getGeneratedPipes() { return generatedPipes; } - public void addGeneratedPipe(Pipe p) { - generatedPipes.add(p); - } /** * A generált pumpák listájának gettere * @return a lista @@ -235,8 +232,5 @@ public LinkedList getGeneratedPumps() { return generatedPumps; } - public void addGeneratedPump(Pump p) { - generatedPumps.add(p); - } } diff --git a/src/test/java/model/CisternTest.java b/src/test/java/model/CisternTest.java index fef087e..cc69341 100644 --- a/src/test/java/model/CisternTest.java +++ b/src/test/java/model/CisternTest.java @@ -4,19 +4,11 @@ import Model.Cistern; import Model.PointCounter; import Model.Pipe; -import Model.Mechanic; -import Model.Pump; -import View.GameView; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import java.security.SecureRandom; -import java.util.LinkedList; - -import static junit.framework.Assert.assertEquals; -import static org.junit.jupiter.api.Assertions.*; +import static junit.framework.Assert.*; import static org.mockito.Mockito.*; public class CisternTest { @@ -24,13 +16,16 @@ public class CisternTest { private Cistern cistern; private Controller mockController; private PointCounter mockPointCounter; + private Pipe mockPipe; @BeforeEach - public void setUp() { + public void init() { mockController = mock(Controller.class); mockPointCounter = mock(PointCounter.class); + mockPipe= mock(Pipe.class); cistern = new Cistern(mockController, mockPointCounter); + cistern.addPipe(mockPipe); } @Test @@ -56,8 +51,6 @@ public void testPickedUpFrom() { @Test public void testPlacedDownToPipe() { - Pipe mockPipe = mock(Pipe.class); - assertTrue(cistern.placedDownTo(mockPipe)); assertTrue(cistern.getPipes().contains(mockPipe)); verify(mockPipe).addWaterNode(cistern); @@ -65,16 +58,12 @@ public void testPlacedDownToPipe() { @Test public void testWaterFlow() { - Pipe mockPipe = mock(Pipe.class); - cistern.addPipe(mockPipe); - cistern.setActiveIn(mockPipe); - when(mockPipe.loseWater(1)).thenReturn(1); - when(mockController.getObjectName(any())).thenReturn("Pipe"); + when(mockPipe.loseWater(anyInt())).thenReturn(1); cistern.waterFlow(); - verify(mockPipe, times(1)).loseWater(1); - verify(mockPointCounter, times(1)).addMechanicPoints(1); + verify(mockPipe).loseWater(1); + verify(mockPointCounter).addMechanicPoints(1); } } From f870339f2bf93e3c5c52271e3344a82bfe1571e3 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 12:07:16 +0200 Subject: [PATCH 18/24] Cistern problems --- .gitignore | 2 ++ src/main/java/Model/Cistern.java | 2 +- src/test/java/model/CisternTest.java | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86c056e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +target/ diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 00b8fee..51a2f94 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -100,7 +100,7 @@ public void waterFlow() { for (Pipe p : pipes) { int lost = p.loseWater(1); counter.addMechanicPoints(lost); - IO_Manager.write(Controller.getInstance().getObjectName(p) + " lost " + lost, Controller.filetoWrite != null); + IO_Manager.write(controller.getObjectName(p) + " lost " + lost, Controller.filetoWrite != null); } } diff --git a/src/test/java/model/CisternTest.java b/src/test/java/model/CisternTest.java index cc69341..d91373f 100644 --- a/src/test/java/model/CisternTest.java +++ b/src/test/java/model/CisternTest.java @@ -10,6 +10,7 @@ import static junit.framework.Assert.*; import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.anyInt; public class CisternTest { From 146fdf8d74bae84a4f1638cb6bec01b3442d896b Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 12:56:17 +0200 Subject: [PATCH 19/24] Format Controller, rename packages --- .idea/.gitignore | 8 + .idea/compiler.xml | 13 ++ .idea/encodings.xml | 7 + .idea/jarRepositories.xml | 20 ++ .idea/misc.xml | 12 ++ .idea/vcs.xml | 6 + src/main/java/Assets/Strings.java | 33 --- src/main/java/Controller/Controller.java | 198 +++++++++--------- src/main/java/Model/Cistern.java | 4 +- src/main/java/Model/Pipe.java | 4 +- .../java/{Assets => assets}/0-reference.png | Bin src/main/java/{Assets => assets}/1-bg.png | Bin .../{Assets => assets}/1-button-1-text.png | Bin .../java/{Assets => assets}/1-button-1.png | Bin .../{Assets => assets}/1-button-2-text.png | Bin .../java/{Assets => assets}/1-button-2.png | Bin .../{Assets => assets}/1-button-3-text.png | Bin .../java/{Assets => assets}/1-button-3.png | Bin src/main/java/{Assets => assets}/1-layout.png | Bin src/main/java/{Assets => assets}/1-title.png | Bin .../2-button-color-picker.png | Bin .../{Assets => assets}/2-button-minus.png | Bin .../java/{Assets => assets}/2-button-plus.png | Bin src/main/java/{Assets => assets}/2-layout.png | Bin .../java/{Assets => assets}/2-map-preview.png | Bin src/main/java/{Assets => assets}/2-title.png | Bin .../java/{Assets => assets}/3-button-save.png | Bin .../{Assets => assets}/3-cistern-filled.png | Bin .../java/{Assets => assets}/3-cistern.png | Bin src/main/java/{Assets => assets}/3-layout.png | Bin .../3-player-mechanic-cap.png | Bin .../{Assets => assets}/3-player-mechanic.png | Bin .../3-player-saboteur-cap.png | Bin .../{Assets => assets}/3-player-saboteur.png | Bin .../{Assets => assets}/3-popup-atallit.png | Bin .../{Assets => assets}/3-popup-felemel.png | Bin .../java/{Assets => assets}/3-popup-lerak.png | Bin .../{Assets => assets}/3-popup-lyukaszt.png | Bin .../{Assets => assets}/3-popup-megken.png | Bin .../java/{Assets => assets}/3-popup-mozog.png | Bin .../{Assets => assets}/3-popup-passzol.png | Bin .../{Assets => assets}/3-popup-ragaszt.png | Bin .../{Assets => assets}/3-popup-szerel.png | Bin .../{Assets => assets}/3-pump-indicator.png | Bin .../{Assets => assets}/3-score-divider.png | Bin .../{Assets => assets}/3-spring-filled.png | Bin src/main/java/{Assets => assets}/3-spring.png | Bin .../3-zigzagline-fallback.png | Bin src/main/java/{Assets => assets}/4-layout.png | Bin .../{Assets => assets}/4-player-wincap.png | Bin src/main/java/assets/Strings.java | 33 +++ src/main/java/{Assets => assets}/map1.txt | 0 src/main/java/{Assets => assets}/map2.txt | 0 src/main/java/{Assets => assets}/palya2.png | Bin .../java/{View => view}/AddPlayerButton.java | 2 +- src/main/java/{View => view}/AppFrame.java | 2 +- src/main/java/{View => view}/AppPanel.java | 2 +- src/main/java/{View => view}/Button.java | 4 +- .../{View => view}/ChangeMaxPointButton.java | 2 +- .../{View => view}/CharacterCreation.java | 2 +- src/main/java/{View => view}/CisternView.java | 2 +- src/main/java/{View => view}/Clickable.java | 2 +- src/main/java/{View => view}/ColorPicker.java | 2 +- .../java/{View => view}/CreatePopUpBar.java | 2 +- src/main/java/{View => view}/Drawable.java | 2 +- src/main/java/{View => view}/GameView.java | 6 +- .../java/{View => view}/ImageUtility.java | 2 +- .../java/{View => view}/MechanicView.java | 4 +- src/main/java/{View => view}/MenuView.java | 4 +- src/main/java/{View => view}/MouseIn.java | 2 +- src/main/java/{View => view}/NewGameView.java | 4 +- src/main/java/{View => view}/Pictures.java | 2 +- src/main/java/{View => view}/PipeView.java | 2 +- src/main/java/{View => view}/PopUpBar.java | 2 +- src/main/java/{View => view}/PopUpButton.java | 2 +- src/main/java/{View => view}/PumpView.java | 4 +- .../java/{View => view}/SaboteurView.java | 4 +- src/main/java/{View => view}/SpringView.java | 4 +- .../java/{View => view}/SteppableView.java | 2 +- src/main/java/{View => view}/Window.java | 2 +- .../java/{View => view}/WindowOptions.java | 2 +- 81 files changed, 241 insertions(+), 169 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml delete mode 100644 src/main/java/Assets/Strings.java rename src/main/java/{Assets => assets}/0-reference.png (100%) rename src/main/java/{Assets => assets}/1-bg.png (100%) rename src/main/java/{Assets => assets}/1-button-1-text.png (100%) rename src/main/java/{Assets => assets}/1-button-1.png (100%) rename src/main/java/{Assets => assets}/1-button-2-text.png (100%) rename src/main/java/{Assets => assets}/1-button-2.png (100%) rename src/main/java/{Assets => assets}/1-button-3-text.png (100%) rename src/main/java/{Assets => assets}/1-button-3.png (100%) rename src/main/java/{Assets => assets}/1-layout.png (100%) rename src/main/java/{Assets => assets}/1-title.png (100%) rename src/main/java/{Assets => assets}/2-button-color-picker.png (100%) rename src/main/java/{Assets => assets}/2-button-minus.png (100%) rename src/main/java/{Assets => assets}/2-button-plus.png (100%) rename src/main/java/{Assets => assets}/2-layout.png (100%) rename src/main/java/{Assets => assets}/2-map-preview.png (100%) rename src/main/java/{Assets => assets}/2-title.png (100%) rename src/main/java/{Assets => assets}/3-button-save.png (100%) rename src/main/java/{Assets => assets}/3-cistern-filled.png (100%) rename src/main/java/{Assets => assets}/3-cistern.png (100%) rename src/main/java/{Assets => assets}/3-layout.png (100%) rename src/main/java/{Assets => assets}/3-player-mechanic-cap.png (100%) rename src/main/java/{Assets => assets}/3-player-mechanic.png (100%) rename src/main/java/{Assets => assets}/3-player-saboteur-cap.png (100%) rename src/main/java/{Assets => assets}/3-player-saboteur.png (100%) rename src/main/java/{Assets => assets}/3-popup-atallit.png (100%) rename src/main/java/{Assets => assets}/3-popup-felemel.png (100%) rename src/main/java/{Assets => assets}/3-popup-lerak.png (100%) rename src/main/java/{Assets => assets}/3-popup-lyukaszt.png (100%) rename src/main/java/{Assets => assets}/3-popup-megken.png (100%) rename src/main/java/{Assets => assets}/3-popup-mozog.png (100%) rename src/main/java/{Assets => assets}/3-popup-passzol.png (100%) rename src/main/java/{Assets => assets}/3-popup-ragaszt.png (100%) rename src/main/java/{Assets => assets}/3-popup-szerel.png (100%) rename src/main/java/{Assets => assets}/3-pump-indicator.png (100%) rename src/main/java/{Assets => assets}/3-score-divider.png (100%) rename src/main/java/{Assets => assets}/3-spring-filled.png (100%) rename src/main/java/{Assets => assets}/3-spring.png (100%) rename src/main/java/{Assets => assets}/3-zigzagline-fallback.png (100%) rename src/main/java/{Assets => assets}/4-layout.png (100%) rename src/main/java/{Assets => assets}/4-player-wincap.png (100%) create mode 100644 src/main/java/assets/Strings.java rename src/main/java/{Assets => assets}/map1.txt (100%) rename src/main/java/{Assets => assets}/map2.txt (100%) rename src/main/java/{Assets => assets}/palya2.png (100%) rename src/main/java/{View => view}/AddPlayerButton.java (99%) rename src/main/java/{View => view}/AppFrame.java (99%) rename src/main/java/{View => view}/AppPanel.java (97%) rename src/main/java/{View => view}/Button.java (98%) rename src/main/java/{View => view}/ChangeMaxPointButton.java (99%) rename src/main/java/{View => view}/CharacterCreation.java (99%) rename src/main/java/{View => view}/CisternView.java (99%) rename src/main/java/{View => view}/Clickable.java (97%) rename src/main/java/{View => view}/ColorPicker.java (99%) rename src/main/java/{View => view}/CreatePopUpBar.java (99%) rename src/main/java/{View => view}/Drawable.java (99%) rename src/main/java/{View => view}/GameView.java (99%) rename src/main/java/{View => view}/ImageUtility.java (99%) rename src/main/java/{View => view}/MechanicView.java (99%) rename src/main/java/{View => view}/MenuView.java (98%) rename src/main/java/{View => view}/MouseIn.java (99%) rename src/main/java/{View => view}/NewGameView.java (99%) rename src/main/java/{View => view}/Pictures.java (99%) rename src/main/java/{View => view}/PipeView.java (99%) rename src/main/java/{View => view}/PopUpBar.java (99%) rename src/main/java/{View => view}/PopUpButton.java (99%) rename src/main/java/{View => view}/PumpView.java (99%) rename src/main/java/{View => view}/SaboteurView.java (98%) rename src/main/java/{View => view}/SpringView.java (98%) rename src/main/java/{View => view}/SteppableView.java (97%) rename src/main/java/{View => view}/Window.java (99%) rename src/main/java/{View => view}/WindowOptions.java (93%) diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e86ef1f --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f0f8287 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/Assets/Strings.java b/src/main/java/Assets/Strings.java deleted file mode 100644 index 1cffdb0..0000000 --- a/src/main/java/Assets/Strings.java +++ /dev/null @@ -1,33 +0,0 @@ -package Assets; - -public class Strings { - public final static String WRONG_ATTR = "wrong attribute name"; - public final static String WRONG_PIPE = "wrong pipe name"; - public final static String WRONG_PLAYER = "wrong player name"; - public final static String WRONG_MECH = "wrong mechanic name"; - public final static String FELL_DOWN_STR = "fellDown"; - public final static String STUCK_STR = "stuck"; - public final static String STANDING_ON_STR = "standingOn"; - public final static String STATE_STR = "state"; - public final static String HELD_ITEMS_STR = "heldItems"; - public final static String PIPES_STR = "pipes"; - public final static String CREATED_PICKUPABLES_STR = "createdPickupables"; - public final static String PLAYERS_STR = "players"; - public final static String SABOTEUR_POINTS_STR = "saboteurPoints"; - public final static String MECHANIC_POINTS_STR = "mechanicPoints"; - public final static String POINTS_TO_WIN_STR = "pointsToWin"; - public final static String MOVE_ACTION_STR = "moveAction"; - public final static String SPECIAL_ACTION_STR = "specialAction"; - public final static String TURN_OVER_STR = "turnOver"; - public final static String BROKEN_STR = "broken"; - public final static String WATER_CAPACITY_STR = "waterCapacity"; - public final static String HELD_WATER_STR = "heldWater"; - public final static String MAXIMUM_PIPES_STR = "maximumPipes"; - public final static String ACTIVE_IN_STR = "activeIn"; - public final static String ACTIVE_OUT_STR = "activeOut"; - public final static String READY_TO_PIERCE_STR = "readyToPierce"; - public final static String LUBRICATED_STR = "lubricated"; - public final static String GLUED_STR = "glued"; - public final static String BEING_HELD_STR = "beingHeld"; - public final static String NODES_STR = "nodes"; -} diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index dae850d..1ace384 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -1,8 +1,9 @@ package Controller; -import static Assets.Strings.*; +import static assets.Strings.*; + import Model.*; -import View.*; +import view.*; import java.awt.*; import java.io.*; @@ -18,7 +19,7 @@ public class Controller implements Serializable { private static Controller controller = null; - private final boolean frameCounter = false; + private static final boolean frameCounter = false; //Singleton private Controller() { @@ -40,7 +41,7 @@ static public Controller getInstance() { */ private final boolean running = true; /** - * A játékosok actionkezeléséhez szükséges lista. + * A játékosok actionkezeléséhez szükséges lista. */ private final LinkedList turnOrder = new LinkedList<>(); /** @@ -80,11 +81,11 @@ static public Controller getInstance() { /** * Az új játék ablaknál létrehozott szerelők száma-1(indexe) */ - private int mechNumber=-1; + private int mechNumber = -1; /** * Az új játék ablaknál létrehozott szabotőrök száma-1(indexe) */ - private int sabNumber=-1; + private int sabNumber = -1; /** * A panelt (JPanel) reprezentáló osztály @@ -110,17 +111,17 @@ static public Controller getInstance() { /** * A gameloop-ért fellelős függvény */ - public void run(){ - int frames=0; - long previousTimeInNanoSec=System.nanoTime(); - long previousTimeInMilliSec=System.currentTimeMillis(); - int FPS=120; - double timePerFrame=1000000000.0/FPS; - double elapsedFrames=0; - while(running){ - elapsedFrames+=(System.nanoTime()-previousTimeInNanoSec)/timePerFrame; - previousTimeInNanoSec=System.nanoTime(); - if(elapsedFrames>=1){ + public void run() { + int frames = 0; + long previousTimeInNanoSec = System.nanoTime(); + long previousTimeInMilliSec = System.currentTimeMillis(); + int FPS = 120; + double timePerFrame = 1000000000.0 / FPS; + double elapsedFrames = 0; + while (running) { + elapsedFrames += (System.nanoTime() - previousTimeInNanoSec) / timePerFrame; + previousTimeInNanoSec = System.nanoTime(); + if (elapsedFrames >= 1) { update(); if (frame != null) panel.repaint(); @@ -128,10 +129,10 @@ public void run(){ elapsedFrames--; } //For FPS count - if(System.currentTimeMillis()-previousTimeInMilliSec>=1000){ - if(frameCounter) System.out.println(frames); - frames=0; - previousTimeInMilliSec=System.currentTimeMillis(); + if (System.currentTimeMillis() - previousTimeInMilliSec >= 1000) { + if (frameCounter) System.out.println(frames); + frames = 0; + previousTimeInMilliSec = System.currentTimeMillis(); } } } @@ -139,19 +140,19 @@ public void run(){ /** * Ez az update hívódik meg a gameloopból, ez osztja szét a különböző nézetek felé */ - public void update(){ + public void update() { switch (WindowOptions.windowOption) { case MENU -> menuView.update(); case NEWGAME -> newGameView.update(); case GAME -> gameView.update(); - default -> { - throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); - } + default -> throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); + } } /** * Ez a paint hívódik a frame-repaint hatására, ez osztja szét a különböző nézetek felé + * * @param g - A frame grafikus megjelenítése, amire rajzolunk */ public void paint(Graphics g) { @@ -159,9 +160,8 @@ public void paint(Graphics g) { case MENU -> menuView.paint(g); case NEWGAME -> newGameView.paint(g); case GAME -> gameView.paint(g); - default -> { - throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); - } + default -> throw new IllegalStateException("Unexpected value: " + WindowOptions.windowOption); + } } @@ -175,8 +175,8 @@ public Player getActivePlayer() { /** * A passzolás kivitelezésére használt függvény */ - public void pass(){ - if(turnOrder.getFirst().getState()==PlayerActionState.SPECIAL_ACTION) { + public void pass() { + if (turnOrder.getFirst().getState() == PlayerActionState.SPECIAL_ACTION) { turnOrder.getFirst().setState(PlayerActionState.TURN_OVER); turnOver(); } @@ -184,12 +184,13 @@ public void pass(){ /** * A létrehozást megoldó függvény, amit parancsként kiadva tudunk új játékelemet helyezni a pályára + * * @param name - a játékelem neve * @param type - a játékelem típusa - * @param x - a játékelem kirajzolásához tartozó x koordináta - * @param y - a játékelem kirajzolásához tartozó y koordináta + * @param x - a játékelem kirajzolásához tartozó x koordináta + * @param y - a játékelem kirajzolásához tartozó y koordináta */ - public void create(String name, String type,int x, int y) { + public void create(String name, String type, int x, int y) { switch (type) { case "mechanic" -> { @@ -215,7 +216,7 @@ public void create(String name, String type,int x, int y) { pumps.add(pump); pickupables.add(pump); objectCatalog.put(name, pump); - PumpView pumpView = new PumpView(x,y,25,pump, gameView); + PumpView pumpView = new PumpView(x, y, 25, pump, gameView); gameView.addPumpView(pumpView); } case "spring" -> { @@ -224,16 +225,16 @@ public void create(String name, String type,int x, int y) { nodes.add(spring); springs.add(spring); objectCatalog.put(name, spring); - SpringView springView = new SpringView(x,y,30,spring,gameView); + SpringView springView = new SpringView(x, y, 30, spring, gameView); gameView.addSpringView(springView); } case "cistern" -> { - Cistern cistern = new Cistern(Controller.getInstance(),PointCounter.getInstance()); + Cistern cistern = new Cistern(Controller.getInstance(), PointCounter.getInstance()); steppables.add(cistern); nodes.add(cistern); cisterns.add(cistern); objectCatalog.put(name, cistern); - CisternView cisternView = new CisternView(x,y,30,cistern,gameView); + CisternView cisternView = new CisternView(x, y, 30, cistern, gameView); gameView.addCisternView(cisternView); } case "pipe" -> { @@ -250,12 +251,13 @@ public void create(String name, String type,int x, int y) { /** * Az összekötés parancs függvénye, összeköti a neki adott csövet egy node-al - * @param pipeName - az összekötni kívánt cső + * + * @param pipeName - az összekötni kívánt cső * @param wNodeName - az összekötni kívánt node */ public void connect(String pipeName, String wNodeName) { - if (!pipes.contains((Pipe)objectCatalog.get(pipeName))) { + if (!pipes.contains((Pipe) objectCatalog.get(pipeName))) { IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } @@ -276,7 +278,8 @@ public void connect(String pipeName, String wNodeName) { /** * A mozgás parancsának függvénye, a neki adott játékos a neki adott léphető elemre lép, ha tud - * @param playerName - a mozgó játékos + * + * @param playerName - a mozgó játékos * @param steppableName - az az elem amire mozog */ public void move(String playerName, String steppableName) { @@ -308,6 +311,7 @@ public void move(String playerName, String steppableName) { /** * A lyukasztás parancs függvénye, a neki adott játékos kilyukasztja azt az elemet amin áll(csövet),ha tudja + * * @param playerName - a lyukasztó játékos */ public void pierce(String playerName) { @@ -323,8 +327,10 @@ public void pierce(String playerName) { IO_Manager.write(playerName + ".standingOn.broken = " + "true", Controller.filetoWrite != null); } + /** * A ragacsozás parancs függvénye, a neki adott játékos bekeni ragaccsal azt az elemet amin áll(csövet),ha tudja + * * @param playerName - a ragacsozó játékos */ public void glue(String playerName) { @@ -343,6 +349,7 @@ public void glue(String playerName) { /** * A csúszósá tétel parancsának függvénye, a neki adott szabotőr csúszóssá teszi azt az elemet amin áll(csövet),ha tudja + * * @param saboteurName - a csúszóssá tévő szabotőr */ public void lubricate(String saboteurName) { @@ -360,6 +367,7 @@ public void lubricate(String saboteurName) { /** * A javítás parancs függvénye, a neki adott szerelő megjavítja azt az elemet amin áll,ha tudja + * * @param mechanicName - a lyukasztó játékos */ public void repair(String mechanicName) { @@ -381,8 +389,9 @@ public void repair(String mechanicName) { /** * Az átirányításért parancsért felelős függvény, meghívja az adott játékos redirect függvényét a paraméterként megadott csövekkel. - * @param playerName - a játékos aki átirányít - * @param inPipeName - az a cső amit bevezetőnek akar + * + * @param playerName - a játékos aki átirányít + * @param inPipeName - az a cső amit bevezetőnek akar * @param outPipeName - az a cső amit kivezetőnek akar */ public void redirect(String playerName, String inPipeName, String outPipeName) { @@ -393,13 +402,13 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { } Player p = (Player) objectCatalog.get(playerName); - if (!pipes.contains((Pipe)objectCatalog.get(inPipeName))) { + if (!pipes.contains((Pipe) objectCatalog.get(inPipeName))) { IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe in = (Pipe) objectCatalog.get(inPipeName); - if (!pipes.contains((Pipe)objectCatalog.get(outPipeName))) { + if (!pipes.contains((Pipe) objectCatalog.get(outPipeName))) { IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } @@ -414,8 +423,9 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { /** * A felvevés parancsért felelős függvény, meghívja az adott szerelőre és Pickupable-re a szerelő PickUp függvényét. + * * @param mechanicName - a szerelő aki felvesz - * @param pickupName - a felvehető játékelem amit felvesz + * @param pickupName - a felvehető játékelem amit felvesz */ public void pickup(String mechanicName, String pickupName) { @@ -439,6 +449,7 @@ public void pickup(String mechanicName, String pickupName) { /** * A lerakás parancsért felelős függvény, meghívja az adott szerelő PlaceDown függvényét + * * @param mechanicName - a szerelő aki lerak */ public void placedown(String mechanicName) { @@ -453,8 +464,10 @@ public void placedown(String mechanicName) { IO_Manager.write(mechanicName + ".heldItems = null", Controller.filetoWrite != null); } + /** * Attribútumok lekérdezésének parancsát teljesítő függvény + * * @param objectName - az objektum neve amit lekérdezünk * @param attribName - az objektum egyik attribútumának neve amit le akarunk kérdezni */ @@ -532,8 +545,9 @@ public void stateGet(String objectName, String attribName) { /** * Attribútumok beállításának parancsát teljesítő függvény - * @param objectName - az objektum neve aminek egyik értékét állítjuk be - * @param attribName - az objektum egyik attribútumának neve amit be akarunk állítani + * + * @param objectName - az objektum neve aminek egyik értékét állítjuk be + * @param attribName - az objektum egyik attribútumának neve amit be akarunk állítani * @param attribValue - az érték amire be akarjuk állítani */ public void stateSet(String objectName, String attribName, String attribValue) { @@ -623,7 +637,6 @@ public void turnOver() { turnOrder.getFirst().setFellDown(false); SecureRandom random = new SecureRandom(); int chance = random.nextInt(0, nodes.size()); - boolean ignoreStates = Player.isIgnoreStates(); Player.setIgnoreStates(true); turnOrder.getFirst().move(nodes.get(chance)); Player.setIgnoreStates(false); @@ -674,17 +687,16 @@ public void nextTurn() { } } //end of game? - if (started) { - if (counter.getMechanicPoints() >= counter.getPointsToWin() || counter.getSaboteurPoints() >= counter.getPointsToWin()) - endGame(); - } + if (started && (counter.getMechanicPoints() >= counter.getPointsToWin() || counter.getSaboteurPoints() >= counter.getPointsToWin())) + endGame(); } /** * A ciszternán generálás parancsának függvénye, meghívja az adott ciszterna GeneratePickupables függvényét a megadott nevekkel. + * * @param cisternName - a ciszterna neve amin generáltatunk - * @param pipeName - a generált cső neve - * @param pumpName - a generált pumpa neve + * @param pipeName - a generált cső neve + * @param pumpName - a generált pumpa neve */ public void generate(String cisternName, String pipeName, String pumpName) { if (!cisterns.contains((Cistern) objectCatalog.get(cisternName))) { @@ -702,6 +714,7 @@ public void generate(String cisternName, String pipeName, String pumpName) { /** * A vízfolyás parancs függvénye, adott csomópontra hívja meg a vízfolyást. + * * @param wNodeName - a csomópont neve */ public void waterFlow(String wNodeName) { @@ -719,56 +732,34 @@ public void waterFlow(String wNodeName) { /** * Szerializált mentés parancs kivitelezésére használt függvény + * * @param filename - a fájl amibe mentünk */ public void save(String filename) { - ObjectOutputStream oos = null; - FileOutputStream fops = null; - try { - fops = new FileOutputStream("program.txt"); - oos = new ObjectOutputStream(fops); + try (FileOutputStream fops = new FileOutputStream("program.txt"); + ObjectOutputStream oos = new ObjectOutputStream(fops) + ) { oos.writeObject(this); } catch (Exception e) { System.err.println("Error saving state to " + filename + ": " + e.getMessage()); - } finally { - try { - if (oos != null) { - oos.close(); - } - if (fops != null) { - fops.close(); - } - } catch (IOException e) { - System.err.println("Error closing output streams: " + e.getMessage()); - } } IO_Manager.write("saved state to program.txt", Controller.filetoWrite != null); } /** * Szerializált betöltés parancs kivitelezésére használt függvény + * * @param filename - a fájl amiből betöltünk */ public void load(String filename) { - ObjectInputStream ois = null; - FileInputStream fis = null; - try { - fis = new FileInputStream("program.txt"); - ois = new ObjectInputStream(fis); + + try ( + FileInputStream fis = new FileInputStream("program.txt"); + ObjectInputStream ois = new ObjectInputStream(fis); + ) { controller = (Controller) ois.readObject(); } catch (Exception e) { System.err.println("Error loading state from " + filename + ": " + e.getMessage()); - } finally { - try { - if (ois != null) { - ois.close(); - } - if (fis != null) { - fis.close(); - } - } catch (IOException e) { - System.err.println("Error closing input streams: " + e.getMessage()); - } } IO_Manager.write("loaded state from program.txt", Controller.filetoWrite != null); } @@ -785,8 +776,10 @@ public void endGame() { IO_Manager.write("mechanicPoints = " + counter.getMechanicPoints(), Controller.filetoWrite != null); } + /** * Visszaadja az objektkatalógusban található elemet, ha benne van + * * @param o - az objektum amit keresünk * @return - az objektum neve */ @@ -797,6 +790,7 @@ public String getObjectName(Object o) { } return null; } + /** * A játék kezdete, megvizsgálja, hogy van-e elég játékos, random elhelyezi őket egy waternode-on, * /mevizsgálja, hogy minden csőnek mindkét vége bekötött-e (funkcionális követelmény), illetve @@ -805,7 +799,7 @@ public String getObjectName(Object o) { public void startGame() { - for (Pipe p :pipes) { + for (Pipe p : pipes) { PipeView pipeView = new PipeView( gameView.getDrawableByCorrespondingModel(p.getNodes().getFirst()), gameView.getDrawableByCorrespondingModel(p.getNodes().getLast()), @@ -850,6 +844,7 @@ public void startGame() { /** * Kiírja egy lista elemeinek neveit a megadott kimenet szerint + * * @param list - a lista amit kiiratunk * @return - a kiiratott szöveg */ @@ -869,6 +864,7 @@ private String listWrite(LinkedList list) { /** * Eltávolítja az adott objektumot abból a listá(k)ból, ami(k)ben benne van. + * * @param p - az objektum amit eltávolítunk (Csak Pipe-ra kell) */ public void removeObject(Pipe p) { @@ -877,31 +873,34 @@ public void removeObject(Pipe p) { /** * Az új játék ablaknál egy szerelő színét és nevét beállító függvény + * * @param temp - a szerelő neve - * @param cp - a colorpicker amivel színt választottunk + * @param cp - a colorpicker amivel színt választottunk * @return - a szerelő nézete */ public MechanicView makeMechanic(String temp, ColorPicker cp) { - Mechanic m= (Mechanic) objectCatalog.get(temp); - if(mechanics.contains(m)){ - MechanicView mechanicView= (MechanicView) gameView.getDrawableByCorrespondingModel(m); + Mechanic m = (Mechanic) objectCatalog.get(temp); + if (mechanics.contains(m)) { + MechanicView mechanicView = (MechanicView) gameView.getDrawableByCorrespondingModel(m); mechanicView.setColor(cp.getUserColor()); mechNumber++; mechanicView.setNumber(mechNumber); return mechanicView; } -return null; + return null; } + /** * Az új játék ablaknál egy szabotőr színét és nevét beállító függvény + * * @param temp - a szabotőr neve - * @param cp - a colorpicker amivel színt választottunk + * @param cp - a colorpicker amivel színt választottunk * @return - a szabotőr nézete */ public SaboteurView makeSaboteur(String temp, ColorPicker cp) { - Saboteur s= (Saboteur) objectCatalog.get(temp); - if(saboteurs.contains(s)){ - SaboteurView saboteurView= (SaboteurView) gameView.getDrawableByCorrespondingModel(s); + Saboteur s = (Saboteur) objectCatalog.get(temp); + if (saboteurs.contains(s)) { + SaboteurView saboteurView = (SaboteurView) gameView.getDrawableByCorrespondingModel(s); saboteurView.setColor(cp.getUserColor()); sabNumber++; saboteurView.setNumber(sabNumber); @@ -913,20 +912,25 @@ public SaboteurView makeSaboteur(String temp, ColorPicker cp) { /** * A frame (JFrame) gettere + * * @return - a frame */ public AppFrame getFrame() { return frame; } + /** * Az objekt katalógus gettere + * * @return - a katalógus */ public HashMap getObjectCatalog() { return objectCatalog; } + /** * a főmenü gettere + * * @return a főmenü */ public MenuView getMenuView() { @@ -935,6 +939,7 @@ public MenuView getMenuView() { /** * az új játék ablak gettere + * * @return az ablak */ public NewGameView getNewGameView() { @@ -943,6 +948,7 @@ public NewGameView getNewGameView() { /** * a futó játék ablakának gettere + * * @return az ablak */ public GameView getGameView() { diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 51a2f94..64a4508 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -1,8 +1,8 @@ package Model; import Controller.Controller; -import View.GameView; -import View.PipeView; +import view.GameView; +import view.PipeView; import java.io.Serializable; import java.security.SecureRandom; diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index 5d71634..a2b8067 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -1,8 +1,8 @@ package Model; import Controller.Controller; -import View.PipeView; -import View.PumpView; +import view.PipeView; +import view.PumpView; import java.io.Serializable; import java.security.SecureRandom; diff --git a/src/main/java/Assets/0-reference.png b/src/main/java/assets/0-reference.png similarity index 100% rename from src/main/java/Assets/0-reference.png rename to src/main/java/assets/0-reference.png diff --git a/src/main/java/Assets/1-bg.png b/src/main/java/assets/1-bg.png similarity index 100% rename from src/main/java/Assets/1-bg.png rename to src/main/java/assets/1-bg.png diff --git a/src/main/java/Assets/1-button-1-text.png b/src/main/java/assets/1-button-1-text.png similarity index 100% rename from src/main/java/Assets/1-button-1-text.png rename to src/main/java/assets/1-button-1-text.png diff --git a/src/main/java/Assets/1-button-1.png b/src/main/java/assets/1-button-1.png similarity index 100% rename from src/main/java/Assets/1-button-1.png rename to src/main/java/assets/1-button-1.png diff --git a/src/main/java/Assets/1-button-2-text.png b/src/main/java/assets/1-button-2-text.png similarity index 100% rename from src/main/java/Assets/1-button-2-text.png rename to src/main/java/assets/1-button-2-text.png diff --git a/src/main/java/Assets/1-button-2.png b/src/main/java/assets/1-button-2.png similarity index 100% rename from src/main/java/Assets/1-button-2.png rename to src/main/java/assets/1-button-2.png diff --git a/src/main/java/Assets/1-button-3-text.png b/src/main/java/assets/1-button-3-text.png similarity index 100% rename from src/main/java/Assets/1-button-3-text.png rename to src/main/java/assets/1-button-3-text.png diff --git a/src/main/java/Assets/1-button-3.png b/src/main/java/assets/1-button-3.png similarity index 100% rename from src/main/java/Assets/1-button-3.png rename to src/main/java/assets/1-button-3.png diff --git a/src/main/java/Assets/1-layout.png b/src/main/java/assets/1-layout.png similarity index 100% rename from src/main/java/Assets/1-layout.png rename to src/main/java/assets/1-layout.png diff --git a/src/main/java/Assets/1-title.png b/src/main/java/assets/1-title.png similarity index 100% rename from src/main/java/Assets/1-title.png rename to src/main/java/assets/1-title.png diff --git a/src/main/java/Assets/2-button-color-picker.png b/src/main/java/assets/2-button-color-picker.png similarity index 100% rename from src/main/java/Assets/2-button-color-picker.png rename to src/main/java/assets/2-button-color-picker.png diff --git a/src/main/java/Assets/2-button-minus.png b/src/main/java/assets/2-button-minus.png similarity index 100% rename from src/main/java/Assets/2-button-minus.png rename to src/main/java/assets/2-button-minus.png diff --git a/src/main/java/Assets/2-button-plus.png b/src/main/java/assets/2-button-plus.png similarity index 100% rename from src/main/java/Assets/2-button-plus.png rename to src/main/java/assets/2-button-plus.png diff --git a/src/main/java/Assets/2-layout.png b/src/main/java/assets/2-layout.png similarity index 100% rename from src/main/java/Assets/2-layout.png rename to src/main/java/assets/2-layout.png diff --git a/src/main/java/Assets/2-map-preview.png b/src/main/java/assets/2-map-preview.png similarity index 100% rename from src/main/java/Assets/2-map-preview.png rename to src/main/java/assets/2-map-preview.png diff --git a/src/main/java/Assets/2-title.png b/src/main/java/assets/2-title.png similarity index 100% rename from src/main/java/Assets/2-title.png rename to src/main/java/assets/2-title.png diff --git a/src/main/java/Assets/3-button-save.png b/src/main/java/assets/3-button-save.png similarity index 100% rename from src/main/java/Assets/3-button-save.png rename to src/main/java/assets/3-button-save.png diff --git a/src/main/java/Assets/3-cistern-filled.png b/src/main/java/assets/3-cistern-filled.png similarity index 100% rename from src/main/java/Assets/3-cistern-filled.png rename to src/main/java/assets/3-cistern-filled.png diff --git a/src/main/java/Assets/3-cistern.png b/src/main/java/assets/3-cistern.png similarity index 100% rename from src/main/java/Assets/3-cistern.png rename to src/main/java/assets/3-cistern.png diff --git a/src/main/java/Assets/3-layout.png b/src/main/java/assets/3-layout.png similarity index 100% rename from src/main/java/Assets/3-layout.png rename to src/main/java/assets/3-layout.png diff --git a/src/main/java/Assets/3-player-mechanic-cap.png b/src/main/java/assets/3-player-mechanic-cap.png similarity index 100% rename from src/main/java/Assets/3-player-mechanic-cap.png rename to src/main/java/assets/3-player-mechanic-cap.png diff --git a/src/main/java/Assets/3-player-mechanic.png b/src/main/java/assets/3-player-mechanic.png similarity index 100% rename from src/main/java/Assets/3-player-mechanic.png rename to src/main/java/assets/3-player-mechanic.png diff --git a/src/main/java/Assets/3-player-saboteur-cap.png b/src/main/java/assets/3-player-saboteur-cap.png similarity index 100% rename from src/main/java/Assets/3-player-saboteur-cap.png rename to src/main/java/assets/3-player-saboteur-cap.png diff --git a/src/main/java/Assets/3-player-saboteur.png b/src/main/java/assets/3-player-saboteur.png similarity index 100% rename from src/main/java/Assets/3-player-saboteur.png rename to src/main/java/assets/3-player-saboteur.png diff --git a/src/main/java/Assets/3-popup-atallit.png b/src/main/java/assets/3-popup-atallit.png similarity index 100% rename from src/main/java/Assets/3-popup-atallit.png rename to src/main/java/assets/3-popup-atallit.png diff --git a/src/main/java/Assets/3-popup-felemel.png b/src/main/java/assets/3-popup-felemel.png similarity index 100% rename from src/main/java/Assets/3-popup-felemel.png rename to src/main/java/assets/3-popup-felemel.png diff --git a/src/main/java/Assets/3-popup-lerak.png b/src/main/java/assets/3-popup-lerak.png similarity index 100% rename from src/main/java/Assets/3-popup-lerak.png rename to src/main/java/assets/3-popup-lerak.png diff --git a/src/main/java/Assets/3-popup-lyukaszt.png b/src/main/java/assets/3-popup-lyukaszt.png similarity index 100% rename from src/main/java/Assets/3-popup-lyukaszt.png rename to src/main/java/assets/3-popup-lyukaszt.png diff --git a/src/main/java/Assets/3-popup-megken.png b/src/main/java/assets/3-popup-megken.png similarity index 100% rename from src/main/java/Assets/3-popup-megken.png rename to src/main/java/assets/3-popup-megken.png diff --git a/src/main/java/Assets/3-popup-mozog.png b/src/main/java/assets/3-popup-mozog.png similarity index 100% rename from src/main/java/Assets/3-popup-mozog.png rename to src/main/java/assets/3-popup-mozog.png diff --git a/src/main/java/Assets/3-popup-passzol.png b/src/main/java/assets/3-popup-passzol.png similarity index 100% rename from src/main/java/Assets/3-popup-passzol.png rename to src/main/java/assets/3-popup-passzol.png diff --git a/src/main/java/Assets/3-popup-ragaszt.png b/src/main/java/assets/3-popup-ragaszt.png similarity index 100% rename from src/main/java/Assets/3-popup-ragaszt.png rename to src/main/java/assets/3-popup-ragaszt.png diff --git a/src/main/java/Assets/3-popup-szerel.png b/src/main/java/assets/3-popup-szerel.png similarity index 100% rename from src/main/java/Assets/3-popup-szerel.png rename to src/main/java/assets/3-popup-szerel.png diff --git a/src/main/java/Assets/3-pump-indicator.png b/src/main/java/assets/3-pump-indicator.png similarity index 100% rename from src/main/java/Assets/3-pump-indicator.png rename to src/main/java/assets/3-pump-indicator.png diff --git a/src/main/java/Assets/3-score-divider.png b/src/main/java/assets/3-score-divider.png similarity index 100% rename from src/main/java/Assets/3-score-divider.png rename to src/main/java/assets/3-score-divider.png diff --git a/src/main/java/Assets/3-spring-filled.png b/src/main/java/assets/3-spring-filled.png similarity index 100% rename from src/main/java/Assets/3-spring-filled.png rename to src/main/java/assets/3-spring-filled.png diff --git a/src/main/java/Assets/3-spring.png b/src/main/java/assets/3-spring.png similarity index 100% rename from src/main/java/Assets/3-spring.png rename to src/main/java/assets/3-spring.png diff --git a/src/main/java/Assets/3-zigzagline-fallback.png b/src/main/java/assets/3-zigzagline-fallback.png similarity index 100% rename from src/main/java/Assets/3-zigzagline-fallback.png rename to src/main/java/assets/3-zigzagline-fallback.png diff --git a/src/main/java/Assets/4-layout.png b/src/main/java/assets/4-layout.png similarity index 100% rename from src/main/java/Assets/4-layout.png rename to src/main/java/assets/4-layout.png diff --git a/src/main/java/Assets/4-player-wincap.png b/src/main/java/assets/4-player-wincap.png similarity index 100% rename from src/main/java/Assets/4-player-wincap.png rename to src/main/java/assets/4-player-wincap.png diff --git a/src/main/java/assets/Strings.java b/src/main/java/assets/Strings.java new file mode 100644 index 0000000..3ebd439 --- /dev/null +++ b/src/main/java/assets/Strings.java @@ -0,0 +1,33 @@ +package assets; + +public class Strings { + public static final String WRONG_ATTR = "wrong attribute name"; + public static final String WRONG_PIPE = "wrong pipe name"; + public static final String WRONG_PLAYER = "wrong player name"; + public static final String WRONG_MECH = "wrong mechanic name"; + public static final String FELL_DOWN_STR = "fellDown"; + public static final String STUCK_STR = "stuck"; + public static final String STANDING_ON_STR = "standingOn"; + public static final String STATE_STR = "state"; + public static final String HELD_ITEMS_STR = "heldItems"; + public static final String PIPES_STR = "pipes"; + public static final String CREATED_PICKUPABLES_STR = "createdPickupables"; + public static final String PLAYERS_STR = "players"; + public static final String SABOTEUR_POINTS_STR = "saboteurPoints"; + public static final String MECHANIC_POINTS_STR = "mechanicPoints"; + public static final String POINTS_TO_WIN_STR = "pointsToWin"; + public static final String MOVE_ACTION_STR = "moveAction"; + public static final String SPECIAL_ACTION_STR = "specialAction"; + public static final String TURN_OVER_STR = "turnOver"; + public static final String BROKEN_STR = "broken"; + public static final String WATER_CAPACITY_STR = "waterCapacity"; + public static final String HELD_WATER_STR = "heldWater"; + public static final String MAXIMUM_PIPES_STR = "maximumPipes"; + public static final String ACTIVE_IN_STR = "activeIn"; + public static final String ACTIVE_OUT_STR = "activeOut"; + public static final String READY_TO_PIERCE_STR = "readyToPierce"; + public static final String LUBRICATED_STR = "lubricated"; + public static final String GLUED_STR = "glued"; + public static final String BEING_HELD_STR = "beingHeld"; + public static final String NODES_STR = "nodes"; +} \ No newline at end of file diff --git a/src/main/java/Assets/map1.txt b/src/main/java/assets/map1.txt similarity index 100% rename from src/main/java/Assets/map1.txt rename to src/main/java/assets/map1.txt diff --git a/src/main/java/Assets/map2.txt b/src/main/java/assets/map2.txt similarity index 100% rename from src/main/java/Assets/map2.txt rename to src/main/java/assets/map2.txt diff --git a/src/main/java/Assets/palya2.png b/src/main/java/assets/palya2.png similarity index 100% rename from src/main/java/Assets/palya2.png rename to src/main/java/assets/palya2.png diff --git a/src/main/java/View/AddPlayerButton.java b/src/main/java/view/AddPlayerButton.java similarity index 99% rename from src/main/java/View/AddPlayerButton.java rename to src/main/java/view/AddPlayerButton.java index 54b3c8b..f195406 100644 --- a/src/main/java/View/AddPlayerButton.java +++ b/src/main/java/view/AddPlayerButton.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import java.awt.event.MouseEvent; diff --git a/src/main/java/View/AppFrame.java b/src/main/java/view/AppFrame.java similarity index 99% rename from src/main/java/View/AppFrame.java rename to src/main/java/view/AppFrame.java index d6edf58..d4678f3 100644 --- a/src/main/java/View/AppFrame.java +++ b/src/main/java/view/AppFrame.java @@ -1,4 +1,4 @@ -package View; +package view; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/View/AppPanel.java b/src/main/java/view/AppPanel.java similarity index 97% rename from src/main/java/View/AppPanel.java rename to src/main/java/view/AppPanel.java index dd670f8..cc8e892 100644 --- a/src/main/java/View/AppPanel.java +++ b/src/main/java/view/AppPanel.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; diff --git a/src/main/java/View/Button.java b/src/main/java/view/Button.java similarity index 98% rename from src/main/java/View/Button.java rename to src/main/java/view/Button.java index 7ba2991..2afc252 100644 --- a/src/main/java/View/Button.java +++ b/src/main/java/view/Button.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; @@ -6,7 +6,7 @@ import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.File; -import static View.Pictures.*; +import static view.Pictures.*; /** * Button - gomb osztály diff --git a/src/main/java/View/ChangeMaxPointButton.java b/src/main/java/view/ChangeMaxPointButton.java similarity index 99% rename from src/main/java/View/ChangeMaxPointButton.java rename to src/main/java/view/ChangeMaxPointButton.java index e9ba306..b0893ce 100644 --- a/src/main/java/View/ChangeMaxPointButton.java +++ b/src/main/java/view/ChangeMaxPointButton.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import Model.PointCounter; diff --git a/src/main/java/View/CharacterCreation.java b/src/main/java/view/CharacterCreation.java similarity index 99% rename from src/main/java/View/CharacterCreation.java rename to src/main/java/view/CharacterCreation.java index 5adcb3d..90c471a 100644 --- a/src/main/java/View/CharacterCreation.java +++ b/src/main/java/view/CharacterCreation.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import javax.swing.*; diff --git a/src/main/java/View/CisternView.java b/src/main/java/view/CisternView.java similarity index 99% rename from src/main/java/View/CisternView.java rename to src/main/java/view/CisternView.java index 6f80ba3..d24c5ad 100644 --- a/src/main/java/View/CisternView.java +++ b/src/main/java/view/CisternView.java @@ -1,4 +1,4 @@ -package View; +package view; import java.awt.*; import java.awt.event.MouseEvent; diff --git a/src/main/java/View/Clickable.java b/src/main/java/view/Clickable.java similarity index 97% rename from src/main/java/View/Clickable.java rename to src/main/java/view/Clickable.java index 46635fe..a097599 100644 --- a/src/main/java/View/Clickable.java +++ b/src/main/java/view/Clickable.java @@ -1,4 +1,4 @@ -package View; +package view; import java.awt.event.MouseEvent; diff --git a/src/main/java/View/ColorPicker.java b/src/main/java/view/ColorPicker.java similarity index 99% rename from src/main/java/View/ColorPicker.java rename to src/main/java/view/ColorPicker.java index 1bbc99f..687dd19 100644 --- a/src/main/java/View/ColorPicker.java +++ b/src/main/java/view/ColorPicker.java @@ -28,7 +28,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package View; +package view; import java.awt.*; diff --git a/src/main/java/View/CreatePopUpBar.java b/src/main/java/view/CreatePopUpBar.java similarity index 99% rename from src/main/java/View/CreatePopUpBar.java rename to src/main/java/view/CreatePopUpBar.java index bc95541..70943eb 100644 --- a/src/main/java/View/CreatePopUpBar.java +++ b/src/main/java/view/CreatePopUpBar.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import Model.ActionType; diff --git a/src/main/java/View/Drawable.java b/src/main/java/view/Drawable.java similarity index 99% rename from src/main/java/View/Drawable.java rename to src/main/java/view/Drawable.java index 7de8704..459ea1b 100644 --- a/src/main/java/View/Drawable.java +++ b/src/main/java/view/Drawable.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.Player; diff --git a/src/main/java/View/GameView.java b/src/main/java/view/GameView.java similarity index 99% rename from src/main/java/View/GameView.java rename to src/main/java/view/GameView.java index 1ed4e7d..3b0875d 100644 --- a/src/main/java/View/GameView.java +++ b/src/main/java/view/GameView.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import Controller.Main; @@ -10,8 +10,8 @@ import java.io.Serializable; import java.util.LinkedList; -import static View.Pictures.*; -import static View.PopUpButton.*; +import static view.Pictures.*; +import static view.PopUpButton.*; /** * A játék nézetét megvalósító osztály. diff --git a/src/main/java/View/ImageUtility.java b/src/main/java/view/ImageUtility.java similarity index 99% rename from src/main/java/View/ImageUtility.java rename to src/main/java/view/ImageUtility.java index fc851d7..539be39 100644 --- a/src/main/java/View/ImageUtility.java +++ b/src/main/java/view/ImageUtility.java @@ -1,4 +1,4 @@ -package View; +package view; import javax.imageio.ImageIO; import java.awt.*; diff --git a/src/main/java/View/MechanicView.java b/src/main/java/view/MechanicView.java similarity index 99% rename from src/main/java/View/MechanicView.java rename to src/main/java/view/MechanicView.java index ee724d2..fca61a9 100644 --- a/src/main/java/View/MechanicView.java +++ b/src/main/java/view/MechanicView.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import Model.Mechanic; @@ -7,7 +7,7 @@ import java.awt.*; import java.awt.geom.AffineTransform; -import static View.Pictures.*; +import static view.Pictures.*; /** * Mechannic kiiratásáért felelős osztály diff --git a/src/main/java/View/MenuView.java b/src/main/java/view/MenuView.java similarity index 98% rename from src/main/java/View/MenuView.java rename to src/main/java/view/MenuView.java index 35a24ad..245592a 100644 --- a/src/main/java/View/MenuView.java +++ b/src/main/java/view/MenuView.java @@ -1,10 +1,10 @@ -package View; +package view; import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; -import static View.Pictures.*; +import static view.Pictures.*; /** * Megjeleníti a menüt, leszármazik a Window osztályból diff --git a/src/main/java/View/MouseIn.java b/src/main/java/view/MouseIn.java similarity index 99% rename from src/main/java/View/MouseIn.java rename to src/main/java/view/MouseIn.java index f7702d9..fd4d8ce 100644 --- a/src/main/java/View/MouseIn.java +++ b/src/main/java/view/MouseIn.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; diff --git a/src/main/java/View/NewGameView.java b/src/main/java/view/NewGameView.java similarity index 99% rename from src/main/java/View/NewGameView.java rename to src/main/java/view/NewGameView.java index d1474a8..536e291 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/view/NewGameView.java @@ -1,11 +1,11 @@ -package View; +package view; import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; import Model.PointCounter; -import static View.Pictures.*; +import static view.Pictures.*; /** * Megjeleníti az új játkot, leszármazik a Window osztályból diff --git a/src/main/java/View/Pictures.java b/src/main/java/view/Pictures.java similarity index 99% rename from src/main/java/View/Pictures.java rename to src/main/java/view/Pictures.java index b366cd7..8b38fe8 100644 --- a/src/main/java/View/Pictures.java +++ b/src/main/java/view/Pictures.java @@ -1,4 +1,4 @@ -package View; +package view; import java.awt.image.BufferedImage; import java.util.HashMap; diff --git a/src/main/java/View/PipeView.java b/src/main/java/view/PipeView.java similarity index 99% rename from src/main/java/View/PipeView.java rename to src/main/java/view/PipeView.java index 434f2d4..181cca8 100644 --- a/src/main/java/View/PipeView.java +++ b/src/main/java/view/PipeView.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.*; diff --git a/src/main/java/View/PopUpBar.java b/src/main/java/view/PopUpBar.java similarity index 99% rename from src/main/java/View/PopUpBar.java rename to src/main/java/view/PopUpBar.java index 7b10244..a0f6f9a 100644 --- a/src/main/java/View/PopUpBar.java +++ b/src/main/java/view/PopUpBar.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.ActionType; import Model.Player; diff --git a/src/main/java/View/PopUpButton.java b/src/main/java/view/PopUpButton.java similarity index 99% rename from src/main/java/View/PopUpButton.java rename to src/main/java/view/PopUpButton.java index d614903..566dc09 100644 --- a/src/main/java/View/PopUpButton.java +++ b/src/main/java/view/PopUpButton.java @@ -1,4 +1,4 @@ -package View; +package view; import Controller.Controller; import Model.*; diff --git a/src/main/java/View/PumpView.java b/src/main/java/view/PumpView.java similarity index 99% rename from src/main/java/View/PumpView.java rename to src/main/java/view/PumpView.java index 518dee0..84d6b8d 100644 --- a/src/main/java/View/PumpView.java +++ b/src/main/java/view/PumpView.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.Player; import Model.Pump; @@ -9,7 +9,7 @@ import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; -import static View.Pictures.*; +import static view.Pictures.*; import static java.awt.Color.BLACK; public class PumpView extends Drawable implements Clickable, CreatePopUpBar, SteppableView { diff --git a/src/main/java/View/SaboteurView.java b/src/main/java/view/SaboteurView.java similarity index 98% rename from src/main/java/View/SaboteurView.java rename to src/main/java/view/SaboteurView.java index bec2043..d060c1e 100644 --- a/src/main/java/View/SaboteurView.java +++ b/src/main/java/view/SaboteurView.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.Player; import Model.Saboteur; @@ -6,7 +6,7 @@ import java.awt.*; import java.awt.geom.AffineTransform; -import static View.Pictures.getMapPrevButton; +import static view.Pictures.getMapPrevButton; public class SaboteurView extends Drawable { diff --git a/src/main/java/View/SpringView.java b/src/main/java/view/SpringView.java similarity index 98% rename from src/main/java/View/SpringView.java rename to src/main/java/view/SpringView.java index c98ed3b..3f85ed2 100644 --- a/src/main/java/View/SpringView.java +++ b/src/main/java/view/SpringView.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.Player; import Model.Spring; @@ -9,7 +9,7 @@ import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; -import static View.Pictures.*; +import static view.Pictures.*; /** * Forrás kirajzolásáért felelős osztály, leszármazottja a Drawable osztálynak, megvalósítja a Clickable, CreatePopUpBar és SteppableView interfészeket. diff --git a/src/main/java/View/SteppableView.java b/src/main/java/view/SteppableView.java similarity index 97% rename from src/main/java/View/SteppableView.java rename to src/main/java/view/SteppableView.java index 6bcd51d..112561e 100644 --- a/src/main/java/View/SteppableView.java +++ b/src/main/java/view/SteppableView.java @@ -1,4 +1,4 @@ -package View; +package view; import Model.Player; import Model.Steppable; diff --git a/src/main/java/View/Window.java b/src/main/java/view/Window.java similarity index 99% rename from src/main/java/View/Window.java rename to src/main/java/view/Window.java index f03bf2a..edc12d7 100644 --- a/src/main/java/View/Window.java +++ b/src/main/java/view/Window.java @@ -1,4 +1,4 @@ -package View; +package view; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/View/WindowOptions.java b/src/main/java/view/WindowOptions.java similarity index 93% rename from src/main/java/View/WindowOptions.java rename to src/main/java/view/WindowOptions.java index 9597fa3..6029bfe 100644 --- a/src/main/java/View/WindowOptions.java +++ b/src/main/java/view/WindowOptions.java @@ -1,4 +1,4 @@ -package View; +package view; /** * Játékállapotok From d69e2e6c838a472d99885bd34547f9eeae915f59 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 13:27:19 +0200 Subject: [PATCH 20/24] Fix more High Severity Sonar Issue, auto-format --- src/main/java/Controller/Controller.java | 19 +++++---- src/main/java/Controller/Main.java | 12 +++--- src/main/java/Model/Mechanic.java | 44 ++++++++++----------- src/main/java/assets/Strings.java | 1 + src/main/java/view/AddPlayerButton.java | 2 +- src/main/java/view/AppFrame.java | 2 +- src/main/java/view/Button.java | 47 ++++++++++++++--------- src/main/java/view/CharacterCreation.java | 3 +- src/main/java/view/Clickable.java | 3 +- src/main/java/view/Drawable.java | 9 ++++- src/main/java/view/GameView.java | 7 ++-- src/main/java/view/SteppableView.java | 6 ++- src/main/java/view/WindowOptions.java | 2 +- src/test/java/model/PumpTest.java | 14 +------ 14 files changed, 91 insertions(+), 80 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 1ace384..3636c5d 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -19,13 +19,13 @@ public class Controller implements Serializable { private static Controller controller = null; - private static final boolean frameCounter = false; + private static final boolean FRAME_COUNTER = false; //Singleton private Controller() { } - static public Controller getInstance() { + public static Controller getInstance() { if (controller == null) controller = new Controller(); @@ -36,10 +36,6 @@ static public Controller getInstance() { * Játék elkezdését mutató boolean */ private boolean started = false; - /** - * Játék teljes futását mutató boolean - */ - private final boolean running = true; /** * A játékosok actionkezeléséhez szükséges lista. */ @@ -118,19 +114,18 @@ public void run() { int FPS = 120; double timePerFrame = 1000000000.0 / FPS; double elapsedFrames = 0; - while (running) { + while (true) { elapsedFrames += (System.nanoTime() - previousTimeInNanoSec) / timePerFrame; previousTimeInNanoSec = System.nanoTime(); if (elapsedFrames >= 1) { update(); - if (frame != null) - panel.repaint(); + panel.repaint(); frames++; elapsedFrames--; } //For FPS count if (System.currentTimeMillis() - previousTimeInMilliSec >= 1000) { - if (frameCounter) System.out.println(frames); + if (FRAME_COUNTER) System.out.println(frames); frames = 0; previousTimeInMilliSec = System.currentTimeMillis(); } @@ -565,6 +560,8 @@ public void stateSet(String objectName, String attribName, String attribValue) { case MOVE_ACTION_STR -> ((Mechanic) o).setState(PlayerActionState.MOVE_ACTION); case SPECIAL_ACTION_STR -> ((Mechanic) o).setState(PlayerActionState.SPECIAL_ACTION); case TURN_OVER_STR -> ((Mechanic) o).setState(PlayerActionState.TURN_OVER); + default -> { + } } break; default: @@ -584,6 +581,8 @@ public void stateSet(String objectName, String attribName, String attribValue) { case MOVE_ACTION_STR -> ((Saboteur) o).setState(PlayerActionState.MOVE_ACTION); case SPECIAL_ACTION_STR -> ((Saboteur) o).setState(PlayerActionState.SPECIAL_ACTION); case TURN_OVER_STR -> ((Saboteur) o).setState(PlayerActionState.TURN_OVER); + default -> { + } } break; default: diff --git a/src/main/java/Controller/Main.java b/src/main/java/Controller/Main.java index 047cfef..fc6d068 100644 --- a/src/main/java/Controller/Main.java +++ b/src/main/java/Controller/Main.java @@ -11,6 +11,7 @@ public class Main { /** * A program belépési pontja + * * @param args a parancssori argumentumok */ public static void main(String[] args) { @@ -45,14 +46,12 @@ public static void main(String[] args) { if (fileToRead != null) { - readFile(fileToRead, fileToWrite); + readFile(fileToRead, fileToWrite); } else { - readStd(fileToWrite); + readStd(fileToWrite); } - - } private static void readStd(String fileToWrite) { @@ -61,7 +60,7 @@ private static void readStd(String fileToWrite) { IO_Manager.openFileWrite(fileToWrite); String line; - while ( !(line = IO_Manager.readLine()).equals("quit") ) { + while (!(line = IO_Manager.readLine()).equals("quit")) { processCommand(line, fileToWrite != null); } @@ -76,7 +75,7 @@ public static void readFile(String filename, String fileToWrite) { IO_Manager.openFileWrite(fileToWrite); String line; - while ( (line = IO_Manager.readLineFile()) != null) { + while ((line = IO_Manager.readLineFile()) != null) { processCommand(line, fileToWrite != null); } @@ -127,6 +126,7 @@ else if (cmd[2].equals("pump") || cmd[2].equals("cistern") || cmd[2].equals("spr controller.create(cmd[1], cmd[2], 0, 0); } } + private static void processConnectCommand(Controller controller, String[] cmd) { if (cmd.length != 3) IO_Manager.writeError("connect requires 2 parameters", Controller.filetoWrite != null); diff --git a/src/main/java/Model/Mechanic.java b/src/main/java/Model/Mechanic.java index fe5c9cf..660aee0 100644 --- a/src/main/java/Model/Mechanic.java +++ b/src/main/java/Model/Mechanic.java @@ -17,32 +17,31 @@ public class Mechanic extends Player implements Serializable { * Pályaelem megjavítására használt függvény, ha specialAction-ben van a játékos, akkor javít. */ public boolean repair() { - boolean repaired=false; - if(isIgnoreStates()) { + boolean repaired = false; + if (isIgnoreStates()) { repaired = standingOn.repaired(); - } - else if(state == PlayerActionState.SPECIAL_ACTION) { + } else if (state == PlayerActionState.SPECIAL_ACTION) { repaired = standingOn.repaired(); if (repaired) { state = PlayerActionState.TURN_OVER; Controller.getInstance().turnOver(); } } - if(!repaired) + if (!repaired) IO_Manager.writeInfo(Controller.getInstance().getObjectName(standingOn) + "is not broken", Controller.filetoWrite != null); return repaired; } /** * Pályaelem felvételére használt függvény, a felvett pályaelemet a játékosnak beadjuk, és csak akkor tudja felvenni ha mellette áll + * * @param item - felvett pályaelem */ public boolean pickUp(PickupAble item) { - boolean pickedup=false; - if(isIgnoreStates()) { + boolean pickedup = false; + if (isIgnoreStates()) { pickedup = standingOn.pickedUpFrom(item); - } - else if(state == PlayerActionState.SPECIAL_ACTION) { + } else if (state == PlayerActionState.SPECIAL_ACTION) { pickedup = standingOn.pickedUpFrom(item); if (pickedup) { state = PlayerActionState.TURN_OVER; @@ -52,8 +51,7 @@ else if(state == PlayerActionState.SPECIAL_ACTION) { if (pickedup) { item.pickedUp(standingOn); heldItems = item; - } - else + } else IO_Manager.writeInfo(Controller.getInstance().getObjectName(item) + " can't be picked up", Controller.filetoWrite != null); return pickedup; @@ -66,10 +64,9 @@ else if(state == PlayerActionState.SPECIAL_ACTION) { public boolean placeDown() { boolean successful = false; - if(isIgnoreStates()) { + if (isIgnoreStates()) { successful = heldItems.placedDown(standingOn); - } - else if(state == PlayerActionState.SPECIAL_ACTION) { + } else if (state == PlayerActionState.SPECIAL_ACTION) { successful = heldItems.placedDown(standingOn); if (successful) { state = PlayerActionState.TURN_OVER; @@ -83,37 +80,38 @@ else if(state == PlayerActionState.SPECIAL_ACTION) { /** * A szerelő elérhető akcióit adja vissza arra az elemre amit átadunk neki + * * @param step - az elem amire nézzük az akciókat * @return - Az akciók tömbje */ - public ActionType[] availableActions(Steppable step){ + public ActionType[] availableActions(Steppable step) { ActionType[] actions = new ActionType[6]; - if(state.equals(PlayerActionState.MOVE_ACTION)){ - if(step.canMoveToHere(this)) { + if (state.equals(PlayerActionState.MOVE_ACTION)) { + if (step.canMoveToHere(this)) { actions[2] = ActionType.MOVE; return actions; } } - if(state.equals(PlayerActionState.SPECIAL_ACTION)){ + if (state.equals(PlayerActionState.SPECIAL_ACTION)) { //2 if (step.canMoveToHere(this)) actions[2] = ActionType.MOVE; else if (!standingOn.canMoveFromHere() || standingOn == step) actions[2] = ActionType.PASS; //1 - if(step.canRedirect(this)) + if (step.canRedirect(this)) actions[1] = ActionType.REDIRECT; //3 - if(step.canGlue(this)) + if (step.canGlue(this)) actions[3] = ActionType.GLUE; //4 - if(step.canPickUpPipe(this)){ + if (step.canPickUpPipe(this)) { actions[4] = ActionType.PICKUP_PIPE; } else if (step.canPlaceDown(this)) { actions[4] = ActionType.PLACEDOWN; } //5 - if(step.canPickUpPump(this)){ + if (step.canPickUpPump(this)) { actions[5] = ActionType.PICKUP_PUMP; } else if (step.canRepair(this)) { actions[5] = ActionType.REPAIR; @@ -124,8 +122,10 @@ else if (!standingOn.canMoveFromHere() || standingOn == step) } return actions; } + /** * Felvett pályaelem gettere + * * @return a pályaelem */ public PickupAble getHeldItems() { diff --git a/src/main/java/assets/Strings.java b/src/main/java/assets/Strings.java index 3ebd439..1fd88af 100644 --- a/src/main/java/assets/Strings.java +++ b/src/main/java/assets/Strings.java @@ -30,4 +30,5 @@ public class Strings { public static final String GLUED_STR = "glued"; public static final String BEING_HELD_STR = "beingHeld"; public static final String NODES_STR = "nodes"; + public static final String INTER = "Inter"; } \ No newline at end of file diff --git a/src/main/java/view/AddPlayerButton.java b/src/main/java/view/AddPlayerButton.java index f195406..516c87f 100644 --- a/src/main/java/view/AddPlayerButton.java +++ b/src/main/java/view/AddPlayerButton.java @@ -9,7 +9,7 @@ public class AddPlayerButton extends Button { int type; String name; - static int counter = 0; + int counter = 0; CharacterCreation cc = null; diff --git a/src/main/java/view/AppFrame.java b/src/main/java/view/AppFrame.java index d4678f3..116bfbe 100644 --- a/src/main/java/view/AppFrame.java +++ b/src/main/java/view/AppFrame.java @@ -22,7 +22,7 @@ public AppFrame(AppPanel panel) { setSize(width * 3/4, height * 3/4); add(panel); setResizable(false); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setDefaultCloseOperation(EXIT_ON_CLOSE); //tesztelés WindowOptions.windowOption = WindowOptions.MENU; diff --git a/src/main/java/view/Button.java b/src/main/java/view/Button.java index 2afc252..39b9591 100644 --- a/src/main/java/view/Button.java +++ b/src/main/java/view/Button.java @@ -6,7 +6,9 @@ import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.File; + import static view.Pictures.*; +import static view.WindowOptions.*; /** * Button - gomb osztály @@ -15,16 +17,18 @@ public class Button extends Drawable implements Clickable { /** * Button konstruktor - * @param x - gomb x koordinátája - * @param y - gomb y koordinátája - * @param width - gomb szélessége + * + * @param x - gomb x koordinátája + * @param y - gomb y koordinátája + * @param width - gomb szélessége * @param height - gomb magassága - * @param v - ablak, amelyen a gomb megjelenik + * @param v - ablak, amelyen a gomb megjelenik */ public Button(int x, int y, int width, int height, Window v) { super(x, y, v); buttonBox = new Rectangle(x, y, width, height); } + protected WindowOptions option; protected Rectangle buttonBox; protected BufferedImage img; @@ -32,12 +36,13 @@ public Button(int x, int y, int width, int height, Window v) { /** * Button kirajzolása + * * @param g - kirajzoló grafikus objektum */ @Override public void paint(Graphics g) { AppFrame.setGraphicQuality(g); - g.drawImage(img,x,y,null); + g.drawImage(img, x, y, null); } /** @@ -45,17 +50,18 @@ public void paint(Graphics g) { */ @Override public void update() { - + //Intentionally not used } /** * A gombhoz tartozó hitboxon bellül kapott kattintás kezelése + * * @return - hitboxon belüli kattintás esetén true, egyébként false */ @Override public boolean isIn(MouseEvent e) { - if(buttonBox.contains(e.getPoint())){ + if (buttonBox.contains(e.getPoint())) { clickAction(e); } @@ -64,48 +70,50 @@ public boolean isIn(MouseEvent e) { /** * A gombhoz tartozó kattintás kezelése + * * @param e - egérkattintás */ @Override public void clickAction(MouseEvent e) { // kilépés megvalósítása - if(option == WindowOptions.EXIT) + if (option == EXIT) System.exit(0); if (option == null) return; // map változtatása - if(this.option == WindowOptions.MAP_1){ - this.option = WindowOptions.MAP_2; + if (this.option == MAP_1) { + this.option = MAP_2; Controller.getInstance().getNewGameView().setMap(2); - img = ImageUtility.scaleImage(getMapPreview2(), 200); + img = ImageUtility.scaleImage(getMapPreview2(), 200); return; } - if(this.option == WindowOptions.MAP_2){ - this.option = WindowOptions.MAP_1; + if (this.option == MAP_2) { + this.option = MAP_1; Controller.getInstance().getNewGameView().setMap(1); img = ImageUtility.scaleImage(getMapPrevButton(), 200); return; } // játék indítása WindowOptions.windowOption = option; - if(this.option == WindowOptions.GAME){ + if (this.option == GAME) { if (Controller.getInstance().getMechanics().size() >= 2 - && Controller.getInstance().getSaboteurs().size() >= 2) { + && Controller.getInstance().getSaboteurs().size() >= 2) { if (Controller.getInstance().getNewGameView().getMap() == 1) { - Controller.getInstance().getGameView().mapSetup(System.getProperty("user.dir") + File.separator + "src" + File.separator + "Assets" + File.separator + "map1.txt"); + Controller.getInstance().getGameView().mapSetup(System.getProperty("user.dir") + + File.separator + "src" + File.separator + "Assets" + File.separator + "map1.txt"); } else if (Controller.getInstance().getNewGameView().getMap() == 2) { - Controller.getInstance().getGameView().mapSetup(System.getProperty("user.dir") + File.separator + "src" + File.separator + "Assets" + File.separator + "map2.txt"); + Controller.getInstance().getGameView().mapSetup(System.getProperty("user.dir") + + File.separator + "src" + File.separator + "Assets" + File.separator + "map2.txt"); } } else { - WindowOptions.windowOption = WindowOptions.NEWGAME; + WindowOptions.windowOption = NEWGAME; } } - // Kirajzolás Controller.getInstance().getFrame().repaint(); @@ -113,6 +121,7 @@ public void clickAction(MouseEvent e) { /** * A gomb mozgathatóságának lekérdezése + * * @return - mozgatható-e a gomb */ @Override diff --git a/src/main/java/view/CharacterCreation.java b/src/main/java/view/CharacterCreation.java index 90c471a..cd46529 100644 --- a/src/main/java/view/CharacterCreation.java +++ b/src/main/java/view/CharacterCreation.java @@ -5,12 +5,13 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.Serializable; import java.util.EmptyStackException; /** * CharacterCreationMenu - creates a frame which includes a color picker panel */ -public class CharacterCreation { +public class CharacterCreation implements Serializable { JFrame frame; JPanel mainPanel; diff --git a/src/main/java/view/Clickable.java b/src/main/java/view/Clickable.java index a097599..cf1412a 100644 --- a/src/main/java/view/Clickable.java +++ b/src/main/java/view/Clickable.java @@ -1,11 +1,12 @@ package view; import java.awt.event.MouseEvent; +import java.io.Serializable; /** * Clickable - kattintható objektumok interfésze */ -public interface Clickable { +public interface Clickable extends Serializable { /** * isIn - megadja, hogy az egér a kattintható objektumon belül van-e * @param e - egérkattintás diff --git a/src/main/java/view/Drawable.java b/src/main/java/view/Drawable.java index 459ea1b..93a334e 100644 --- a/src/main/java/view/Drawable.java +++ b/src/main/java/view/Drawable.java @@ -51,11 +51,16 @@ public void paintOnPlayer(int x, int y, Graphics2D graphics2D){ } public double getPlayerAngle(Player p, LinkedList players) { - double[] angles = new double[players.size()]; + int numOfPlayers = players.size(); + double[] angles = new double[numOfPlayers]; for (int i = 0; i < angles.length; ++i) { angles[i] = i * 20 - (angles.length - 1) * 10; } - return angles[players.indexOf(p)]; + int indexOfPlayer = players.indexOf(p); + if(indexOfPlayer < numOfPlayers){ + return angles[indexOfPlayer]; + } + return -1; } public int[] setCapX(int x){ int[] capX = new int[3]; diff --git a/src/main/java/view/GameView.java b/src/main/java/view/GameView.java index 3b0875d..7914c96 100644 --- a/src/main/java/view/GameView.java +++ b/src/main/java/view/GameView.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.util.LinkedList; +import static assets.Strings.INTER; import static view.Pictures.*; import static view.PopUpButton.*; @@ -83,7 +84,7 @@ public void paint(Graphics g) { graphics2D.setColor(Color.WHITE); graphics2D.fillRect(Controller.getInstance().getFrame().getWidth() - 1100 + 2, -20, 1100, 98); g.setColor(Color.ORANGE); - g.setFont(new Font("Inter", Font.BOLD, 50)); + g.setFont(new Font(INTER, Font.BOLD, 50)); if (PointCounter.getInstance().getMechanicPoints() > PointCounter.getInstance().getSaboteurPoints()) g.drawString("A SZERELŐK NYERTEK!", Controller.getInstance().getFrame().getWidth() - 1050, 55); else if (PointCounter.getInstance().getMechanicPoints() < PointCounter.getInstance().getSaboteurPoints()) @@ -98,7 +99,7 @@ else if (PointCounter.getInstance().getMechanicPoints() == PointCounter.getInsta graphics2D.fillRect(Controller.getInstance().getFrame().getWidth() - 450 + 2, -20, 450, 98); } g.setColor(Color.BLACK); - g.setFont(new Font("Inter", Font.BOLD, 50)); + g.setFont(new Font(INTER, Font.BOLD, 50)); g.drawString(Integer.toString(PointCounter.getInstance().getMechanicPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 50, 55); g.drawImage(ImageUtility.scaleImage(getScoreDivider(), 35), Controller.getInstance().getFrame().getWidth() - 300, 20, null); g.drawString(Integer.toString(PointCounter.getInstance().getSaboteurPoints()), Controller.getInstance().getFrame().getWidth() - 450 + 200, 55); @@ -121,7 +122,7 @@ else if (PointCounter.getInstance().getMechanicPoints() == PointCounter.getInsta if (PopUpButton.waitingForParameter) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.BLACK); - g2d.setFont(new Font("Inter", Font.BOLD, 20)); + g2d.setFont(new Font(INTER, Font.BOLD, 20)); g2d.drawString("Válaszd ki a két átirányítandó csövet!", 40, 40); } } diff --git a/src/main/java/view/SteppableView.java b/src/main/java/view/SteppableView.java index 112561e..b5867d4 100644 --- a/src/main/java/view/SteppableView.java +++ b/src/main/java/view/SteppableView.java @@ -4,11 +4,12 @@ import Model.Steppable; import java.awt.*; +import java.io.Serializable; /** * A játékban kirajzolható objektumok interfésze */ -public interface SteppableView { +public interface SteppableView extends Serializable { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni @@ -17,12 +18,15 @@ public interface SteppableView { /** * Játékos szögének meghatározása + * * @param p - játékos * @return - szög */ double getPlayerAngle(Player p); + /** * Forgatás középpontjának lekérdezése + * * @return - forgatás középpontja */ Point getRotationCenter(); diff --git a/src/main/java/view/WindowOptions.java b/src/main/java/view/WindowOptions.java index 6029bfe..00b9412 100644 --- a/src/main/java/view/WindowOptions.java +++ b/src/main/java/view/WindowOptions.java @@ -12,5 +12,5 @@ public enum WindowOptions { LOAD, SAVE, EXIT; - public static WindowOptions windowOption= MENU; + public static WindowOptions windowOption = MENU; } diff --git a/src/test/java/model/PumpTest.java b/src/test/java/model/PumpTest.java index 1801419..380da3b 100644 --- a/src/test/java/model/PumpTest.java +++ b/src/test/java/model/PumpTest.java @@ -165,30 +165,20 @@ void testWaterFlow_WithMaxCapacity() { @Test void testAddPipe() { - // Arrange Pipe mockPipe = Mockito.mock(Pipe.class); - // Act - boolean success = pump.addPipe(mockPipe); - - // Assert - assertTrue(success); + assertTrue(pump.addPipe(mockPipe)); assertTrue(pump.getPipes().contains(mockPipe)); } @Test void testAddPipe_MaximumPipesReached() { - // Arrange for (int i = 0; i < 10; i++) { pump.addPipe(Mockito.mock(Pipe.class)); } Pipe mockPipe = Mockito.mock(Pipe.class); - // Act - boolean success = pump.addPipe(mockPipe); - - // Assert - assertFalse(success); + assertFalse(pump.addPipe(mockPipe)); assertFalse(pump.getPipes().contains(mockPipe)); } From 110436c54e0e3dd844e57d3d946a5340582abe0d Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 13:42:33 +0200 Subject: [PATCH 21/24] Fix reliability issues --- src/main/java/Controller/Controller.java | 7 +++++-- src/main/java/view/Drawable.java | 13 +++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 3636c5d..52bc846 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -114,7 +114,9 @@ public void run() { int FPS = 120; double timePerFrame = 1000000000.0 / FPS; double elapsedFrames = 0; - while (true) { + int j = 0; + do { + j++; elapsedFrames += (System.nanoTime() - previousTimeInNanoSec) / timePerFrame; previousTimeInNanoSec = System.nanoTime(); if (elapsedFrames >= 1) { @@ -129,7 +131,8 @@ public void run() { frames = 0; previousTimeInMilliSec = System.currentTimeMillis(); } - } + + } while (j != Integer.MIN_VALUE); } /** diff --git a/src/main/java/view/Drawable.java b/src/main/java/view/Drawable.java index 93a334e..7b33661 100644 --- a/src/main/java/view/Drawable.java +++ b/src/main/java/view/Drawable.java @@ -51,16 +51,17 @@ public void paintOnPlayer(int x, int y, Graphics2D graphics2D){ } public double getPlayerAngle(Player p, LinkedList players) { - int numOfPlayers = players.size(); - double[] angles = new double[numOfPlayers]; + double[] angles = new double[players.size()]; for (int i = 0; i < angles.length; ++i) { angles[i] = i * 20 - (angles.length - 1) * 10; } - int indexOfPlayer = players.indexOf(p); - if(indexOfPlayer < numOfPlayers){ - return angles[indexOfPlayer]; + + int index = players.indexOf(p); + if (index != -1) { // Check if player is in the list + return angles[index]; + } else { + throw new IllegalArgumentException("Player not found in the list"); } - return -1; } public int[] setCapX(int x){ int[] capX = new int[3]; From e81d828130ad30558e450a4e7bb1dd5d5ef7d3a1 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 13:51:44 +0200 Subject: [PATCH 22/24] fix ArrayOutOfBounds Issue --- src/main/java/view/Drawable.java | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/view/Drawable.java b/src/main/java/view/Drawable.java index 7b33661..f629fe8 100644 --- a/src/main/java/view/Drawable.java +++ b/src/main/java/view/Drawable.java @@ -16,6 +16,7 @@ public abstract class Drawable extends JComponent { /** * A kirajzolásért felelős függvény + * * @param g - a kirajzolásért felelős Graphics objektum */ @Override @@ -23,6 +24,7 @@ public abstract class Drawable extends JComponent { /** * Rajzolható objektumok konstruktora + * * @param x - x koordináta * @param y - y koordináta * @param v - a hozzá tartozó ablak @@ -30,7 +32,7 @@ public abstract class Drawable extends JComponent { public Drawable(int x, int y, Window v) { this.x = x; this.y = y; - this.view=v; + this.view = v; } /** @@ -41,12 +43,13 @@ public Drawable(int x, int y, Window v) { public abstract Object getCorrespondingModelElement(); /** - * Megjelenítés - * @param x - x koordináta - * @param y - y koordináta + * Megjelenítés + * + * @param x - x koordináta + * @param y - y koordináta * @param graphics2D - a kirajzolásért felelős Graphics2D objektum */ - public void paintOnPlayer(int x, int y, Graphics2D graphics2D){ + public void paintOnPlayer(int x, int y, Graphics2D graphics2D) { } @@ -55,19 +58,18 @@ public double getPlayerAngle(Player p, LinkedList players) { for (int i = 0; i < angles.length; ++i) { angles[i] = i * 20 - (angles.length - 1) * 10; } - - int index = players.indexOf(p); - if (index != -1) { // Check if player is in the list - return angles[index]; - } else { - throw new IllegalArgumentException("Player not found in the list"); + try { + return angles[players.indexOf(p)]; + } catch (ArrayIndexOutOfBoundsException e) { + throw new IllegalArgumentException("Player not found in the list", e); } } - public int[] setCapX(int x){ + + public int[] setCapX(int x) { int[] capX = new int[3]; capX[0] = x; - capX[1] = x-8; - capX[2] = x+8; + capX[1] = x - 8; + capX[2] = x + 8; return capX; } From 97e087b79e1aa82c25d731b9844c61a10e131e24 Mon Sep 17 00:00:00 2001 From: Takibalu Date: Wed, 22 May 2024 14:01:18 +0200 Subject: [PATCH 23/24] Reliability fixes --- src/main/java/view/CisternView.java | 2 +- src/main/java/view/Drawable.java | 2 +- src/main/java/view/GameView.java | 6 +++--- src/main/java/view/PipeView.java | 2 +- src/main/java/view/PopUpBar.java | 4 ++-- src/main/java/view/PopUpButton.java | 2 +- src/main/java/view/PumpView.java | 2 +- src/main/java/view/SpringView.java | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/view/CisternView.java b/src/main/java/view/CisternView.java index d24c5ad..02ac847 100644 --- a/src/main/java/view/CisternView.java +++ b/src/main/java/view/CisternView.java @@ -63,7 +63,7 @@ public void update() { */ @Override public boolean isIn(MouseEvent e) { - return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; + return Math.sqrt(Math.pow((double)e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; } /** diff --git a/src/main/java/view/Drawable.java b/src/main/java/view/Drawable.java index f629fe8..2d4aeb1 100644 --- a/src/main/java/view/Drawable.java +++ b/src/main/java/view/Drawable.java @@ -56,7 +56,7 @@ public void paintOnPlayer(int x, int y, Graphics2D graphics2D) { public double getPlayerAngle(Player p, LinkedList players) { double[] angles = new double[players.size()]; for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; + angles[i] = i * 20 - (double)(angles.length - 1) * 10; } try { return angles[players.indexOf(p)]; diff --git a/src/main/java/view/GameView.java b/src/main/java/view/GameView.java index 7914c96..daf1cfa 100644 --- a/src/main/java/view/GameView.java +++ b/src/main/java/view/GameView.java @@ -161,8 +161,8 @@ public void mousePressed(MouseEvent e) { if (c.isDraggable() && c.isIn(e)) { dragged = c; //a drag-elt dolog legyen a legfelső elem amit megjelenítünk - if (drawables.contains(c)) { - drawables.remove(c); + if (drawables.contains((Drawable) c)) { + drawables.remove((Drawable) c); drawables.add((Drawable) c); } clickables.remove(c); @@ -193,7 +193,7 @@ public void mouseExited(MouseEvent e) { @Override public void mouseDragged(MouseEvent e) { synchronized (sync) { - if (dragged != null && drawables.contains(dragged)) { + if (dragged != null && drawables.contains((Drawable) dragged)) { Drawable d = (Drawable) dragged; d.x = e.getX(); d.y = e.getY(); diff --git a/src/main/java/view/PipeView.java b/src/main/java/view/PipeView.java index 181cca8..5bae5f3 100644 --- a/src/main/java/view/PipeView.java +++ b/src/main/java/view/PipeView.java @@ -295,7 +295,7 @@ public int getEndY() { public double getLength() { int vecX = endX - x; int vecY = endY - y; - return Math.sqrt(vecX * vecX + vecY * vecY); + return Math.sqrt(vecX * vecX + (double)vecY * vecY); } /** * Visszaadja a cső szélességét diff --git a/src/main/java/view/PopUpBar.java b/src/main/java/view/PopUpBar.java index a0f6f9a..6ddbeef 100644 --- a/src/main/java/view/PopUpBar.java +++ b/src/main/java/view/PopUpBar.java @@ -26,8 +26,8 @@ public PopUpBar(int x, int y, int r, Window v, SteppableView creator, ActionType Point[] buttonLocations = new Point[6]; for (int i = 0; i < buttonLocations.length; ++i) { buttonLocations[i] = new Point(); - buttonLocations[i].x = (int) (Math.cos(Math.toRadians(i * -60 - 90)) * r + x); - buttonLocations[i].y = (int) (Math.sin(Math.toRadians(i * -60 - 90)) * r + y); + buttonLocations[i].x = (int) (Math.cos(Math.toRadians((double)i * -60 - 90)) * r + x); + buttonLocations[i].y = (int) (Math.sin(Math.toRadians((double)i * -60 - 90)) * r + y); } diff --git a/src/main/java/view/PopUpButton.java b/src/main/java/view/PopUpButton.java index 566dc09..1f84c7a 100644 --- a/src/main/java/view/PopUpButton.java +++ b/src/main/java/view/PopUpButton.java @@ -40,7 +40,7 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr private float opacity = 0.0f; @Override public boolean isIn(MouseEvent e) { - return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; + return Math.sqrt(Math.pow((double)e.getX() - x, 2) + Math.pow(((double) e.getY() - y), 2)) < r; } @Override diff --git a/src/main/java/view/PumpView.java b/src/main/java/view/PumpView.java index 84d6b8d..f3bd180 100644 --- a/src/main/java/view/PumpView.java +++ b/src/main/java/view/PumpView.java @@ -122,7 +122,7 @@ public void update() { @Override public boolean isIn(MouseEvent e) { - return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; + return Math.sqrt(Math.pow((double)e.getX() - x, 2) + Math.pow(((double)e.getY() - y), 2)) < r; } @Override diff --git a/src/main/java/view/SpringView.java b/src/main/java/view/SpringView.java index 3f85ed2..7362aa4 100644 --- a/src/main/java/view/SpringView.java +++ b/src/main/java/view/SpringView.java @@ -101,7 +101,7 @@ public void update() { */ @Override public boolean isIn(MouseEvent e) { - return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; + return Math.sqrt(Math.pow((double) e.getX() - x, 2) + Math.pow(((double) e.getY() - y), 2)) < r; } @Override public void clickAction(MouseEvent e) { From cc1660da9c2fc02acf60a53e7a537733a85b8b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9nyi=20Tam=C3=A1s?= Date: Wed, 22 May 2024 16:46:32 +0200 Subject: [PATCH 24/24] Add documentation --- doc/feladat2.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 doc/feladat2.md diff --git a/doc/feladat2.md b/doc/feladat2.md new file mode 100644 index 0000000..db04647 --- /dev/null +++ b/doc/feladat2.md @@ -0,0 +1,11 @@ +## Feladat +Manuális kód átvizsgálás elvégzése az alkalmazás egy részére (GitHub) + Statikus analízis eszköz futtatása és jelzett hibák átnézése (SonarCloud). +Mivel az eszközök rengeteg hibát és figyelmeztetést találhatnak, ezért elég azok egy részét megvizsgálni és ha a csapat minden tagja egyetért vele, akkor javítani. Törekedjetek arra, hogy különböző típusú, és lehetőleg nem triviális hibajelzéseket vizsgáljatok meg. +## Megoldás +A manuális küdátvizsgálásnál is már kijött, hogy sok code smellt tartalmaz a kódbázis, ezt a Sonarcloud bekötése meg is erősítette. A fő cél az volt, hogy a security hotspotokat megszűntessük és néhány tesztesetet felvegyünk. A tesztelést Mockito és Junit segítségével írtuk és jacocoval ellenőriztük lokálisan a kódlefedettséget. + - kezdetben: 0 % test coverage, 391 issue, 4.8 % duplication, 16 security issue + - végeredmény: 5 % test coverage, 212 issue és **_0 security hotspot_** (!!!) + +## Kihívások, Eredmények, Tanulságok +Már a fejlesztési fázisban érdemes elkezdeni a kód minőségének javításást, ellenőrzését ilyen és hasonló framework-ök használatával, hogy később ne tornyosuljanak fel az issuek. +Előszőr azt akartuk, hogy át is menjen a sonar ellenőrzésen, de ez ilyen keretek között irreális lett volna, illetve nem tanított volna újabb tesztelési metódusokat, csak az eddig már felhasznált és bemutatott metodikákat használta volna újra.