Skip to main content
Code Review

Return to Answer

added 10 characters in body
Source Link
mdfst13
  • 22.4k
  • 6
  • 34
  • 70
 bool hasCollision(GameLevel level, int x1, int y1, int x2, int y2, int xOff, int yOff) {
 Tile relative1 = getRelativeTile(level, x1, y1, 0xOff, -1yOff);
 Tile relative2 = getRelativeTile(level, x2, y2, 0xOff, -1yOff);
 return relative1 != null && relative1.getType() == 0
 || relative2 != null && relative2.getType() == 0;
 }
 bool hasCollision(GameLevel level, int x1, int y1, int x2, int y2, int xOff, int yOff) {
 Tile relative1 = getRelativeTile(level, x1, y1, 0, -1);
 Tile relative2 = getRelativeTile(level, x2, y2, 0, -1);
 return relative1 != null && relative1.getType() == 0
 || relative2 != null && relative2.getType() == 0;
 }
 bool hasCollision(GameLevel level, int x1, int y1, int x2, int y2, int xOff, int yOff) {
 Tile relative1 = getRelativeTile(level, x1, y1, xOff, yOff);
 Tile relative2 = getRelativeTile(level, x2, y2, xOff, yOff);
 return relative1 != null && relative1.getType() == 0
 || relative2 != null && relative2.getType() == 0;
 }
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

This does three things to get the code down. First, I get rid of a smack variable that is unused. Second, for those fields that get set the same regardless of how the constructor is called, I initialize those at declaration time. So the constructors don't need to do so. Third, I call one constructor from the other call one constructor from the other. This allows me to set default values for the parameters. And it means that we don't have to repeat the snap logic in both constructors.

This does three things to get the code down. First, I get rid of a smack variable that is unused. Second, for those fields that get set the same regardless of how the constructor is called, I initialize those at declaration time. So the constructors don't need to do so. Third, I call one constructor from the other. This allows me to set default values for the parameters. And it means that we don't have to repeat the snap logic in both constructors.

This does three things to get the code down. First, I get rid of a smack variable that is unused. Second, for those fields that get set the same regardless of how the constructor is called, I initialize those at declaration time. So the constructors don't need to do so. Third, I call one constructor from the other. This allows me to set default values for the parameters. And it means that we don't have to repeat the snap logic in both constructors.

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

You have four of these methods. All of them have the same basic pattern. You may want to consider @SimonForsberg's Direction enum pattern @SimonForsberg's Direction enum pattern for this. But even without that, you could make this code considerably simpler.

You have four of these methods. All of them have the same basic pattern. You may want to consider @SimonForsberg's Direction enum pattern for this. But even without that, you could make this code considerably simpler.

You have four of these methods. All of them have the same basic pattern. You may want to consider @SimonForsberg's Direction enum pattern for this. But even without that, you could make this code considerably simpler.

Source Link
mdfst13
  • 22.4k
  • 6
  • 34
  • 70
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /