Search in sources :

Example 1 with MatchComponentsMove

use of com.janfic.games.computercombat.model.moves.MatchComponentsMove in project computercombat by janfic.

the class GameRules method getAvailableMoves.

public static List<Move> getAvailableMoves(MatchState state) {
    List<Move> moves = new ArrayList<>();
    // Get MatchComponentsMoves
    List<Integer[]> matches = areAvailableComponentMatches(state);
    for (Integer[] match : matches) {
        Component a = state.getComponentBoard()[match[0]][match[1]];
        Component b = state.getComponentBoard()[match[2]][match[3]];
        MatchComponentsMove m = new MatchComponentsMove(state.currentPlayerMove, a, b);
        moves.add(m);
    }
    // Get UseAbilityMoves
    String uid = state.currentPlayerMove;
    for (Card card : state.activeEntities.get(uid)) {
        if (card.getRunProgress() >= card.getRunRequirements()) {
            List<UseAbilityMove> generatedMoves = generateMovesWithSelection(0, card, state, new ArrayList<>(), new ArrayList<>());
            moves.addAll(generatedMoves);
        }
    }
    Card c = state.computers.get(uid);
    if (c.getRunProgress() >= c.getRunRequirements()) {
        UseAbilityMove m = new UseAbilityMove(uid, c, null, null);
        moves.add(m);
    }
    return moves;
}
Also used : MatchComponentsMove(com.janfic.games.computercombat.model.moves.MatchComponentsMove) MatchComponentsMove(com.janfic.games.computercombat.model.moves.MatchComponentsMove) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) Move(com.janfic.games.computercombat.model.moves.Move) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove)

Example 2 with MatchComponentsMove

use of com.janfic.games.computercombat.model.moves.MatchComponentsMove in project computercombat by janfic.

the class Board method addComponent.

