Skip to content

Commit

Permalink
Solved checkstyle, removed methods unused
Browse files Browse the repository at this point in the history
  • Loading branch information
bagarozzi committed Jul 8, 2024
1 parent 70aa547 commit c2fe7e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public BombarderoGraphics(final Controller controller) {

resizingEngine = new ResizingEngine(this, frame.getInsets());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(resizingEngine.getGameWindowSize(frame));
frame.setSize(resizingEngine.getGameWindowSize());
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setIconImage(gameIconImage.getScaledInstance(64, 64, Image.SCALE_SMOOTH));
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/it/unibo/bombardero/view/ResizingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public final class ResizingEngine {
private final Dimension buttonSize;
private final Dimension menuLogoSize;

/**
* The class that manages the dynamic resizing of the game, choosing and setting
* a {@link #currentScale} that uses to proportionally enlarge every item in the game.
* <p>
* The scale is choosen by checking the display's resolution.
* @param graphics the {@link GraphicsEngine} related to this instance
* @param insets the insets of the frame, used to compute the total window size
*/
public ResizingEngine(final GraphicsEngine graphics, final Insets insets) {
final int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
if (resolution >= HIGH_RES_THRESHOLD) {
Expand All @@ -73,17 +81,23 @@ public ResizingEngine(final GraphicsEngine graphics, final Insets insets) {
menuLogoSize = initLogoSize();
}

/**
* Returns a cloned version of the current instance with the same values.
* @param graphics the {@link GraphicsEngine} related to this instance
* @return a new cloned {@link ResizingEngine}
*/
public ResizingEngine getNewEngine(final GraphicsEngine graphics) {
return new ResizingEngine(graphics, frameInsets);
}

/* FRAME-RELATED METHODS */

/*
* The initial windows size is calculated scaling the map and adding some grass
* on the sides, other than the insets
/**
* Returns the size of the whole window, taking into account insets,
* map's size and a little bit of grass.
* @return the width and height of the game's window
*/
public Dimension getGameWindowSize(final JFrame frame) {
public Dimension getGameWindowSize() {
return new Dimension(
gameWindowSize.width,
gameWindowSize.height);
Expand Down Expand Up @@ -200,17 +214,17 @@ public Image getScaledWASDImage(final Image wasdImage) {

/**
* Scales the sprite's image using the view's scale.
* @param wasdImage the image to scale
* @param spaceBarImage the image to scale
* @return the sprite's scaled image
*/
public Image getScaledSpaceImage(final Image wasdImage) {
return wasdImage.getScaledInstance((int) Math.floor(30 * 2 * getScale()), (int) Math.floor(12 * 2 * getScale()),
public Image getScaledSpaceImage(final Image spaceBarImage) {
return spaceBarImage.getScaledInstance((int) Math.floor(30 * 2 * getScale()), (int) Math.floor(12 * 2 * getScale()),
Image.SCALE_SMOOTH);
}
// CHECKSTYLE: MagicNumber ON
/**
* Scales the button's image using the view's scale.
* @param wasdImage the image to scale
* @param buttonImage the image to scale
* @return the sprite's scaled image
*/
public Image getScaledButtonImage(final Image buttonImage) {
Expand All @@ -219,7 +233,7 @@ public Image getScaledButtonImage(final Image buttonImage) {

/**
* Scales the menu's image using the view's scale.
* @param wasdImage the image to scale
* @param menuLogoImage the image to scale
* @return the sprite's scaled image
*/
public Image getScaledMenuLogoImage(final Image menuLogoImage) {
Expand All @@ -228,7 +242,7 @@ public Image getScaledMenuLogoImage(final Image menuLogoImage) {

/**
* Crops the background image passed.
* @param wasdImage the image to scale
* @param menuBackgroundImage the image to scale
* @return the sprite's scaled image
*/
public Image getSubImageFromBackground(final BufferedImage menuBackgroundImage) {
Expand Down Expand Up @@ -265,6 +279,7 @@ public Dimension getEntityPlacingPoint() {

/**
* Returns the upper-left corner of the cell at the {@link #cooordinate} of the map.
* @param coordinate the position of the cell on the map
* @return the coordinate of the top-left corner of the requested cell.
*/
public Dimension getCellPlacingPoint(final GenPair<Integer, Integer> coordinate) {
Expand Down Expand Up @@ -368,9 +383,6 @@ private Dimension initMapPlacingPoint() {
gameWindowSize.height / 2 - getMapSize().height / 2 - frameInsets.top + frameInsets.bottom);
}

/**
* Returns the corner of the north-eastern cell of the map
*/
// CHECKSTYLE: MagicNumber OFF
private Dimension initEntityPlacingPoint() {
return new Dimension(
Expand Down

0 comments on commit c2fe7e9

Please sign in to comment.