package y3.players;
import java.util.List;
import y3.fight.Fight;
import y3.playground.Board;
import y3.playground.RedTile;
import y3.playground.Tile;
import y3.threadViz.ThreadViz;
/**
* V�luri klass.
* M�ngija abstraktse klassi Player alamklass.
*
* @author Jaak Laanpere
*
*/
public class Wizard extends Player {
/**
* Konstruktor.
*
* @param name
* @param board
*/
public Wizard(String name, Board board) {
super(name, board);
}
/**
* Punasele m�nguv�ljale sisenemise meetod.
* Kui punasel m�nguv�ljal on koletis, tahab koletis hakata v�luriga kaklema.
*/
@Override
public void enterRedTile(Tile t) {
List<Player> players = t.getPlayers();
if(players.isEmpty()){
ThreadViz.addMessage(this, " hyppab kannatamatult yhelt jalalt teisele.");
} else {
for(Player p : players){
if(!(p instanceof Monster)){
players.remove(p);
}
}
if (!players.isEmpty()) {
Player opponent = players.get(0);
Fight fight = new Fight(this, opponent, t);
}
}
}
/**
* Valgele m�nguv�ljale sisenemine.
* Harjutab v�lukunsti: kui ei ole k�es maksimaalne level, siis level t�useb.
*/
@Override
public void enterWhiteTile(Tile t) {
if (level < MAXLEVEL) {
levelUp();
ThreadViz.addMessage(this, "harjutas loitse, level n��d: " + this.getLevel());
} else {
ThreadViz.addMessage(this, "Maksimaalne tase saavutatud.");
}
}
/**
* Kontroll enne m�nguv�ljale sisenemist.
* Kui punasel v�ljal on koletisi rohkem kui inimesi, siis v�lur sinna siseneda ei taha.
*
*/
@Override
public boolean canEnter(Tile t) {
List<Player> players = t.getPlayers();
if (t instanceof RedTile) {
int monsterCount = 0;
int playerCount = players.size();
System.out.println("V�lur n�eb punasel: " + playerCount + " m�ngijat");
for (Player p : t.getPlayers()) {
if (p instanceof Monster) {
monsterCount++;
}
}
if (monsterCount > playerCount / 2) {
ThreadViz.addMessage(this, "ei taha kollidega �hineda, neid on liiga palju.");
return false;
}
}
return true;
}
}