Search in sources :

Example 1 with Player

use of com.janfic.games.computercombat.model.Player in project computercombat by janfic.

the class MultiAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    for (int i = 0; i < abilities.size(); i++) {
        Ability ability = abilities.get(i);
        List<MoveResult> abilityResults = ability.doAbility(state, move);
        if (i != 0) {
            for (MoveResult abilityResult : abilityResults) {
                int index = -1;
                for (MoveAnimation animation : abilityResult.getAnimations()) {
                    if (animation instanceof ConsumeProgressAnimation) {
                        index = abilityResult.getAnimations().indexOf(animation);
                        break;
                    }
                }
                if (index >= 0) {
                    abilityResult.getAnimations().remove(index);
                }
            }
        }
        results.addAll(abilityResults);
        if (i < abilities.size() - 1) {
            for (Player player : state.players) {
                if (player.getUID().equals(move.getPlayerUID())) {
                    state.currentPlayerMove = player.getUID();
                }
            }
        }
    }
    return results;
}
Also used : Ability(com.janfic.games.computercombat.model.Ability) Player(com.janfic.games.computercombat.model.Player) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)

Example 2 with Player

use of com.janfic.games.computercombat.model.Player in project computercombat by janfic.

the class DrawAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> r = new ArrayList<>();
    UseAbilityMove abilityMove = (UseAbilityMove) move;
    List<Card> cards = state.activeEntities.get(move.getPlayerUID());
    Deck deck = state.decks.get(move.getPlayerUID());
    List<Card> drawnCards = new ArrayList<>();
    if (cards.size() < 4) {
        if (this.cards == null) {
            if (deck.size() > 0) {
                Card s = deck.draw();
                s.setOwnerUID(move.getPlayerUID());
                cards.add(s);
                drawnCards.add(s);
            }
        } else {
            for (StateAnalyzer<Integer> card : this.cards) {
                Card s = SQLAPI.getSingleton().getCardById(card.analyze(state, move), move.getPlayerUID());
                s.setOwnerUID(move.getPlayerUID());
                s.generateMatchID();
                cards.add(s);
                drawnCards.add(s);
            }
        }
    }
    List<MoveAnimation> animations = new ArrayList<>();
    if (abilityMove.getCard().getID() == 0) {
        state.computers.get(move.getPlayerUID()).setProgress(0);
    } else {
        for (Card card : state.activeEntities.get(move.getPlayerUID())) {
            if (card.equals(abilityMove.getCard())) {
                card.setProgress(0);
            }
        }
    }
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    ConsumeProgressAnimation drainAnimation = new ConsumeProgressAnimation(move.getPlayerUID(), drained);
    DrawAnimation drawAnimation = new DrawAnimation(move.getPlayerUID(), drawnCards);
    for (Player player : state.players) {
        if (player.getUID().equals(move.getPlayerUID())) {
            state.currentPlayerMove = state.getOtherProfile(player.getUID());
        }
    }
    animations.add(drainAnimation);
    animations.add(drawAnimation);
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    r.add(result);
    return r;
}
Also used : Player(com.janfic.games.computercombat.model.Player) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) Deck(com.janfic.games.computercombat.model.Deck) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card) DrawAnimation(com.janfic.games.computercombat.model.animations.DrawAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 3 with Player

use of com.janfic.games.computercombat.model.Player 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)

Aggregations

Player (com.janfic.games.computercombat.model.Player)3 ArrayList (java.util.ArrayList)3 Card (com.janfic.games.computercombat.model.Card)2 Deck (com.janfic.games.computercombat.model.Deck)2 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)2 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)2 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)2 Ability (com.janfic.games.computercombat.model.Ability)1 Component (com.janfic.games.computercombat.model.Component)1 DrawAnimation (com.janfic.games.computercombat.model.animations.DrawAnimation)1 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1 HashMap (java.util.HashMap)1 List (java.util.List)1