use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class TransformComponentsAnimation method animate.
@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
List<List<Action>> animation = new ArrayList<>();
List<Action> transformAnimation = new ArrayList<>();
for (int i = 0; i < originalComponents.size(); i++) {
Component originalComponent = originalComponents.get(i);
Component newComponent = newComponents.get(i);
for (ComponentActor componentActor : screen.getBoard().getComponents()) {
if (componentActor.getComponent().equals(originalComponent)) {
Action transformAction = Actions.sequence(Actions.fadeOut(0.25f * animationSpeed), Actions.run(() -> {
componentActor.setRegion(newComponent);
}), Actions.fadeIn(0.25f * animationSpeed));
transformAction.setActor(componentActor);
transformAnimation.add(transformAction);
}
}
}
animation.add(transformAnimation);
return animation;
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method buildNeighbors.
public static void buildNeighbors(Component[][] componentBoard) {
for (int x = 0; x < componentBoard.length; x++) {
for (int y = 0; y < componentBoard[x].length; y++) {
componentBoard[x][y].invalidate();
for (int i = 0; i < Component.coordsToNeighbors.length; i += 3) {
int neighborX = x + Component.coordsToNeighbors[i];
int neighborY = y + Component.coordsToNeighbors[i + 1];
if (neighborX < componentBoard.length && neighborY < componentBoard[x].length && neighborX >= 0 && neighborY >= 0) {
Component c = componentBoard[neighborX][neighborY];
componentBoard[x][y].setNeighbor(Component.coordsToNeighbors[i + 2], c);
}
}
}
}
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method read.
@Override
public void read(Json json, JsonValue jsonData) {
json.setTypeName("class");
this.players = json.readValue("players", List.class, Player.class, jsonData);
json.setTypeName(null);
this.isGameOver = json.readValue("isGameOver", boolean.class, jsonData);
this.winner = json.readValue("winner", String.class, jsonData);
this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
this.decks = json.readValue("decks", HashMap.class, Deck.class, jsonData);
HashMap<String, List<JsonValue>> v = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
this.activeEntities = new HashMap<>();
for (String string : v.keySet()) {
List<Card> cards = new ArrayList<>();
for (JsonValue jsonValue : v.get(string)) {
Card c = json.readValue(Card.class, jsonValue);
cards.add(c);
}
activeEntities.put(string, cards);
}
this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
String boardString = json.readValue("componentBoard", String.class, jsonData);
componentBoard = new Component[8][8];
assert (boardString.length() == 64);
for (int i = 0; i < boardString.length(); i++) {
int x = i / 8;
int y = i % 8;
try {
componentBoard[x][y] = new Component(Integer.parseInt("" + boardString.substring(i, i + 1)), x, y);
} catch (Exception e) {
e.printStackTrace();
}
}
json.setTypeName("class");
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method cascade.
public List<CascadeData> cascade() {
List<CascadeAnimation.CascadeData> cascade = new ArrayList<>();
for (int x = 0; x < componentBoard.length; x++) {
for (int y = componentBoard[x].length - 1; y >= 0; y--) {
if (componentBoard[x][y].getColor() == 0) {
componentBoard[x][y].invalidate();
componentBoard[x][y].invalidateNeighbors();
boolean cascaded = false;
for (int i = y - 1; i >= 0; i--) {
if (componentBoard[x][i].getColor() != 0) {
Component fallenComponent = new Component(componentBoard[x][i].getColor(), x, y);
Component originalComponent = new Component(componentBoard[x][i]);
cascade.add(new CascadeAnimation.CascadeData(fallenComponent, originalComponent));
componentBoard[x][y].changeColor(componentBoard[x][i].getColor());
componentBoard[x][i].changeColor(0);
cascaded = true;
break;
}
}
if (cascaded == false) {
componentBoard[x][y].changeColor(GameRules.getNewColor());
cascade.add(new CascadeAnimation.CascadeData(new Component(componentBoard[x][y]), x, (-y) - 1));
}
}
}
}
return cascade;
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method progress.
public void progress(CollectAnimation collectAnimation) {
Map<Component, Card> progress = collectAnimation.progress;
for (Component c : collectAnimation.getAllComponents()) {
boolean collectedByCard = false;
for (Card card : activeEntities.get(currentPlayerMove)) {
if (card.getRunProgress() < card.getRunRequirements()) {
for (Integer requirement : card.getRunComponents()) {
if (c.getColor() == requirement) {
card.recieveComponents(requirement, 1);
collectedByCard = true;
progress.put(c, card);
break;
}
}
}
if (collectedByCard == true) {
break;
}
}
if (collectedByCard == false) {
computers.get(currentPlayerMove).recieveProgress(1);
}
}
}
Aggregations