📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@ -23,8 +23,7 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* This pattern simulate a collection of independent objects by telling each to
|
||||
@ -32,10 +31,9 @@ import org.slf4j.LoggerFactory;
|
||||
* of objects. Each object implements an update method that simulates one frame of
|
||||
* the object’s behavior. Each frame, the game updates every object in the collection.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
private static final int GAME_RUNNING_TIME = 2000;
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -35,6 +37,8 @@ public abstract class Entity {
|
||||
|
||||
protected int id;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
protected int position;
|
||||
|
||||
public Entity(int id) {
|
||||
@ -44,11 +48,4 @@ public abstract class Entity {
|
||||
|
||||
public abstract void update();
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ public class Skeleton extends Entity {
|
||||
* Constructor of Skeleton.
|
||||
*
|
||||
* @param id id of skeleton
|
||||
* @param postition position of skeleton
|
||||
* @param position position of skeleton
|
||||
*/
|
||||
public Skeleton(int id, int postition) {
|
||||
public Skeleton(int id, int position) {
|
||||
super(id);
|
||||
this.position = position;
|
||||
patrollingLeft = false;
|
||||
@ -72,7 +72,7 @@ public class Skeleton extends Entity {
|
||||
patrollingLeft = true;
|
||||
}
|
||||
}
|
||||
logger.info("Skeleton " + id + " is on position " + position + ".");
|
||||
logger.info("Skeleton {} is on position {}.", id, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class Statue extends Entity {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (++ frames == delay) {
|
||||
if (++frames == delay) {
|
||||
shootLightning();
|
||||
frames = 0;
|
||||
}
|
||||
|
@ -26,17 +26,15 @@ package com.iluwatar.updatemethod;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.Random;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The game world class. Maintain all the objects existed in the game frames.
|
||||
*/
|
||||
@Slf4j
|
||||
public class World {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(World.class);
|
||||
|
||||
protected List<Entity> entities;
|
||||
|
||||
protected volatile boolean isRunning;
|
||||
@ -70,6 +68,7 @@ public class World {
|
||||
Thread.sleep(lag);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,10 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
|
@ -31,7 +31,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
class SkeletonTest {
|
||||
|
||||
private static Skeleton skeleton;
|
||||
|
Reference in New Issue
Block a user