Newer
Older
Algolike / src / main / java / controls / StepScheduler.java
package controls;

import interfaces.IAttack;
import resources.Algo;

import java.util.List;
import java.util.Map;

public class StepScheduler implements IAttack {
    Algo algo;
    int turnCount = 0;
    boolean isATurn;
    boolean isSucceedLatestAttack;

    public StepScheduler() {
        algo = new Algo();
        isATurn = true;
    }

    @Override
    public void attack(int guess, int attacker, int target) {
        if (isATurn) {
            if (isDeckLess()) {
                //algo.selectAndAttackA(attacker, target, guess);
                isSucceedLatestAttack = algo.getResultBySelectingA().getKey();
            } else {
              //  algo.drawAndAttackA(target, guess);
                isSucceedLatestAttack = algo.getResultByDrawingA().getKey();
            }
        } else {
            if (isDeckLess()) {
              //  algo.selectAndAttackB(attacker, target, guess);
                isSucceedLatestAttack = algo.getResultBySelectingB().getKey();
            } else {
              //  algo.drawAndAttackB(target, guess);
                isSucceedLatestAttack = algo.getResultByDrawingB().getKey();
            }
        }
        turnCount++;

    }

    @Override
    public List<Map.Entry<Integer, Boolean>> getMyHands() {
        return algo.getHandsA();
    }

    @Override
    public List<Map.Entry<Integer, Boolean>> getOpponentHands() {
        return algo.getHandsB();
    }

    @Override
    public Map.Entry<Integer, Boolean> getTopCard() {
        if (isDeckLess()) return null;
        return algo.getDeck().get(0);
    }

    public boolean isDeckLess() {
        return algo.getDeck().size() == 0;
    }

    @Override
    public int getDeckNumber() {
        return algo.getDeck().size();
    }

    public boolean isSucceedLatestAttack() {
        return isSucceedLatestAttack;
    }

    @Override
    public boolean updateTurn() {
        isATurn = isATurn ? false : true;
        return isATurn;
    }

    public boolean isATurn() {
        return isATurn;
    }

    @Override
    public boolean isALose() {
        return algo.getLoseA();
    }

    @Override
    public boolean isBLose() {
        return algo.getLoseB();
    }
}