Feito
This commit is contained in:
@@ -0,0 +1,382 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public class TIC_Projeto_Final {
|
||||||
|
|
||||||
|
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 comida = 2;
|
||||||
|
static int garrafas = 2;
|
||||||
|
static int kits = 1;
|
||||||
|
|
||||||
|
static Scanner ler = new Scanner(System.in);
|
||||||
|
static Random random = new Random();
|
||||||
|
|
||||||
|
public static void estado() {
|
||||||
|
|
||||||
|
System.out.println("\n===== ESTADO =====");
|
||||||
|
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("\n===== INVENTÁRIO =====");
|
||||||
|
System.out.println("Comida: " + comida);
|
||||||
|
System.out.println("Garrafas de Água: " + garrafas);
|
||||||
|
System.out.println("Kits Médicos: " + kits);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ganharXP(int valor) {
|
||||||
|
|
||||||
|
xp += valor;
|
||||||
|
|
||||||
|
if (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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void passarTempo() {
|
||||||
|
|
||||||
|
fome -= 5;
|
||||||
|
agua -= 5;
|
||||||
|
|
||||||
|
if (fome <= 0) {
|
||||||
|
fome = 0;
|
||||||
|
vida -= 10;
|
||||||
|
System.out.println("⚠️ Estás com fome!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (agua <= 0) {
|
||||||
|
agua = 0;
|
||||||
|
vida -= 10;
|
||||||
|
System.out.println("⚠️ Estás desidratado!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void guardarJogo() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
PrintWriter ficheiro = new PrintWriter(new FileWriter("save.txt"));
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
ficheiro.close();
|
||||||
|
|
||||||
|
System.out.println("💾 Jogo guardado com sucesso!");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
System.out.println("Erro ao guardar jogo.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void carregarJogo() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
File ficheiro = new File("save.txt");
|
||||||
|
|
||||||
|
if (!ficheiro.exists()) {
|
||||||
|
System.out.println("⚠️ Não existe jogo guardado.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scanner leitor = new Scanner(ficheiro);
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
leitor.close();
|
||||||
|
|
||||||
|
System.out.println("📂 Jogo carregado com sucesso!");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
System.out.println("Erro ao carregar jogo.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
int inicio = ler.nextInt();
|
||||||
|
|
||||||
|
if (inicio == 2) {
|
||||||
|
carregarJogo();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
if (vida <= 0) {
|
||||||
|
System.out.println("\n💀 Morreste!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nivel >= 5) {
|
||||||
|
System.out.println("\n🏆 Parabéns! Chegaste ao nível máximo!");
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user