diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/BaseGameLogicTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/BaseGameLogicTest.java new file mode 100644 index 0000000..ea7539a --- /dev/null +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/BaseGameLogicTest.java @@ -0,0 +1,80 @@ +package uulm.teamname.marvelous.gamelibrary.gamelogic; + +import uulm.teamname.marvelous.gamelibrary.config.*; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.concurrent.ThreadLocalRandom; + +public class BaseGameLogicTest { + protected static final Iterator randomIntegers = ThreadLocalRandom.current().ints().iterator(); + + protected static final PartyConfig partyConfig = new PartyConfig(); + protected static final CharacterConfig characterConfig = new CharacterConfig(); + protected static final ScenarioConfig scenarioConfig = new ScenarioConfig(); + + protected static final ArrayList player1Selection = new ArrayList<>(); + protected static final ArrayList player2Selection = new ArrayList<>(); + + protected static void generate() { + partyConfig.maxRounds = 100; + partyConfig.mindStoneCD = 2; + partyConfig.powerStoneCD = 3; + partyConfig.realityStoneCD = 4; + partyConfig.soulStoneCD = 5; + partyConfig.spaceStoneCD = 6; + partyConfig.timeStoneCD = 7; + partyConfig.mindStoneDMG = 3; + + characterConfig.characters = new CharacterProperties[] { + generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), + generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter() + }; + + scenarioConfig.name = generateName(20); + scenarioConfig.author = generateName(20); + scenarioConfig.scenario = new FieldType[20][20]; + for(int x = 0; x < scenarioConfig.scenario[0].length; x++) { + for(int y = 0; y < scenarioConfig.scenario.length; y++) { + if(Math.abs(randomIntegers.next() % 100) < 10) { + scenarioConfig.scenario[y][x] = FieldType.ROCK; + }else { + scenarioConfig.scenario[y][x] = FieldType.GRASS; + } + } + } + + for(int i = 0; i < 6; i++) { + player1Selection.add(i); + } + + for(int i = 6; i < 12; i++) { + player2Selection.add(i); + } + } + + private static String generateName(int length) { + StringBuilder name = new StringBuilder(); + for (int j = 0; j < length; j++) { + name.append((char) ( + 65 + Math.abs(randomIntegers.next() % 26) + 32 * Math.abs(randomIntegers.next() % 2) + )); + } + return name.toString(); + } + + private static CharacterProperties generateCharacter() { + CharacterProperties props = new CharacterProperties(); + + props.name = generateName(10); + + props.HP = Math.abs(randomIntegers.next() % 15 + 5); + props.MP = Math.abs(randomIntegers.next() % 5 + 2); + props.AP = Math.abs(randomIntegers.next() % 5 + 2); + props.meleeDamage = Math.abs(randomIntegers.next() % 5 + 2); + props.rangedDamage = Math.abs(randomIntegers.next() % 5 + 2); + props.attackRange = Math.abs(randomIntegers.next() % 5 + 2); + + return props; + } +} diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java index 4646f65..83089b2 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java @@ -10,81 +10,14 @@ import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.requests.*; import java.util.*; -import java.util.concurrent.ThreadLocalRandom; import static org.junit.jupiter.api.Assertions.*; -class GameLogicTest { - private static final Iterator randomIntegers = ThreadLocalRandom.current().ints().iterator(); - - private static final PartyConfig partyConfig = new PartyConfig(); - private static final CharacterConfig characterConfig = new CharacterConfig(); - private static final ScenarioConfig scenarioConfig = new ScenarioConfig(); - - private static final ArrayList player1Selection = new ArrayList<>(); - private static final ArrayList player2Selection = new ArrayList<>(); +class GameLogicTest extends BaseGameLogicTest { @BeforeAll static void setUp() { - partyConfig.maxRounds = 100; - partyConfig.mindStoneCD = 2; - partyConfig.powerStoneCD = 3; - partyConfig.realityStoneCD = 4; - partyConfig.soulStoneCD = 5; - partyConfig.spaceStoneCD = 6; - partyConfig.timeStoneCD = 7; - partyConfig.mindStoneDMG = 3; - - characterConfig.characters = new CharacterProperties[] { - generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), - generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter(), generateCharacter() - }; - - scenarioConfig.name = generateName(20); - scenarioConfig.author = generateName(20); - scenarioConfig.scenario = new FieldType[20][20]; - for(int x = 0; x < scenarioConfig.scenario[0].length; x++) { - for(int y = 0; y < scenarioConfig.scenario.length; y++) { - if(Math.abs(randomIntegers.next() % 100) < 10) { - scenarioConfig.scenario[y][x] = FieldType.ROCK; - }else { - scenarioConfig.scenario[y][x] = FieldType.GRASS; - } - } - } - - for(int i = 0; i < 6; i++) { - player1Selection.add(i); - } - - for(int i = 6; i < 12; i++) { - player2Selection.add(i); - } - } - - private static String generateName(int length) { - StringBuilder name = new StringBuilder(); - for (int j = 0; j < length; j++) { - name.append((char) ( - 65 + Math.abs(randomIntegers.next() % 26) + 32 * Math.abs(randomIntegers.next() % 2) - )); - } - return name.toString(); - } - - private static CharacterProperties generateCharacter() { - CharacterProperties props = new CharacterProperties(); - - props.name = generateName(10); - - props.HP = Math.abs(randomIntegers.next() % 15 + 5); - props.MP = Math.abs(randomIntegers.next() % 5 + 2); - props.AP = Math.abs(randomIntegers.next() % 5 + 2); - props.meleeDamage = Math.abs(randomIntegers.next() % 5 + 2); - props.rangedDamage = Math.abs(randomIntegers.next() % 5 + 2); - props.attackRange = Math.abs(randomIntegers.next() % 5 + 2); - - return props; + generate(); }