TUdo Feito
This commit is contained in:
@@ -1,223 +1,66 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.mycompany.tic_projeto_final;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 250408
|
||||
*/
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.*;
|
||||
|
||||
public class TIC_Projeto_Final {
|
||||
|
||||
// Jogador
|
||||
static String nome;
|
||||
static int vida = 100;
|
||||
static int fome = 100;
|
||||
static int agua = 100;
|
||||
static int moedas = 10;
|
||||
static int xp = 0;
|
||||
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;
|
||||
|
||||
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);
|
||||
System.out.println("Vida: " + vida);
|
||||
System.out.println("Fome: " + fome);
|
||||
System.out.println("Água: " + agua);
|
||||
System.out.println("Moedas: " + moedas);
|
||||
System.out.println("XP: " + xp);
|
||||
System.out.println("Nível: " + nivel);
|
||||
System.out.println("Dias: " + dias);
|
||||
|
||||
System.out.println("\n===== INVENTÁRIO =====");
|
||||
System.out.println("Comida: " + comida);
|
||||
System.out.println("Garrafas de Água: " + garrafas);
|
||||
System.out.println("Kits Médicos: " + kits);
|
||||
System.out.println("Água: " + garrafas);
|
||||
System.out.println("Kits: " + kits);
|
||||
System.out.println("Arma: " + arma);
|
||||
}
|
||||
|
||||
// ===================== XP =====================
|
||||
public static void ganharXP(int valor) {
|
||||
|
||||
xp += valor;
|
||||
|
||||
if (xp >= nivel * 100) {
|
||||
while (xp >= nivel * 100) {
|
||||
xp -= nivel * 100;
|
||||
nivel++;
|
||||
System.out.println("\n⭐ Parabéns! Subiste para o nível " + nivel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void procurar() {
|
||||
|
||||
int sorte = random.nextInt(4) + 1;
|
||||
|
||||
if (sorte == 1) {
|
||||
comida++;
|
||||
System.out.println("🍎 Encontraste comida!");
|
||||
} else if (sorte == 2) {
|
||||
garrafas++;
|
||||
System.out.println("💧 Encontraste água!");
|
||||
} else if (sorte == 3) {
|
||||
moedas += 5;
|
||||
System.out.println("💰 Encontraste 5 moedas!");
|
||||
} else {
|
||||
System.out.println("😔 Não encontraste nada.");
|
||||
}
|
||||
|
||||
ganharXP(10);
|
||||
passarTempo();
|
||||
}
|
||||
|
||||
public static void lutar() {
|
||||
|
||||
String[] inimigos = {"Lobo", "Urso", "Javali"};
|
||||
|
||||
String inimigo = inimigos[random.nextInt(3)];
|
||||
|
||||
System.out.println("\n🐺 Encontraste um " + inimigo);
|
||||
|
||||
int ataqueJogador = random.nextInt(16) + 15;
|
||||
|
||||
if (ataqueJogador >= 20) {
|
||||
|
||||
int recompensa = random.nextInt(11) + 5;
|
||||
|
||||
moedas += recompensa;
|
||||
|
||||
System.out.println("🏆 Venceste a luta!");
|
||||
System.out.println("💰 Ganhaste " + recompensa + " moedas!");
|
||||
|
||||
ganharXP(25);
|
||||
|
||||
} else {
|
||||
|
||||
int dano = random.nextInt(16) + 5;
|
||||
|
||||
vida -= dano;
|
||||
|
||||
System.out.println("💥 Sofreste " + dano + " de dano!");
|
||||
}
|
||||
|
||||
passarTempo();
|
||||
}
|
||||
|
||||
public static void comer() {
|
||||
|
||||
if (comida > 0) {
|
||||
|
||||
comida--;
|
||||
fome += 25;
|
||||
|
||||
if (fome > 100) {
|
||||
fome = 100;
|
||||
}
|
||||
|
||||
System.out.println("🍔 Comeste.");
|
||||
|
||||
} else {
|
||||
System.out.println("❌ Não tens comida.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void beber() {
|
||||
|
||||
if (garrafas > 0) {
|
||||
|
||||
garrafas--;
|
||||
agua += 25;
|
||||
|
||||
if (agua > 100) {
|
||||
agua = 100;
|
||||
}
|
||||
|
||||
System.out.println("🥤 Bebeste água.");
|
||||
|
||||
} else {
|
||||
System.out.println("❌ Não tens água.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void usarKit() {
|
||||
|
||||
if (kits > 0) {
|
||||
|
||||
kits--;
|
||||
vida += 30;
|
||||
|
||||
if (vida > 100) {
|
||||
vida = 100;
|
||||
}
|
||||
|
||||
System.out.println("🩹 Usaste um kit médico.");
|
||||
|
||||
} else {
|
||||
System.out.println("❌ Não tens kits médicos.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void loja() {
|
||||
|
||||
System.out.println("\n===== LOJA =====");
|
||||
System.out.println("1 - Comprar comida (5 moedas)");
|
||||
System.out.println("2 - Comprar água (5 moedas)");
|
||||
System.out.println("3 - Comprar kit médico (15 moedas)");
|
||||
|
||||
int op = ler.nextInt();
|
||||
|
||||
switch (op) {
|
||||
|
||||
case 1:
|
||||
|
||||
if (moedas >= 5) {
|
||||
moedas -= 5;
|
||||
comida++;
|
||||
System.out.println("🍎 Compraste comida.");
|
||||
} else {
|
||||
System.out.println("❌ Moedas insuficientes.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if (moedas >= 5) {
|
||||
moedas -= 5;
|
||||
garrafas++;
|
||||
System.out.println("💧 Compraste água.");
|
||||
} else {
|
||||
System.out.println("❌ Moedas insuficientes.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
if (moedas >= 15) {
|
||||
moedas -= 15;
|
||||
kits++;
|
||||
System.out.println("🩹 Compraste um kit médico.");
|
||||
} else {
|
||||
System.out.println("❌ Moedas insuficientes.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Opção inválida.");
|
||||
System.out.println("\n⭐ Subiste para o nível " + nivel);
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== TEMPO =====================
|
||||
public static void passarTempo() {
|
||||
|
||||
dias++;
|
||||
fome -= 5;
|
||||
agua -= 5;
|
||||
|
||||
@@ -234,148 +77,280 @@ public class TIC_Projeto_Final {
|
||||
}
|
||||
}
|
||||
|
||||
public static void guardarJogo() {
|
||||
// ===================== EVENTOS =====================
|
||||
public static void eventoAleatorio() {
|
||||
|
||||
try {
|
||||
int evento = random.nextInt(10);
|
||||
|
||||
PrintWriter ficheiro = new PrintWriter(new FileWriter("save.txt"));
|
||||
switch (evento) {
|
||||
case 0:
|
||||
vida -= 10;
|
||||
System.out.println("🐍 Cobra atacou-te!");
|
||||
break;
|
||||
|
||||
ficheiro.println(vida);
|
||||
ficheiro.println(fome);
|
||||
ficheiro.println(agua);
|
||||
ficheiro.println(moedas);
|
||||
ficheiro.println(xp);
|
||||
ficheiro.println(nivel);
|
||||
ficheiro.println(comida);
|
||||
ficheiro.println(garrafas);
|
||||
ficheiro.println(kits);
|
||||
case 1:
|
||||
moedas += 10;
|
||||
System.out.println("💰 Encontraste tesouro!");
|
||||
break;
|
||||
|
||||
ficheiro.close();
|
||||
case 2:
|
||||
kits++;
|
||||
System.out.println("🩹 Encontraste kit médico!");
|
||||
break;
|
||||
|
||||
System.out.println("💾 Jogo guardado com sucesso!");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.println("Erro ao guardar jogo.");
|
||||
case 3:
|
||||
agua += 10;
|
||||
System.out.println("🌧️ Chuva aumentou a água!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void carregarJogo() {
|
||||
// ===================== PROCURAR =====================
|
||||
public static void procurar() {
|
||||
|
||||
try {
|
||||
int sorte = random.nextInt(4);
|
||||
|
||||
File ficheiro = new File("save.txt");
|
||||
switch (sorte) {
|
||||
case 0:
|
||||
comida++;
|
||||
System.out.println("🍎 Encontraste comida!");
|
||||
break;
|
||||
case 1:
|
||||
garrafas++;
|
||||
System.out.println("💧 Encontraste água!");
|
||||
break;
|
||||
case 2:
|
||||
moedas += 5;
|
||||
System.out.println("💰 Encontraste moedas!");
|
||||
break;
|
||||
default:
|
||||
System.out.println("😔 Não encontraste nada.");
|
||||
}
|
||||
|
||||
if (!ficheiro.exists()) {
|
||||
System.out.println("⚠️ Não existe jogo guardado.");
|
||||
return;
|
||||
}
|
||||
eventoAleatorio();
|
||||
ganharXP(10);
|
||||
passarTempo();
|
||||
}
|
||||
|
||||
Scanner leitor = new Scanner(ficheiro);
|
||||
// ===================== LUTA =====================
|
||||
public static void lutar() {
|
||||
|
||||
vida = Integer.parseInt(leitor.nextLine());
|
||||
fome = Integer.parseInt(leitor.nextLine());
|
||||
agua = Integer.parseInt(leitor.nextLine());
|
||||
moedas = Integer.parseInt(leitor.nextLine());
|
||||
xp = Integer.parseInt(leitor.nextLine());
|
||||
nivel = Integer.parseInt(leitor.nextLine());
|
||||
comida = Integer.parseInt(leitor.nextLine());
|
||||
garrafas = Integer.parseInt(leitor.nextLine());
|
||||
kits = Integer.parseInt(leitor.nextLine());
|
||||
String[] inimigos = {"Lobo", "Urso", "Javali"};
|
||||
String inimigo = inimigos[random.nextInt(inimigos.length)];
|
||||
|
||||
leitor.close();
|
||||
System.out.println("\n🐺 Encontraste um " + inimigo);
|
||||
|
||||
System.out.println("📂 Jogo carregado com sucesso!");
|
||||
int vidaInimigo = 40 + random.nextInt(30);
|
||||
|
||||
} catch (Exception e) {
|
||||
while (vidaInimigo > 0 && vida > 0) {
|
||||
|
||||
System.out.println("Erro ao carregar jogo.");
|
||||
int ataqueJogador = random.nextInt(10) + danoArma;
|
||||
int danoInimigo = random.nextInt(10) + 5;
|
||||
|
||||
vidaInimigo -= ataqueJogador;
|
||||
vida -= danoInimigo;
|
||||
|
||||
System.out.println("Tu atacaste: -" + ataqueJogador);
|
||||
System.out.println("Inimigo atacou: -" + danoInimigo);
|
||||
}
|
||||
|
||||
if (vida > 0) {
|
||||
int recompensa = random.nextInt(10) + 5;
|
||||
moedas += recompensa;
|
||||
System.out.println("🏆 Venceste! +" + recompensa + " moedas");
|
||||
ganharXP(25);
|
||||
}
|
||||
|
||||
passarTempo();
|
||||
}
|
||||
|
||||
// ===================== CONSUMO =====================
|
||||
public static void comer() {
|
||||
if (comida > 0) {
|
||||
comida--;
|
||||
fome = Math.min(100, fome + 25);
|
||||
System.out.println("🍔 Comeste.");
|
||||
} else {
|
||||
System.out.println("❌ Sem comida.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void beber() {
|
||||
if (garrafas > 0) {
|
||||
garrafas--;
|
||||
agua = Math.min(100, agua + 25);
|
||||
System.out.println("🥤 Bebeste água.");
|
||||
} else {
|
||||
System.out.println("❌ Sem água.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void usarKit() {
|
||||
if (kits > 0) {
|
||||
kits--;
|
||||
vida = Math.min(100, vida + 30);
|
||||
System.out.println("🩹 Usaste kit.");
|
||||
} else {
|
||||
System.out.println("❌ Sem kits.");
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== LOJA =====================
|
||||
public static void loja() {
|
||||
|
||||
System.out.println("\n===== LOJA =====");
|
||||
System.out.println("💰 Tens " + moedas + " 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)");
|
||||
|
||||
int op = ler.nextInt();
|
||||
|
||||
switch (op) {
|
||||
|
||||
case 1:
|
||||
if (moedas >= 5) { moedas -= 5; comida++; }
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (moedas >= 5) { moedas -= 5; garrafas++; }
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (moedas >= 15) { moedas -= 15; kits++; }
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (moedas >= 25) {
|
||||
moedas -= 25;
|
||||
arma = "Faca";
|
||||
danoArma = 20;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (moedas >= 50) {
|
||||
moedas -= 50;
|
||||
arma = "Espada";
|
||||
danoArma = 35;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== SAVE =====================
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== LOAD =====================
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== MENU =====================
|
||||
public static void menu() {
|
||||
|
||||
System.out.println("\n===== SOBREVIVÊNCIA =====");
|
||||
System.out.println("1 - Procurar recursos");
|
||||
System.out.println("2 - Lutar");
|
||||
System.out.println("3 - Comer");
|
||||
System.out.println("4 - Beber");
|
||||
System.out.println("5 - Usar kit médico");
|
||||
System.out.println("6 - Loja");
|
||||
System.out.println("7 - Ver estado");
|
||||
System.out.println("8 - Guardar jogo");
|
||||
System.out.println("9 - Sair");
|
||||
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");
|
||||
|
||||
System.out.println("\n1 - Novo Jogo");
|
||||
System.out.println("2 - Continuar Jogo");
|
||||
System.out.print("Nome do jogador: ");
|
||||
ler.nextLine();
|
||||
nome = ler.nextLine();
|
||||
|
||||
int inicio = ler.nextInt();
|
||||
System.out.println("1 - Novo jogo");
|
||||
System.out.println("2 - Carregar");
|
||||
|
||||
if (inicio == 2) {
|
||||
carregarJogo();
|
||||
}
|
||||
int op = ler.nextInt();
|
||||
if (op == 2) carregar();
|
||||
|
||||
while (true) {
|
||||
|
||||
if (vida <= 0) {
|
||||
System.out.println("\n💀 Morreste!");
|
||||
System.out.println("💀 Morreste!");
|
||||
break;
|
||||
}
|
||||
|
||||
if (nivel >= 5) {
|
||||
System.out.println("\n🏆 Parabéns! Chegaste ao nível máximo!");
|
||||
System.out.println("🐉 BOSS FINAL!");
|
||||
System.out.println("Ganhaste o jogo!");
|
||||
break;
|
||||
}
|
||||
|
||||
menu();
|
||||
|
||||
int escolha = ler.nextInt();
|
||||
|
||||
switch (escolha) {
|
||||
|
||||
case 1:
|
||||
procurar();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
lutar();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
comer();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
beber();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
usarKit();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
loja();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
estado();
|
||||
break;
|
||||
|
||||
case 8:
|
||||
guardarJogo();
|
||||
break;
|
||||
|
||||
case 9:
|
||||
System.out.println("👋 Até à próxima!");
|
||||
return;
|
||||
|
||||
default:
|
||||
System.out.println("❌ Opção inválida.");
|
||||
case 1 -> procurar();
|
||||
case 2 -> lutar();
|
||||
case 3 -> comer();
|
||||
case 4 -> beber();
|
||||
case 5 -> usarKit();
|
||||
case 6 -> loja();
|
||||
case 7 -> estado();
|
||||
case 8 -> guardar();
|
||||
case 9 -> { return; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user