Search in sources :

Example 1 with CascadeData

use of com.janfic.games.computercombat.model.animations.CascadeAnimation.CascadeData in project computercombat by janfic.

the class MatchState method cascade.

public List<CascadeData> cascade() {
    List<CascadeAnimation.CascadeData> cascade = new ArrayList<>();
    for (int x = 0; x < componentBoard.length; x++) {
        for (int y = componentBoard[x].length - 1; y >= 0; y--) {
            if (componentBoard[x][y].getColor() == 0) {
                componentBoard[x][y].invalidate();
                componentBoard[x][y].invalidateNeighbors();
                boolean cascaded = false;
                for (int i = y - 1; i >= 0; i--) {
                    if (componentBoard[x][i].getColor() != 0) {
                        Component fallenComponent = new Component(componentBoard[x][i].getColor(), x, y);
                        Component originalComponent = new Component(componentBoard[x][i]);
                        cascade.add(new CascadeAnimation.CascadeData(fallenComponent, originalComponent));
                        componentBoard[x][y].changeColor(componentBoard[x][i].getColor());
                        componentBoard[x][i].changeColor(0);
                        cascaded = true;
                        break;
                    }
                }
                if (cascaded == false) {
                    componentBoard[x][y].changeColor(GameRules.getNewColor());
                    cascade.add(new CascadeAnimation.CascadeData(new Component(componentBoard[x][y]), x, (-y) - 1));
                }
            }
        }
    }
    return cascade;
}
Also used : ArrayList(java.util.ArrayList) CascadeAnimation(com.janfic.games.computercombat.model.animations.CascadeAnimation) Component(com.janfic.games.computercombat.model.Component) CascadeData(com.janfic.games.computercombat.model.animations.CascadeAnimation.CascadeData) CascadeData(com.janfic.games.computercombat.model.animations.CascadeAnimation.CascadeData)

Aggregations

Component (com.janfic.games.computercombat.model.Component)1 CascadeAnimation (com.janfic.games.computercombat.model.animations.CascadeAnimation)1 CascadeData (com.janfic.games.computercombat.model.animations.CascadeAnimation.CascadeData)1 ArrayList (java.util.ArrayList)1