Tudo Feito
This commit is contained in:
@@ -6,6 +6,7 @@ import java.io.*;
|
||||
|
||||
public class TIC_Projeto_Final {
|
||||
|
||||
// Jogador
|
||||
static String nome;
|
||||
static int vida = 100;
|
||||
static int fome = 100;
|
||||
@@ -15,16 +16,23 @@ public class TIC_Projeto_Final {
|
||||
static int nivel = 1;
|
||||
static int dias = 1;
|
||||
|
||||
// Inventário
|
||||
static int comida = 2;
|
||||
static int garrafas = 2;
|
||||
static int kits = 1;
|
||||
|
||||
// Armas
|
||||
static String arma = "Paus";
|
||||
static int danoArma = 10;
|
||||
|
||||
// Armadura
|
||||
static String armadura = "Nenhuma";
|
||||
static int defesa = 0;
|
||||
|
||||
static Scanner ler = new Scanner(System.in);
|
||||
static Random random = new Random();
|
||||
|
||||
// ===================== ESTADO =====================
|
||||
public static void estado() {
|
||||
System.out.println("\n===== ESTADO =====");
|
||||
System.out.println("Jogador: " + nome);
|
||||
@@ -36,13 +44,17 @@ public class TIC_Projeto_Final {
|
||||
System.out.println("Nível: " + nivel);
|
||||
System.out.println("Dias: " + dias);
|
||||
|
||||
System.out.println("\n===== EQUIPAMENTO =====");
|
||||
System.out.println("Arma: " + arma + " (Dano " + danoArma + ")");
|
||||
System.out.println("Armadura: " + armadura + " (Defesa " + defesa + ")");
|
||||
|
||||
System.out.println("\n===== INVENTÁRIO =====");
|
||||
System.out.println("Comida: " + comida);
|
||||
System.out.println("Água: " + garrafas);
|
||||
System.out.println("Kits: " + kits);
|
||||
System.out.println("Arma: " + arma);
|
||||
}
|
||||
|
||||
// ===================== XP =====================
|
||||
public static void ganharXP(int valor) {
|
||||
xp += valor;
|
||||
|
||||
@@ -53,6 +65,7 @@ public class TIC_Projeto_Final {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== TEMPO =====================
|
||||
public static void passarTempo() {
|
||||
dias++;
|
||||
fome -= 5;
|
||||
@@ -71,6 +84,7 @@ public class TIC_Projeto_Final {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== EVENTOS =====================
|
||||
public static void eventoAleatorio() {
|
||||
|
||||
int evento = random.nextInt(10);
|
||||
@@ -98,6 +112,7 @@ public class TIC_Projeto_Final {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== PROCURAR =====================
|
||||
public static void procurar() {
|
||||
|
||||
int sorte = random.nextInt(4);
|
||||
@@ -124,6 +139,7 @@ public class TIC_Projeto_Final {
|
||||
passarTempo();
|
||||
}
|
||||
|
||||
// ===================== LUTA =====================
|
||||
public static void lutar() {
|
||||
|
||||
String[] inimigos = {"Lobo", "Urso", "Javali"};
|
||||
@@ -136,7 +152,10 @@ public class TIC_Projeto_Final {
|
||||
while (vidaInimigo > 0 && vida > 0) {
|
||||
|
||||
int ataqueJogador = random.nextInt(10) + danoArma;
|
||||
|
||||
int danoInimigo = random.nextInt(10) + 5;
|
||||
danoInimigo -= defesa;
|
||||
if (danoInimigo < 0) danoInimigo = 0;
|
||||
|
||||
vidaInimigo -= ataqueJogador;
|
||||
vida -= danoInimigo;
|
||||
@@ -155,6 +174,7 @@ public class TIC_Projeto_Final {
|
||||
passarTempo();
|
||||
}
|
||||
|
||||
// ===================== CONSUMO =====================
|
||||
public static void comer() {
|
||||
if (comida > 0) {
|
||||
comida--;
|
||||
@@ -185,21 +205,30 @@ public class TIC_Projeto_Final {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== LOJA =====================
|
||||
public static void loja() {
|
||||
|
||||
System.out.println("\n===== LOJA =====");
|
||||
System.out.println("💰 Tens " + moedas + " moedas");
|
||||
System.out.println("\n===== LOJA =====");
|
||||
System.out.println("💰 Tens " + moedas + " moedas");
|
||||
System.out.println("🛡️ Armadura atual: " + armadura);
|
||||
|
||||
System.out.println("\n1 - Comida (5 moedas)");
|
||||
System.out.println("2 - Água (5 moedas)");
|
||||
System.out.println("3 - Kit (15 moedas)");
|
||||
System.out.println("4 - Faca (25 moedas)");
|
||||
System.out.println("5 - Espada (50 moedas)");
|
||||
System.out.println("\n1 - Comida (5 moedas)");
|
||||
System.out.println("2 - Água (5 moedas)");
|
||||
System.out.println("3 - Kit (15 moedas)");
|
||||
System.out.println("4 - Faca (25 moedas)");
|
||||
System.out.println("5 - Espada (50 moedas)");
|
||||
System.out.println("6 - Armadura de Couro (30 moedas)");
|
||||
System.out.println("7 - Armadura de Ferro (60 moedas)");
|
||||
System.out.println("0 - Não comprar nada");
|
||||
|
||||
int op = ler.nextInt();
|
||||
int op = ler.nextInt();
|
||||
|
||||
switch (op) {
|
||||
|
||||
case 0:
|
||||
System.out.println("👋 Saíste da loja sem comprar nada.");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (moedas >= 5) { moedas -= 5; comida++; }
|
||||
break;
|
||||
@@ -227,75 +256,28 @@ public class TIC_Projeto_Final {
|
||||
danoArma = 35;
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if (moedas >= 30) {
|
||||
moedas -= 30;
|
||||
armadura = "Couro";
|
||||
defesa = 3;
|
||||
System.out.println("🛡️ Compraste armadura de couro!");
|
||||
}
|
||||
break;
|
||||
|
||||
case 7:
|
||||
if (moedas >= 60) {
|
||||
moedas -= 60;
|
||||
armadura = "Ferro";
|
||||
defesa = 6;
|
||||
System.out.println("🛡️ Compraste armadura de ferro!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void guardar() {
|
||||
try {
|
||||
PrintWriter p = new PrintWriter(new FileWriter("save.txt"));
|
||||
|
||||
p.println(nome);
|
||||
p.println(vida);
|
||||
p.println(fome);
|
||||
p.println(agua);
|
||||
p.println(moedas);
|
||||
p.println(xp);
|
||||
p.println(nivel);
|
||||
p.println(dias);
|
||||
p.println(comida);
|
||||
p.println(garrafas);
|
||||
p.println(kits);
|
||||
p.println(arma);
|
||||
p.println(danoArma);
|
||||
|
||||
p.close();
|
||||
System.out.println("💾 Guardado!");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Erro ao guardar.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void carregar() {
|
||||
try {
|
||||
File f = new File("save.txt");
|
||||
if (!f.exists()) return;
|
||||
|
||||
Scanner s = new Scanner(f);
|
||||
|
||||
nome = s.nextLine();
|
||||
vida = Integer.parseInt(s.nextLine());
|
||||
fome = Integer.parseInt(s.nextLine());
|
||||
agua = Integer.parseInt(s.nextLine());
|
||||
moedas = Integer.parseInt(s.nextLine());
|
||||
xp = Integer.parseInt(s.nextLine());
|
||||
nivel = Integer.parseInt(s.nextLine());
|
||||
dias = Integer.parseInt(s.nextLine());
|
||||
comida = Integer.parseInt(s.nextLine());
|
||||
garrafas = Integer.parseInt(s.nextLine());
|
||||
kits = Integer.parseInt(s.nextLine());
|
||||
arma = s.nextLine();
|
||||
danoArma = Integer.parseInt(s.nextLine());
|
||||
|
||||
s.close();
|
||||
System.out.println("📂 Jogo carregado!");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Erro ao carregar.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void menu() {
|
||||
System.out.println("\n===== MENU =====");
|
||||
System.out.println("1 Procurar");
|
||||
System.out.println("2 Lutar");
|
||||
System.out.println("3 Comer");
|
||||
System.out.println("4 Beber");
|
||||
System.out.println("5 Kit");
|
||||
System.out.println("6 Loja");
|
||||
System.out.println("7 Estado");
|
||||
System.out.println("8 Guardar");
|
||||
System.out.println("9 Sair");
|
||||
}
|
||||
|
||||
// ===================== MAIN =====================
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("🏕️ JOGO DE SOBREVIVÊNCIA");
|
||||
@@ -308,7 +290,36 @@ public class TIC_Projeto_Final {
|
||||
System.out.println("2 - Carregar");
|
||||
|
||||
int op = ler.nextInt();
|
||||
if (op == 2) carregar();
|
||||
|
||||
if (op == 2) {
|
||||
try {
|
||||
File f = new File("save.txt");
|
||||
if (f.exists()) {
|
||||
Scanner s = new Scanner(f);
|
||||
|
||||
nome = s.nextLine();
|
||||
vida = Integer.parseInt(s.nextLine());
|
||||
fome = Integer.parseInt(s.nextLine());
|
||||
agua = Integer.parseInt(s.nextLine());
|
||||
moedas = Integer.parseInt(s.nextLine());
|
||||
xp = Integer.parseInt(s.nextLine());
|
||||
nivel = Integer.parseInt(s.nextLine());
|
||||
dias = Integer.parseInt(s.nextLine());
|
||||
comida = Integer.parseInt(s.nextLine());
|
||||
garrafas = Integer.parseInt(s.nextLine());
|
||||
kits = Integer.parseInt(s.nextLine());
|
||||
arma = s.nextLine();
|
||||
danoArma = Integer.parseInt(s.nextLine());
|
||||
armadura = s.nextLine();
|
||||
defesa = Integer.parseInt(s.nextLine());
|
||||
|
||||
s.close();
|
||||
System.out.println("📂 Jogo carregado!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Erro ao carregar.");
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -318,12 +329,20 @@ public class TIC_Projeto_Final {
|
||||
}
|
||||
|
||||
if (nivel >= 5) {
|
||||
System.out.println("🐉 BOSS FINAL!");
|
||||
System.out.println("Ganhaste o jogo!");
|
||||
System.out.println("🏆 CHEGASTE AO FINAL DO JOGO!");
|
||||
break;
|
||||
}
|
||||
|
||||
menu();
|
||||
System.out.println("\n1 Procurar");
|
||||
System.out.println("2 Lutar");
|
||||
System.out.println("3 Comer");
|
||||
System.out.println("4 Beber");
|
||||
System.out.println("5 Kit");
|
||||
System.out.println("6 Loja");
|
||||
System.out.println("7 Estado");
|
||||
System.out.println("8 Guardar");
|
||||
System.out.println("9 Sair");
|
||||
|
||||
int escolha = ler.nextInt();
|
||||
|
||||
switch (escolha) {
|
||||
@@ -334,7 +353,32 @@ public class TIC_Projeto_Final {
|
||||
case 5 -> usarKit();
|
||||
case 6 -> loja();
|
||||
case 7 -> estado();
|
||||
case 8 -> guardar();
|
||||
case 8 -> {
|
||||
try {
|
||||
PrintWriter p = new PrintWriter(new FileWriter("save.txt"));
|
||||
|
||||
p.println(nome);
|
||||
p.println(vida);
|
||||
p.println(fome);
|
||||
p.println(agua);
|
||||
p.println(moedas);
|
||||
p.println(xp);
|
||||
p.println(nivel);
|
||||
p.println(dias);
|
||||
p.println(comida);
|
||||
p.println(garrafas);
|
||||
p.println(kits);
|
||||
p.println(arma);
|
||||
p.println(danoArma);
|
||||
p.println(armadura);
|
||||
p.println(defesa);
|
||||
|
||||
p.close();
|
||||
System.out.println("💾 Guardado!");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Erro ao guardar.");
|
||||
}
|
||||
}
|
||||
case 9 -> { return; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user