-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.java
114 lines (95 loc) · 3.81 KB
/
Enemy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.*;
public class Enemy {
public static ArrayList<Pokemon> inimigos = new ArrayList<>();
public static Pokemon inimigoAtual;
public static InterfaceCaixa painel;
public static Game frame;
private static int numeroDeInimigo;
public Enemy() {
geraInimigos();
inimigoAtual = getInimigo(0);
}
public static void setInterfaceCaixa(InterfaceCaixa painel) {
Enemy.painel = painel; // Adicione este método
}
public static void setGameFrame(Game frame) {
Enemy.frame = frame;
}
public static Pokemon getInimigo(int i) {
return inimigos.get(i);
}
private void geraInimigos() {
ArrayList<String> tempArray = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader("pokemonhp.csv"))) {
String line = "";
// Ignorando o inicio do arquivo CSV
for(int i = 0; i < 10; i++) {
br.readLine();
}
while ((line = br.readLine()) != null) {
String[] pokemonInfo = line.split(",");
String nomePokemon = pokemonInfo[0];
tempArray.add(nomePokemon);
}
} catch (IOException e) {
e.printStackTrace();
}
String[] nomesPokemons = tempArray.toArray(new String[0]);
numeroDeInimigo = nomesPokemons.length;
// System.out.println("array original");
// for (String string : nomesPokemons) {
// System.out.println(string);
// }
// embaralha os nomes dos inimigos garantinto que sejam sempre diferentes
for(int i = 0; i < nomesPokemons.length; i++) {
int randomIndex = (int) (Math.random() * nomesPokemons.length);
String temp = nomesPokemons[i];
nomesPokemons[i] = nomesPokemons[randomIndex];
nomesPokemons[randomIndex] = temp;
}
// System.out.println("\narray embaralhado");
// for (String string : nomesPokemons) {
// System.out.println(string);
// }
for (int i = 0; i < nomesPokemons.length; i++) {
Pokemon pokemon = new Pokemon(nomesPokemons[i], "front");
inimigos.add(pokemon);
}
}
public static void atacar() {
Player.pokemonSelecionado.setVida(Player.pokemonSelecionado.getVida() - 10);
System.out.println("O pokemon inimigo atacou o " + Player.pokemonSelecionado.getNome() + " e causou 10 de dano");
if(Player.pokemonSelecionado.getVida() <= 0) {
System.out.println("O pokemon do player foi derrotado");
painel.mostrarDerrotaPlayer();
Timer timer = new Timer(1000, e -> {
try {
PokemonsBatle.instance.atualizarVidaPlayer();
Player.resultado = false;
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Final finalPanel = new Final();
frame.mudarTela(finalPanel);
});
timer.setRepeats(false);
timer.start();
}
PokemonsBatle.instance.atualizarVidaPlayer();
}
public static void trocarInimigo() {
for(int i = 0; i < numeroDeInimigo - 1; i++) {
if(inimigoAtual == getInimigo(i)) {
inimigoAtual = getInimigo(i + 1);
System.out.println("inimigo trocado");
return;
}
}
System.out.println("Todos os inimigos foram derrotados");
}
}