use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class Match method makeBoard.
private Component[][] makeBoard(Map<Integer, Integer> colorFrequencies) throws Exception {
Component[][] componentBoard = new Component[8][8];
// Construct Component Frequencies
List<Integer> colorBag = new ArrayList<>();
for (Integer type : colorFrequencies.keySet()) {
int frequency = colorFrequencies.get(type);
colorBag.addAll(Collections.nCopies(frequency, type));
}
// Generate Board
for (int x = 0; x < componentBoard.length; x++) {
for (int y = 0; y < componentBoard[x].length; y++) {
int color = colorBag.get((int) (Math.random() * colorBag.size()));
Component c = new Component(color, x, y);
componentBoard[x][y] = c;
c.invalidate();
}
}
// Set Neighbors
MatchState.buildNeighbors(componentBoard);
return componentBoard;
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method write.
@Override
public void write(Json json) {
json.setTypeName(null);
json.writeValue("players", players, List.class);
json.writeValue("currentPlayerMove", currentPlayerMove, Player.class);
json.writeValue("activeEntities", activeEntities, Map.class);
json.writeValue("computers", computers, Map.class);
json.writeValue("decks", decks, Map.class);
json.writeValue("winner", winner, Player.class);
json.writeValue("isGameOver", isGameOver, boolean.class);
String board = "";
for (Component[] components : componentBoard) {
for (Component component : components) {
board += "" + component.getColor();
}
}
assert (board.length() == 64);
json.writeValue("componentBoard", board);
json.setTypeName("class");
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method clone.
@Override
public Object clone() throws CloneNotSupportedException {
Player player1 = (Player) players.get(0).clone();
Player player2 = (Player) players.get(1).clone();
Component[][] componentBoard = new Component[8][8];
for (int x = 0; x < componentBoard.length; x++) {
for (int y = 0; y < componentBoard[x].length; y++) {
componentBoard[x][y] = new Component(this.componentBoard[x][y]);
}
}
Map<String, List<Card>> activeEntities = new HashMap<>();
List<Card> player1Cards = new ArrayList<>();
List<Card> player2Cards = new ArrayList<>();
activeEntities.put(player1.getUID(), player1Cards);
activeEntities.put(player2.getUID(), player2Cards);
for (String string : this.activeEntities.keySet()) {
for (Card card : this.activeEntities.get(string)) {
activeEntities.get(string).add((Card) (card.clone()));
}
}
Map<String, Deck> decks = new HashMap<>();
for (String uid : this.decks.keySet()) {
decks.put(uid, (Deck) this.decks.get(uid).clone());
}
Map<String, Card> computers = new HashMap<>();
for (String uid : this.computers.keySet()) {
computers.put(uid, (Card) this.computers.get(uid).clone());
}
MatchState state = new MatchState(player1, player2, componentBoard, activeEntities, computers, decks);
state.isGameOver = this.isGameOver;
if (this.winner != null) {
state.winner = "" + this.winner;
}
state.currentPlayerMove = "" + this.currentPlayerMove;
MatchState.buildNeighbors(componentBoard);
state.update();
return state;
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class MatchState method results.
public List<MoveResult> results(Move move) {
List<MoveResult> results = new ArrayList<>();
boolean extraTurn = false;
while (isInvalidBoard() || getMatches().isEmpty() == false) {
// Save Old State
// Update
update();
// Collect Components
Map<Integer, List<Component>> collected = collectComponents();
Map<Component, Card> progress = new HashMap<>();
CollectAnimation collectAnimation = new CollectAnimation(collected, progress);
progress(collectAnimation);
// Attack
boolean attack = false;
for (Integer integer : collected.keySet()) {
for (Component component : collected.get(integer)) {
if (component.getColor() == 5) {
attack = true;
break;
}
}
}
if (attack && activeEntities.get(currentPlayerMove).isEmpty() == false) {
results.addAll(attack(move));
}
// Remove
for (Integer matchNumber : collected.keySet()) {
for (Component component : collected.get(matchNumber)) {
this.componentBoard[component.getX()][component.getY()].changeColor(0);
}
}
// Cascade
// This can be optimized by storing collected components
CascadeAnimation cascadeAnimation = new CascadeAnimation(cascade());
List<MoveAnimation> moveAnimation = new ArrayList<>();
moveAnimation.add(collectAnimation);
moveAnimation.add(cascadeAnimation);
for (Integer integer : collected.keySet()) {
if (collected.get(integer).size() >= 4) {
extraTurn = true;
}
}
MoveResult result = new MoveResult(move, MatchState.record(this), moveAnimation);
results.add(result);
}
if (extraTurn == false && results.size() > 0) {
MoveResult last = results.get(results.size() - 1);
last.getState().currentPlayerMove = last.getState().getOtherProfile(last.getState().currentPlayerMove);
this.currentPlayerMove = last.getState().currentPlayerMove;
}
return results;
}
use of com.janfic.games.computercombat.model.Component in project computercombat by janfic.
the class FilterWindowActor method buildComponentsTable.
private void buildComponentsTable() {
componentsTable.clear();
for (int i = 1; i <= 6; i++) {
if (i == 5) {
continue;
}
final int j = i;
Table table = new Table();
table.defaults().pad(1);
table.add(new ComponentActor(game.getAssetManager().get("texture_packs/components.atlas"), new Component(i, 0, 0))).row();
LEDActor led = new LEDActor(skin, Component.colorToTextureName.get(j).toUpperCase()) {
@Override
public void act(float delta) {
super.act(delta);
this.setLightOn(FilterWindowActor.this.components.contains((Integer) j));
}
};
table.add(led);
componentsTable.add(table);
table.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (FilterWindowActor.this.components.contains(j)) {
FilterWindowActor.this.components.remove((Integer) j);
led.setLightOn(false);
} else {
FilterWindowActor.this.components.add((Integer) j);
led.setLightOn(true);
}
}
});
}
TextButton toggleComponentFilterType = new TextButton("", skin) {
@Override
public void act(float delta) {
// To change body of generated methods, choose Tools | Templates.
super.act(delta);
this.setText(allComponentsNeeded ? "All" : "One");
}
};
toggleComponentFilterType.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
allComponentsNeeded = !allComponentsNeeded;
}
});
componentsTable.add(toggleComponentFilterType).growX();
}
Aggregations