mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 19:26:12 +00:00
* fix: add UnsupportedOperationException in KingsHand and GameLoopTest * refactor: update DatabaseService to use constant for BINARY_DATA and remove obsolete test files * refactor: update timePasses method in KingsHand * refactor CandyGame.java * refactor: simplify boundary checks in CandyGame * feat: add getters for type and points in Candy class and initialize logger in CandyGame * remove class and logger initialization in CandyGame * Modify CandyGame.java * fix Checkstyle violations * Remove generic wildcard type in ThreatAwareSystem
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel
|
||||
* is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
@@ -27,12 +28,12 @@ package com.iluwatar.typeobject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Type object pattern is the pattern we use when the OOP concept of creating a base class and
|
||||
* Type object pattern is the pattern we use when the OOP concept of creating a base class and
|
||||
* inheriting from it just doesn't work for the case in hand. This happens when we either don't know
|
||||
* what types we will need upfront, or want to be able to modify or add new types conveniently w/o
|
||||
* recompiling repeatedly. The pattern provides a solution by allowing flexible creation of required
|
||||
* objects by creating one class, which has a field which represents the 'type' of the object.</p>
|
||||
* <p>In this example, we have a mini candy-crush game in action. There are many different candies
|
||||
* objects by creating one class, which has a field which represents the 'type' of the object.
|
||||
* In this example, we have a mini candy-crush game in action. There are many different candies
|
||||
* in the game, which may change over time, as we may want to upgrade the game. To make the object
|
||||
* creation convenient, we have a class {@link Candy} which has a field name, parent, points and
|
||||
* Type. We have a json file {@link candy} which contains the details about the candies, and this is
|
||||
@@ -41,7 +42,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* how crushing can be done, how the matrix is to be reconfigured and how points are to be gained.
|
||||
* The {@link CellPool} class is a pool which reuses the candy cells that have been crushed instead
|
||||
* of making new ones repeatedly. The {@link CandyGame} class has the rules for the continuation of
|
||||
* the game and the {@link App} class has the game itself.</p>
|
||||
* the game and the {@link App} class has the game itself.
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.iluwatar.typeobject.Candy.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The CandyGame class contains the rules for the continuation of the game and has the game matrix
|
||||
@@ -37,7 +39,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
@SuppressWarnings("java:S3776") //"Cognitive Complexity of methods should not be too high"
|
||||
public class CandyGame {
|
||||
|
||||
Cell[][] cells;
|
||||
CellPool pool;
|
||||
int totalPoints;
|
||||
@@ -85,17 +86,20 @@ public class CandyGame {
|
||||
if (x == 0) {
|
||||
adjacent.add(this.cells[y][1]);
|
||||
}
|
||||
if (y == cells.length - 1) {
|
||||
if (y == cells.length - 1 && cells.length > 1) {
|
||||
adjacent.add(this.cells[cells.length - 2][x]);
|
||||
}
|
||||
if (x == cells.length - 1) {
|
||||
|
||||
if (x == cells.length - 1 && cells.length > 1) {
|
||||
adjacent.add(this.cells[y][cells.length - 2]);
|
||||
}
|
||||
|
||||
|
||||
if (y > 0 && y < cells.length - 1) {
|
||||
adjacent.add(this.cells[y - 1][x]);
|
||||
adjacent.add(this.cells[y + 1][x]);
|
||||
}
|
||||
if (x > 0 && x < cells.length - 1) {
|
||||
if (y >= 0 && y < cells.length && x > 0 && x < cells[y].length - 1) {
|
||||
adjacent.add(this.cells[y][x - 1]);
|
||||
adjacent.add(this.cells[y][x + 1]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user