Search in sources :

Example 16 with Component

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;
}
Also used : ArrayList(java.util.ArrayList) Component(com.janfic.games.computercombat.model.Component)

Example 17 with Component

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");
}
Also used : Component(com.janfic.games.computercombat.model.Component)

Example 18 with Component

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;
}
Also used : Player(com.janfic.games.computercombat.model.Player) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Deck(com.janfic.games.computercombat.model.Deck) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.janfic.games.computercombat.model.Component)

Example 19 with Component

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;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CollectAnimation(com.janfic.games.computercombat.model.animations.CollectAnimation) CascadeAnimation(com.janfic.games.computercombat.model.animations.CascadeAnimation) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 20 with Component

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();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Component(com.janfic.games.computercombat.model.Component) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Component (com.janfic.games.computercombat.model.Component)20 ArrayList (java.util.ArrayList)14 List (java.util.List)8 Card (com.janfic.games.computercombat.model.Card)7 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)7 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)5 HashMap (java.util.HashMap)4 Action (com.badlogic.gdx.scenes.scene2d.Action)3 ComponentActor (com.janfic.games.computercombat.actors.ComponentActor)3 MatchState (com.janfic.games.computercombat.model.match.MatchState)3 Move (com.janfic.games.computercombat.model.moves.Move)3 Deck (com.janfic.games.computercombat.model.Deck)2 Player (com.janfic.games.computercombat.model.Player)2 CascadeAnimation (com.janfic.games.computercombat.model.animations.CascadeAnimation)2 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)2 SpawnAnimation (com.janfic.games.computercombat.model.animations.SpawnAnimation)2 SwitchAnimation (com.janfic.games.computercombat.model.animations.SwitchAnimation)2 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)2 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 Vector2 (com.badlogic.gdx.math.Vector2)1