package org.academiadecodigo.bootcamp11.pokemon.trainer;

import org.academiadecodigo.bootcamp11.pokemon.map.Map;
import org.academiadecodigo.bootcamp11.pokemon.map.city.City;
import org.academiadecodigo.bootcamp11.pokemon.map.city.PalletTown;

/**
 * Each MainCharacter has a homeTown.
 */

public class MainCharacter extends Trainer {
    private City hometown;
    private City currentCity;
    private Map map;
    private boolean gameOver;

    public MainCharacter(String name) {
        super(name);
        this.hometown = new PalletTown();
        this.gameOver = false;
    }

    public void setGameOver() {
        this.gameOver = true;
    }

    public boolean canPlay() {
        return !this.gameOver;
    }

    public City getCurrentCity() {
        return this.currentCity;
    }

    public boolean travelToNextCity() {
        City newCity = map.getNextCity(this.currentCity);
        if (newCity == null) {
            setGameOver();
            return false;
        }
        this.currentCity = newCity;
        return true;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    @Override
    public boolean fight(Trainer opponent) {
        return false;
    }

    public String getStatus() {
        if (!canPlay()) {
            return getName() + " lost the game" +
                   ((getCurrentCity() != null) ? " while in " + getCurrentCity().getName() : "") + ".";
        }
        return getName() + " is still in the game.";
    }
}
