Fixed most reported issues by SonarCloud.
This commit is contained in:
@ -30,8 +30,8 @@ package com.iluwatar.typeobject;
|
||||
public class Candy {
|
||||
|
||||
enum Type {
|
||||
crushableCandy,
|
||||
rewardFruit
|
||||
CRUSHABLE_CANDY,
|
||||
REWARD_FRUIT
|
||||
}
|
||||
|
||||
String name;
|
||||
|
@ -104,13 +104,13 @@ public class CandyGame {
|
||||
|
||||
boolean continueRound() {
|
||||
for (var i = 0; i < this.cells.length; i++) {
|
||||
if (this.cells[cells.length - 1][i].candy.getType().equals(Type.rewardFruit)) {
|
||||
if (this.cells[cells.length - 1][i].candy.getType().equals(Type.REWARD_FRUIT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < this.cells.length; i++) {
|
||||
for (var j = 0; j < this.cells.length; j++) {
|
||||
if (!this.cells[i][j].candy.getType().equals(Type.rewardFruit)) {
|
||||
if (!this.cells[i][j].candy.getType().equals(Type.REWARD_FRUIT)) {
|
||||
var adj = adjacentCells(i, j);
|
||||
for (Cell cell : adj) {
|
||||
if (this.cells[i][j].candy.name.equals(cell.candy.name)) {
|
||||
@ -136,7 +136,7 @@ public class CandyGame {
|
||||
for (var i = 0; i < this.cells.length; i++) {
|
||||
var points = 0;
|
||||
var j = this.cells.length - 1;
|
||||
while (this.cells[j][i].candy.getType().equals(Type.rewardFruit)) {
|
||||
while (this.cells[j][i].candy.getType().equals(Type.REWARD_FRUIT)) {
|
||||
points = this.cells[j][i].candy.getPoints();
|
||||
this.cells[j][i].crush(pool, this.cells);
|
||||
handleChange(points);
|
||||
|
@ -74,8 +74,8 @@ public class Cell {
|
||||
}
|
||||
|
||||
int interact(Cell c, CellPool pool, Cell[][] cellMatrix) {
|
||||
if (this.candy.getType().equals(Type.rewardFruit) || c.candy.getType()
|
||||
.equals(Type.rewardFruit)) {
|
||||
if (this.candy.getType().equals(Type.REWARD_FRUIT) || c.candy.getType()
|
||||
.equals(Type.REWARD_FRUIT)) {
|
||||
return 0;
|
||||
} else {
|
||||
if (this.candy.name.equals(c.candy.name)) {
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.typeobject;
|
||||
|
||||
import com.iluwatar.typeobject.Candy.Type;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -39,6 +39,8 @@ import org.json.simple.parser.ParseException;
|
||||
|
||||
public class CellPool {
|
||||
private static final Random RANDOM = new Random();
|
||||
public static final String FRUIT = "fruit";
|
||||
public static final String CANDY = "candy";
|
||||
List<Cell> pool;
|
||||
int pointer;
|
||||
Candy[] randomCode;
|
||||
@ -51,11 +53,11 @@ public class CellPool {
|
||||
e.printStackTrace();
|
||||
//manually initialising this.randomCode
|
||||
this.randomCode = new Candy[5];
|
||||
randomCode[0] = new Candy("cherry", "fruit", Type.rewardFruit, 20);
|
||||
randomCode[1] = new Candy("mango", "fruit", Type.rewardFruit, 20);
|
||||
randomCode[2] = new Candy("purple popsicle", "candy", Type.crushableCandy, 10);
|
||||
randomCode[3] = new Candy("green jellybean", "candy", Type.crushableCandy, 10);
|
||||
randomCode[4] = new Candy("orange gum", "candy", Type.crushableCandy, 10);
|
||||
randomCode[0] = new Candy("cherry", FRUIT, Type.REWARD_FRUIT, 20);
|
||||
randomCode[1] = new Candy("mango", FRUIT, Type.REWARD_FRUIT, 20);
|
||||
randomCode[2] = new Candy("purple popsicle", CANDY, Type.CRUSHABLE_CANDY, 10);
|
||||
randomCode[3] = new Candy("green jellybean", CANDY, Type.CRUSHABLE_CANDY, 10);
|
||||
randomCode[4] = new Candy("orange gum", CANDY, Type.CRUSHABLE_CANDY, 10);
|
||||
}
|
||||
for (int i = 0; i < num; i++) {
|
||||
var c = new Cell();
|
||||
@ -84,7 +86,7 @@ public class CellPool {
|
||||
var i = 0;
|
||||
for (var e = jp.candies.keys(); e.hasMoreElements(); ) {
|
||||
var s = e.nextElement();
|
||||
if (!s.equals("fruit") && !s.equals("candy")) {
|
||||
if (!s.equals(FRUIT) && !s.equals(CANDY)) {
|
||||
//not generic
|
||||
randomCode[i] = jp.candies.get(s);
|
||||
i++;
|
||||
|
@ -29,7 +29,7 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
@ -58,9 +58,9 @@ public class JsonParser {
|
||||
var name = (String) candy.get("name");
|
||||
var parentName = (String) candy.get("parent");
|
||||
var t = (String) candy.get("type");
|
||||
var type = Type.crushableCandy;
|
||||
var type = Type.CRUSHABLE_CANDY;
|
||||
if (t.equals("rewardFruit")) {
|
||||
type = Type.rewardFruit;
|
||||
type = Type.REWARD_FRUIT;
|
||||
}
|
||||
var points = Integer.parseInt((String) candy.get("points"));
|
||||
var c = new Candy(name, parentName, type, points);
|
||||
|
@ -46,9 +46,9 @@ class CandyGameTest {
|
||||
@Test
|
||||
void continueRoundTest() {
|
||||
var matrix = new Cell[2][2];
|
||||
var c1 = new Candy("green jelly", "jelly", Type.crushableCandy, 5);
|
||||
var c2 = new Candy("purple jelly", "jelly", Type.crushableCandy, 5);
|
||||
var c3 = new Candy("green apple", "apple", Type.rewardFruit, 10);
|
||||
var c1 = new Candy("green jelly", "jelly", Type.CRUSHABLE_CANDY, 5);
|
||||
var c2 = new Candy("purple jelly", "jelly", Type.CRUSHABLE_CANDY, 5);
|
||||
var c3 = new Candy("green apple", "apple", Type.REWARD_FRUIT, 10);
|
||||
matrix[0][0] = new Cell(c1, 0, 0);
|
||||
matrix[0][1] = new Cell(c2, 1, 0);
|
||||
matrix[1][0] = new Cell(c3, 0, 1);
|
||||
|
@ -36,8 +36,8 @@ class CellTest {
|
||||
|
||||
@Test
|
||||
void interactTest() {
|
||||
var c1 = new Candy("green jelly", "jelly", Type.crushableCandy, 5);
|
||||
var c2 = new Candy("green apple", "apple", Type.rewardFruit, 10);
|
||||
var c1 = new Candy("green jelly", "jelly", Type.CRUSHABLE_CANDY, 5);
|
||||
var c2 = new Candy("green apple", "apple", Type.REWARD_FRUIT, 10);
|
||||
var matrix = new Cell[4][4];
|
||||
matrix[0][0] = new Cell(c1, 0, 0);
|
||||
matrix[0][1] = new Cell(c1, 1, 0);
|
||||
@ -51,8 +51,8 @@ class CellTest {
|
||||
|
||||
@Test
|
||||
void crushTest() {
|
||||
var c1 = new Candy("green jelly", "jelly", Type.crushableCandy, 5);
|
||||
var c2 = new Candy("purple candy", "candy", Type.crushableCandy, 5);
|
||||
var c1 = new Candy("green jelly", "jelly", Type.CRUSHABLE_CANDY, 5);
|
||||
var c2 = new Candy("purple candy", "candy", Type.CRUSHABLE_CANDY, 5);
|
||||
var matrix = new Cell[4][4];
|
||||
matrix[0][0] = new Cell(c1, 0, 0);
|
||||
matrix[1][0] = new Cell(c2, 0, 1);
|
||||
|
Reference in New Issue
Block a user