fix: add missing checks to game logic and fix events not being applied
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
|
||||
@ -37,7 +39,12 @@ public class GameInstance {
|
||||
public Optional<List<Event>> checkRequestsAndApply(Request... requests) {
|
||||
if(manager.processRequests(requests, true)) {
|
||||
ArrayList<Event> result = manager.apply();
|
||||
result.addAll(manager.checkPostPhase());
|
||||
|
||||
ArrayList<Event> result2 = manager.checkPostPhase();
|
||||
manager.applyEvents(result2);
|
||||
|
||||
result.addAll(result2);
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@ -62,7 +69,11 @@ public class GameInstance {
|
||||
public ArrayList<Event> startGame(ArrayList<Integer> selectedCharacters1, ArrayList<Integer> selectedCharacters2) {
|
||||
ArrayList<Event> result = manager.initGame(selectedCharacters1, selectedCharacters2);
|
||||
manager.applyEvents(result);
|
||||
result.addAll(manager.startGame());
|
||||
|
||||
ArrayList<Event> result2 = manager.startGame();
|
||||
manager.applyEvents(result2);
|
||||
|
||||
result.addAll(result2); //do not merge this, result needs to be applied before startGame is called
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -90,4 +101,44 @@ public class GameInstance {
|
||||
public void applyEvents(ArrayList<Event> events) {
|
||||
manager.applyEvents(events);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int y = 0; y < _state.mapSize.getY(); y++) {
|
||||
for(int x = 0; x < _state.mapSize.getX(); x++) {
|
||||
ArrayList<Entity> entities = _state.entities.findByPosition(new IntVector2(x, y));
|
||||
if(entities.isEmpty()) {
|
||||
sb.append(". ");
|
||||
}else {
|
||||
switch(entities.get(0).id.type) {
|
||||
case NPC -> {
|
||||
switch(entities.get(0).id.id) {
|
||||
case 0 -> {
|
||||
sb.append("G ");
|
||||
}
|
||||
case 1 -> {
|
||||
sb.append("S ");
|
||||
}
|
||||
case 2 -> {
|
||||
sb.append("T ");
|
||||
}
|
||||
}
|
||||
}
|
||||
case P1, P2 -> {
|
||||
sb.append("X ");
|
||||
}
|
||||
case Rocks -> {
|
||||
sb.append("O ");
|
||||
}
|
||||
case InfinityStones -> {
|
||||
sb.append("# ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user