-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
133 lines (119 loc) · 4.98 KB
/
Player.java
File metadata and controls
133 lines (119 loc) · 4.98 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
public class Player implements Serializable {
private static final long serialVersionUID = 1L;
public static String pokemonNome;
public static Pokemon pokemonSelecionado;
public static String nome;
public static String tipoPersonagem = "boy";
public static InterfaceCaixa painel;
public static Game frame;
public static boolean resultado;
public static int ataqueValue = 15;
public Player(String pokemon, Game frame) {
Player.pokemonNome = pokemon;
Player.frame = frame;
pokemonSelecionado = new Pokemon(pokemon, "back");
}
public String getPokemonNome(){
return pokemonNome;
}
public void setPokemonNome(String pokemonNome){
Player.pokemonNome = pokemonNome;
}
public static void setInterfaceCaixa(InterfaceCaixa painel) {
Player.painel = painel; // Adicione este método
}
public static void atacar() {
Enemy.inimigoAtual.setVida(Enemy.inimigoAtual.getVida() - ataqueValue);
System.out.println("O pokemon do player atacou o pokemon inimigo e causou " + ataqueValue + " de dano");
if (Enemy.inimigoAtual.getVida() <= 0) {
System.out.println("O pokemon inimigo foi derrotado");
painel.mostrarDerrotaInimigo();
Timer timer = new Timer(1000, e -> {
Enemy.trocarInimigo();
PokemonsBatle.instance.atualizarInimigo();
PokemonsBatle.instance.atualizarVidaInimigo();
pokemonSelecionado.evoluir(PokemonsBatle.playerLv, frame);
});
timer.setRepeats(false);
timer.start();
}
PokemonsBatle.instance.atualizarVidaInimigo();
}
public static void curar(String curaValor) {
pokemonSelecionado.setVida(pokemonSelecionado.getVida() + Integer.parseInt(curaValor));
if (pokemonSelecionado.getVida() > pokemonSelecionado.getVidaMaxima()) {
pokemonSelecionado.setVida(pokemonSelecionado.getVidaMaxima());
}
System.out.println("O pokemon do player foi curado e recuperou " + curaValor + " de vida");
PokemonsBatle.instance.atualizarVidaPlayer();
}
public static void salvarDados() {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("player_data.dat"))) {
oos.writeObject(pokemonNome);
oos.writeObject(pokemonSelecionado);
oos.writeObject(nome);
oos.writeObject(tipoPersonagem);
oos.writeObject(frame);
oos.writeObject(ataqueValue);
oos.writeObject(Enemy.inimigoAtual);
oos.writeObject(Enemy.inimigos);
oos.writeObject(PokemonsBatle.inimigoLv);
oos.writeObject(PokemonsBatle.playerLv);
System.out.println("Dados salvos com sucesso!");
} catch (IOException e) {
System.out.println("Erro ao salvar os dados: " + e.getMessage());
}
}
@SuppressWarnings("unchecked")
public static boolean carregarDados() {
File file = new File("player_data.dat");
if (!file.exists()) {
System.out.println("Nenhum save do jogo encontrado.");
return false;
}
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
pokemonNome = (String) ois.readObject();
pokemonSelecionado = (Pokemon) ois.readObject();
nome = (String) ois.readObject();
tipoPersonagem = (String) ois.readObject();
frame = (Game) ois.readObject();
ataqueValue = (int) ois.readObject();
Enemy.inimigoAtual = (Pokemon) ois.readObject();
Enemy.inimigos = (ArrayList<Pokemon>) ois.readObject();
PokemonsBatle.inimigoLv = (int) ois.readObject();
PokemonsBatle.playerLv = (int) ois.readObject();
System.out.println("Dados carregados com sucesso!");
return true;
} catch (IOException | ClassNotFoundException e) {
System.out.println("Erro ao carregar os dados: " + e.getMessage());
return false;
}
}
public static int getAlturaPokemon() {
switch (pokemonSelecionado.getNome()) {
case "Bulbasaur":
return 256;
case "Ivysaur":
return 232;
case "Venusaur":
return 232;
case "Squirtle":
return 252;
case "Wartortle":
return 232;
case "Blastoise":
return 232;
case "Charmander":
return 232;
case "Charmeleon":
return 220;
case "Charizard":
return 208;
default:
return 256;
}
}
}