package org.academiadecodigo.bootcamp.car;

import org.academiadecodigo.bootcamp.grid.GridColor;
import org.academiadecodigo.bootcamp.grid.position.GridPosition;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class Teleporter extends Car {

    public final static int SPEED = 20;
    private final static int BASECOOLDOWN = 8;

    private int cooldown;

    public Teleporter(GridPosition pos) {
        super(pos, CarType.TELEPORTER);
        cooldown = BASECOOLDOWN;
    }

    @Override
    public void move() {
        if (isCrashed()) {return;}
        cooldown--;
        switch(cooldown) {
            case 7:
            case 6:
            case 5:
            case 4:
                break;
            case 3:
            case 2:
                getPos().setColor(GridColor.NOCOLOR);
                break;
            case 1:
                getPos().hide();
                break;
            default:
                setDefaults();
                accelerate(chooseDirection(), SPEED);
        }
    }

    private void setDefaults() {
        cooldown = BASECOOLDOWN;
        getPos().setColor(CarType.TELEPORTER.getColor());
    }
}
