-2
I wanted to understand the method get()
, how it works and what is it serving in this code (preferably wanted an explanation of imaginary form without technical names).
package exemplo_oo;
public class Game {
private Player player;
private Inimigo inimigo;
public Game() {
player = new Player();
inimigo = new Inimigo();
}
public Player getPlayer() {
return player;
}
public Inimigo getInimigo() {
return inimigo;
}
public static void main(String[] args) {
Game game = new Game();
Player player = game.getPlayer();
player.atacarInimigo(game.getInimigo());
System.out.println(game.getInimigo().life);
}
}
package exemplo_oo;
public class Player {
private int life = 100;
public void atacarInimigo(Inimigo inimigo) {
inimigo.life--;
}
}
package exemplo_oo;
public class Inimigo {
public int life = 5;
}