public void addComponent(ComponentActor actor, int x, int y) {
    board[x][y].setActor(actor);
    components.add(actor);
    actor.addListener(new ClickListener() {

        float dragStartX = -10, dragStartY = -10;

        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            super.enter(event, x, y, pointer, fromActor);
            if (!selected.contains(actor) && canSelect) {
                actor.addAction(Actions.scaleTo(1.2f, 1.2f, 0.5f));
            }
        }

        @Override
        public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
            super.exit(event, x, y, pointer, toActor);
            if (!selected.contains(actor) && canSelect) {
                actor.clearActions();
                actor.addAction(Actions.scaleTo(1, 1, 0.25f));
            }
        }

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            dragStartX = x;
            dragStartY = y;
            return true;
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            if (!canSelect || componentsToSelect > -1) {
                return;
            }
            selected.clear();
            int ax = actor.getComponent().getX();
            int ay = actor.getComponent().getY();
            if (dragStartX > 0 && dragStartY > 0) {
                float deltaX = dragStartX - x;
                float deltaY = dragStartY - y;
                if (Math.abs(deltaX) > 10 || Math.abs(deltaY) > 10) {
                    int bx = 0;
                    int by = 0;
                    if (deltaX < -10) {
                        bx++;
                    } else if (deltaX > 10) {
                        bx--;
                    } else if (deltaY < -10) {
                        by--;
                    } else if (deltaY > 10) {
                        by++;
                    }
                    if (ax + bx >= 0 && ax + bx < 8 && ay + by >= 0 && ay + by < 8) {
                        ComponentActor other = board[ax + bx][ay + by].getActor();
                        float s1x = actor.getX();
                        float s1y = actor.getY();
                        float s2x = other.getX();
                        float s2y = other.getY();
                        canSelect = false;
                        dragStartX = -10;
                        dragStartY = -10;
                        Move move = new MatchComponentsMove(game.getCurrentProfile().getUID(), actor.getComponent(), other.getComponent());
                        boolean isLegalMove = GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move);
                        if (!isLegalMove) {
                            List<Action> as = new ArrayList<>();
                            Action a = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s1x, s1y, 0.35f), Actions.moveTo(s2x, s2y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f));
                            Action a2 = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s2x, s2y, 0.35f), Actions.moveTo(s1x, s1y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f), Actions.run(removeActions));
                            a.setActor(other);
                            a2.setActor(actor);
                            as.add(a);
                            as.add(a2);
                            matchAnimations.add(as);
                        } else {
                            List<Action> as = new ArrayList<>();
                            Action a = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s1x, s1y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f));
                            Action a2 = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s2x, s2y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f));
                            a.setActor(other);
                            a2.setActor(actor);
                            as.add(a);
                            as.add(a2);
                            matchAnimations.add(as);
                            Board.this.move = move;
                        }
                    }
                }
            }
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            dragStartX = -10;
            dragStartY = -10;
            if (!canSelect) {
                return;
            }
            if (selected.contains(actor)) {
                selected.get(0).clearActions();
                selected.get(0).addAction(Actions.scaleTo(1, 1, 0.25f));
                selected.get(0).addAction(Actions.sequence(Actions.rotateTo(0, 0.25f), Actions.run(removeActions)));
                selected.remove(actor);
                return;
            } else {
                selected.add(actor);
                selected.get(0).addAction(Actions.forever(Actions.sequence(Actions.rotateTo(10, 0.1f), Actions.rotateTo(-10, 0.1f))));
            }
            if (componentsToSelect != -1 || selected.size() <= 1) {
                return;
            }
            // Selected New Actor
            int ax = actor.getComponent().getX();
            int ay = actor.getComponent().getY();
            int sx = selected.get(0).getComponent().getX();
            int sy = selected.get(0).getComponent().getY();
            // Check if can switch
            if (isNeighbor(ax, ay, sx, sy) && canSelect) {
                // switch anim
                canSelect = false;
                selected.add(actor);
                selected.get(1).addAction(Actions.forever(Actions.sequence(Actions.rotateTo(10, 0.1f), Actions.rotateTo(-10, 0.1f))));
                float s1x = selected.get(0).getX();
                float s1y = selected.get(0).getY();
                float s2x = selected.get(1).getX();
                float s2y = selected.get(1).getY();
                selected.get(0).clearActions();
                selected.get(1).clearActions();
                Move move = new MatchComponentsMove(game.getCurrentProfile().getUID(), selected.get(0).getComponent(), selected.get(1).getComponent());
                boolean isLegalMove = GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move);
                if (!isLegalMove) {
                    List<Action> as = new ArrayList<>();
                    Action a = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s1x, s1y, 0.35f), Actions.moveTo(s2x, s2y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f));
                    Action a2 = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s2x, s2y, 0.35f), Actions.moveTo(s1x, s1y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f), Actions.run(removeActions));
                    a.setActor(selected.get(1));
                    a2.setActor(selected.get(0));
                    as.add(a);
                    as.add(a2);
                    matchAnimations.add(as);
                } else {
                    List<Action> as = new ArrayList<>();
                    Action a = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s1x, s1y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f));
                    Action a2 = Actions.sequence(Actions.rotateTo(0), Actions.moveTo(s2x, s2y, 0.35f), Actions.scaleTo(1, 1, 0.25f), Actions.rotateTo(0, 0.25f));
                    a.setActor(selected.get(1));
                    a2.setActor(selected.get(0));
                    as.add(a);
                    as.add(a2);
                    matchAnimations.add(as);
                    Board.this.move = move;
                }
            } else {
                if (!canSelect) {
                    return;
                }
                for (ComponentActor componentActor : selected) {
                    componentActor.clearActions();
                    componentActor.addAction(Actions.scaleTo(1, 1, 0.25f));
                    componentActor.addAction(Actions.rotateTo(0, 0.25f));
                    componentActor.clearActions();
                }
                selected.clear();
                selected.add(actor);
                selected.get(0).addAction(Actions.forever(Actions.sequence(Actions.rotateTo(10, 0.1f), Actions.rotateTo(-10, 0.1f))));
            }
        }
    });
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) MatchComponentsMove(com.janfic.games.computercombat.model.moves.MatchComponentsMove) Move(com.janfic.games.computercombat.model.moves.Move) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ArrayList(java.util.ArrayList) List(java.util.List) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) MatchComponentsMove(com.janfic.games.computercombat.model.moves.MatchComponentsMove) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

MatchComponentsMove (com.janfic.games.computercombat.model.moves.MatchComponentsMove)2 Move (com.janfic.games.computercombat.model.moves.Move)2 Action (com.badlogic.gdx.scenes.scene2d.Action)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1