Skip to content

Instantly share code, notes, and snippets.

public static void delay(int milliseconds){
try{
Thread.sleep(milliseconds);
}catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// Função para limpar o console e reposicionar o cursor
public static void clearConsole() {
System.out.print("\033[H\033[2J");
System.out.flush();
}
@EcthorSilva
EcthorSilva / atacar.java
Created March 22, 2023 17:28
Método para gerar o dano do personagem
public int atacar() {
Random rand = new Random();
int min = getForca() / 2;
int max = getForca() + getDefesa();
int dano = rand.nextInt(max - min + 1) + min;
System.out.println(getNome() + " atacou com sua espada e causou " + dano + " de dano!");
return dano;
}
@EcthorSilva
EcthorSilva / gerarMonstroAleatorio.java
Last active March 22, 2023 17:31
Função para criar monstros aleatórios
// Gerador de monstros aleatorios
public static Monstro gerarMonstroAleatorio() {
Random rand = new Random();
String[] nomes = { "Esqueleto", "Orc", "Troll", "Goblin", "Dragão" };
int vida = rand.nextInt(100) + 100; // Vida do Monstro
int ataque = rand.nextInt(20) + 20; // Ataque do Monstro
int defesa = rand.nextInt(20) + 20; // Defesa do Monstro
return new Monstro(nomes[rand.nextInt(nomes.length)], vida, ataque, defesa);
}