mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 21:25:52 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -27,10 +27,10 @@ package com.iluwatar.updatemethod;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* This pattern simulate a collection of independent objects by telling each to
|
||||
* process one frame of behavior at a time. The game world maintains a collection
|
||||
* 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.
|
||||
* This pattern simulate a collection of independent objects by telling each to process one frame of
|
||||
* behavior at a time. The game world maintains a collection 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 {
|
||||
@@ -39,6 +39,7 @@ public class App {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args runtime arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -29,18 +29,14 @@ import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Abstract class for all the entity types.
|
||||
*/
|
||||
/** Abstract class for all the entity types. */
|
||||
public abstract class Entity {
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
protected int id;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
protected int position;
|
||||
@Getter @Setter protected int position;
|
||||
|
||||
public Entity(int id) {
|
||||
this.id = id;
|
||||
@@ -48,5 +44,4 @@ public abstract class Entity {
|
||||
}
|
||||
|
||||
public abstract void update();
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
/**
|
||||
* Skeletons are always patrolling on the game map. Initially all the skeletons
|
||||
* patrolling to the right, and after them reach the bounding, it will start
|
||||
* patrolling to the left. For each frame, one skeleton will move 1 position
|
||||
* step.
|
||||
* Skeletons are always patrolling on the game map. Initially all the skeletons patrolling to the
|
||||
* right, and after them reach the bounding, it will start patrolling to the left. For each frame,
|
||||
* one skeleton will move 1 position step.
|
||||
*/
|
||||
public class Skeleton extends Entity {
|
||||
|
||||
@@ -76,4 +75,3 @@ public class Skeleton extends Entity {
|
||||
logger.info("Skeleton {} is on position {}.", id, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
/**
|
||||
* Statues shoot lightning at regular intervals.
|
||||
*/
|
||||
/** Statues shoot lightning at regular intervals. */
|
||||
public class Statue extends Entity {
|
||||
|
||||
protected int frames;
|
||||
|
||||
@@ -29,9 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The game world class. Maintain all the objects existed in the game frames.
|
||||
*/
|
||||
/** The game world class. Maintain all the objects existed in the game frames. */
|
||||
@Slf4j
|
||||
public class World {
|
||||
|
||||
@@ -45,9 +43,9 @@ public class World {
|
||||
}
|
||||
|
||||
/**
|
||||
* Main game loop. This loop will always run until the game is over. For
|
||||
* each loop it will process user input, update internal status, and render
|
||||
* the next frames. For more detail please refer to the game-loop pattern.
|
||||
* Main game loop. This loop will always run until the game is over. For each loop it will process
|
||||
* user input, update internal status, and render the next frames. For more detail please refer to
|
||||
* the game-loop pattern.
|
||||
*/
|
||||
private void gameLoop() {
|
||||
while (isRunning) {
|
||||
@@ -58,9 +56,8 @@ public class World {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle any user input that has happened since the last call. In order to
|
||||
* simulate the situation in real-life game, here we add a random time lag.
|
||||
* The time lag ranges from 50 ms to 250 ms.
|
||||
* Handle any user input that has happened since the last call. In order to simulate the situation
|
||||
* in real-life game, here we add a random time lag. The time lag ranges from 50 ms to 250 ms.
|
||||
*/
|
||||
private void processInput() {
|
||||
try {
|
||||
@@ -73,8 +70,8 @@ public class World {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update internal status. The update method pattern invoke update method for
|
||||
* each entity in the game.
|
||||
* Update internal status. The update method pattern invoke update method for each entity in the
|
||||
* game.
|
||||
*/
|
||||
private void update() {
|
||||
for (var entity : entities) {
|
||||
@@ -82,17 +79,12 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the next frame. Here we do nothing since it is not related to the
|
||||
* pattern.
|
||||
*/
|
||||
/** Render the next frame. Here we do nothing since it is not related to the pattern. */
|
||||
private void render() {
|
||||
// Does Nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Run game loop.
|
||||
*/
|
||||
/** Run game loop. */
|
||||
public void run() {
|
||||
LOGGER.info("Start game.");
|
||||
isRunning = true;
|
||||
@@ -100,9 +92,7 @@ public class World {
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop game loop.
|
||||
*/
|
||||
/** Stop game loop. */
|
||||
public void stop() {
|
||||
LOGGER.info("Stop game.");
|
||||
isRunning = false;
|
||||
@@ -111,5 +101,4 @@ public class World {
|
||||
public void addEntity(Entity entity) {
|
||||
entities.add(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
*/
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SkeletonTest {
|
||||
|
||||
private static Skeleton skeleton;
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class StatueTest {
|
||||
|
||||
private static Statue statue;
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
*/
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class WorldTest {
|
||||
|
||||
private static World world;
|
||||
|
||||
Reference in New Issue
Block a user