Quase tudo comleto!!
This commit is contained in:
@@ -66,10 +66,11 @@ public class Mavenproject4 {
|
|||||||
System.out.println("║ 1 ➜ Depositar ║");
|
System.out.println("║ 1 ➜ Depositar ║");
|
||||||
System.out.println("║ 2 ➜ Ver Saldo ║");
|
System.out.println("║ 2 ➜ Ver Saldo ║");
|
||||||
System.out.println("║ 3 ➜ Menu de Jogos ║");
|
System.out.println("║ 3 ➜ Menu de Jogos ║");
|
||||||
System.out.println("║ 4 ➜ Logout ║");
|
System.out.println("║ 4 ➜ Sacar Dinheiro ║");
|
||||||
|
System.out.println("║ 5 ➜ Logout ║");
|
||||||
|
|
||||||
if (admin) {
|
if (admin) {
|
||||||
System.out.println("║ 5 ➜ Ver Utilizadores ║");
|
System.out.println("║ 6 ➜ Painel Admin ║");
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("╚════════════════════════════════════╝");
|
System.out.println("╚════════════════════════════════════╝");
|
||||||
@@ -86,30 +87,25 @@ public class Mavenproject4 {
|
|||||||
int deposito = scanner.nextInt();
|
int deposito = scanner.nextInt();
|
||||||
|
|
||||||
if (deposito > 100000) {
|
if (deposito > 100000) {
|
||||||
|
System.out.println("Não podes depositar mais de 100.000€!");
|
||||||
System.out.println("Não podes depositar mais de 100.000€! Aposto que não tens metade...");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deposito <= 0) {
|
if (deposito <= 0) {
|
||||||
|
|
||||||
System.out.println("Valor inválido!");
|
System.out.println("Valor inválido!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
saldoAtual += deposito;
|
saldoAtual += deposito;
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
atualizarSaldo("utilizadores.txt");
|
||||||
|
|
||||||
System.out.println("Novo saldo: " + saldoAtual);
|
System.out.println("Novo saldo: " + saldoAtual);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// VER SALDO
|
// VER SALDO
|
||||||
case 2:
|
case 2:
|
||||||
|
|
||||||
System.out.println("Seu saldo é: " + saldoAtual);
|
System.out.println("Seu saldo é: " + saldoAtual);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// MENU DE JOGOS
|
// MENU DE JOGOS
|
||||||
@@ -132,200 +128,50 @@ public class Mavenproject4 {
|
|||||||
|
|
||||||
switch (opcao) {
|
switch (opcao) {
|
||||||
|
|
||||||
// GOLDEN NUMBER
|
|
||||||
case 1:
|
|
||||||
|
|
||||||
System.out.println("|==========| Golden Number |==========|");
|
|
||||||
|
|
||||||
System.out.println("Quanto desejas apostar?");
|
|
||||||
int dinheiroApostado = scanner.nextInt();
|
|
||||||
|
|
||||||
if (dinheiroApostado > saldoAtual) {
|
|
||||||
|
|
||||||
System.out.println("Saldo insuficiente!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Introduza um número de 1 a 9");
|
|
||||||
int numeroEscolhido = scanner.nextInt();
|
|
||||||
|
|
||||||
saldoAtual -= dinheiroApostado;
|
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
|
||||||
|
|
||||||
int numeroRandom = random.nextInt(9) + 1;
|
|
||||||
|
|
||||||
System.out.println("O número aleatório foi: " + numeroRandom);
|
|
||||||
|
|
||||||
if (numeroEscolhido == numeroRandom) {
|
|
||||||
|
|
||||||
int premio = dinheiroApostado * 2;
|
|
||||||
|
|
||||||
saldoAtual += premio;
|
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
|
||||||
|
|
||||||
System.out.println("GANHASTE!");
|
|
||||||
System.out.println("Recebeste: " + premio);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
System.out.println("Perdeste...");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Saldo atual: " + saldoAtual);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
// SLOT MACHINE
|
|
||||||
case 2:
|
|
||||||
|
|
||||||
System.out.println("|==========| Slot Machine |==========|");
|
|
||||||
System.out.println("Regras:");
|
|
||||||
System.out.println("🍒 🍒 🍒 = x5");
|
|
||||||
System.out.println("💎 💎 💎 = x50");
|
|
||||||
System.out.println("🎰 🎰 🎰 = x1000");
|
|
||||||
|
|
||||||
System.out.print("Valor a apostar: ");
|
|
||||||
int dinheiroApostado2 = scanner.nextInt();
|
|
||||||
|
|
||||||
if (dinheiroApostado2 > saldoAtual) {
|
|
||||||
|
|
||||||
System.out.println("Saldo insuficiente!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
saldoAtual -= dinheiroApostado2;
|
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
|
||||||
|
|
||||||
String[] simbolos = {"🍒", "💎", "🎰"};
|
|
||||||
|
|
||||||
String s1 = simbolos[random.nextInt(simbolos.length)];
|
|
||||||
String s2 = simbolos[random.nextInt(simbolos.length)];
|
|
||||||
String s3 = simbolos[random.nextInt(simbolos.length)];
|
|
||||||
|
|
||||||
System.out.println("\nA rodar...");
|
|
||||||
System.out.println("| " + s1 + " | " + s2 + " | " + s3 + " |");
|
|
||||||
|
|
||||||
if (s1.equals("🍒") && s2.equals("🍒") && s3.equals("🍒")) {
|
|
||||||
|
|
||||||
int premio = dinheiroApostado2 * 5;
|
|
||||||
saldoAtual += premio;
|
|
||||||
|
|
||||||
System.out.println("🍒🍒🍒 GANHASTE x5!");
|
|
||||||
System.out.println("Prémio: " + premio);
|
|
||||||
|
|
||||||
} else if (s1.equals("💎") && s2.equals("💎") && s3.equals("💎")) {
|
|
||||||
|
|
||||||
int premio = dinheiroApostado2 * 50;
|
|
||||||
saldoAtual += premio;
|
|
||||||
|
|
||||||
System.out.println("💎💎💎 MEGA WIN x50!");
|
|
||||||
System.out.println("Prémio: " + premio);
|
|
||||||
|
|
||||||
} else if (s1.equals("🎰") && s2.equals("🎰") && s3.equals("🎰")) {
|
|
||||||
|
|
||||||
int premio = dinheiroApostado2 * 1000;
|
|
||||||
saldoAtual += premio;
|
|
||||||
|
|
||||||
System.out.println("🎰 JACKPOT x1000 🎰");
|
|
||||||
System.out.println("Prémio: " + premio);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
System.out.println("Perdeste!");
|
|
||||||
}
|
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
|
||||||
|
|
||||||
System.out.println("Saldo atual: " + saldoAtual);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
// PAR OU ÍMPAR
|
|
||||||
case 3:
|
|
||||||
|
|
||||||
System.out.println("|==========| Par ou Ímpar |==========|");
|
|
||||||
|
|
||||||
System.out.println("Quanto desejas apostar?");
|
|
||||||
int dinheiroApostado3 = scanner.nextInt();
|
|
||||||
|
|
||||||
if (dinheiroApostado3 > saldoAtual) {
|
|
||||||
|
|
||||||
System.out.println("Saldo insuficiente!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("1 - Par");
|
|
||||||
System.out.println("2 - Ímpar");
|
|
||||||
|
|
||||||
int escolha = scanner.nextInt();
|
|
||||||
|
|
||||||
if (escolha != 1 && escolha != 2) {
|
|
||||||
|
|
||||||
System.out.println("Opção inválida!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
saldoAtual -= dinheiroApostado3;
|
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
|
||||||
|
|
||||||
int numero = random.nextInt(100) + 1;
|
|
||||||
|
|
||||||
System.out.println("Número sorteado: " + numero);
|
|
||||||
|
|
||||||
boolean numeroPar = numero % 2 == 0;
|
|
||||||
|
|
||||||
if ((numeroPar && escolha == 1)
|
|
||||||
|| (!numeroPar && escolha == 2)) {
|
|
||||||
|
|
||||||
int premio = dinheiroApostado3 * 2;
|
|
||||||
|
|
||||||
saldoAtual += premio;
|
|
||||||
|
|
||||||
atualizarSaldo("utilizadores.txt");
|
|
||||||
|
|
||||||
System.out.println("GANHASTE!");
|
|
||||||
System.out.println("Recebeste: " + premio);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
System.out.println("Perdeste!");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Saldo atual: " + saldoAtual);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
// VOLTAR
|
|
||||||
case 4:
|
case 4:
|
||||||
|
|
||||||
System.out.println("A voltar ao Menu Utilizador...");
|
System.out.println("A voltar ao Menu Utilizador...");
|
||||||
break menuJogos;
|
break menuJogos;
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
System.out.println("Opção inválida");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// LOGOUT
|
// SACAR DINHEIRO
|
||||||
case 4:
|
case 4:
|
||||||
|
|
||||||
|
System.out.print("Valor a sacar: ");
|
||||||
|
int saque = scanner.nextInt();
|
||||||
|
|
||||||
|
if (saque <= 0) {
|
||||||
|
System.out.println("Valor inválido!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saque > saldoAtual) {
|
||||||
|
System.out.println("Não tens saldo suficiente!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
saldoAtual -= saque;
|
||||||
|
atualizarSaldo("utilizadores.txt");
|
||||||
|
|
||||||
|
System.out.println("Saque efetuado com sucesso!");
|
||||||
|
System.out.println("Saldo atual: " + saldoAtual);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// LOGOUT
|
||||||
|
case 5:
|
||||||
|
|
||||||
System.out.println("Logout...");
|
System.out.println("Logout...");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// PAINEL ADMIN
|
// ADMIN
|
||||||
case 5:
|
case 6:
|
||||||
|
|
||||||
if (admin) {
|
if (admin) {
|
||||||
|
|
||||||
System.out.println("\n╔════════════════════════════════════╗");
|
System.out.println("\n╔════════════════════════════════════╗");
|
||||||
System.out.println("║ TODOS UTILIZADORES ║");
|
System.out.println("║ PAINEL DE ADMIN ║");
|
||||||
System.out.println("╚════════════════════════════════════╝");
|
System.out.println("╚════════════════════════════════════╝");
|
||||||
|
|
||||||
String[] dados = lerFicheiro("utilizadores.txt");
|
String[] dados = lerFicheiro("utilizadores.txt");
|
||||||
@@ -336,31 +182,28 @@ public class Mavenproject4 {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
||||||
System.out.println("Utilizador: " + dados[i]);
|
System.out.println("Utilizador: " + dados[i]);
|
||||||
System.out.println("Senha: " + dados[i + 1]);
|
System.out.println("Senha: " + dados[i + 1]);
|
||||||
System.out.println("Saldo: " + dados[i + 2]);
|
System.out.println("Saldo: " + dados[i + 2]);
|
||||||
|
System.out.println("-------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
System.out.println("Acesso negado.");
|
System.out.println("Acesso negado.");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
System.out.println("Opção inválida");
|
System.out.println("Opção inválida");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op == 4) {
|
if (op == 5) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
System.out.println("Nome ou senha incorretos.");
|
System.out.println("Nome ou senha incorretos.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,12 +211,10 @@ public class Mavenproject4 {
|
|||||||
|
|
||||||
// SAIR
|
// SAIR
|
||||||
case 3:
|
case 3:
|
||||||
|
|
||||||
System.out.println("Adeus!");
|
System.out.println("Adeus!");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
System.out.println("Opção inválida");
|
System.out.println("Opção inválida");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,22 +224,15 @@ public class Mavenproject4 {
|
|||||||
private static void escreverNoFicheiro(String email, String senha, String saldo, String nomeFicheiro) {
|
private static void escreverNoFicheiro(String email, String senha, String saldo, String nomeFicheiro) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(nomeFicheiro, true));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(nomeFicheiro, true));
|
||||||
|
|
||||||
bw.write(email);
|
bw.write(email);
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
|
|
||||||
bw.write(senha);
|
bw.write(senha);
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
|
|
||||||
bw.write(saldo);
|
bw.write(saldo);
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
|
|
||||||
bw.close();
|
bw.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
System.out.println("Erro ao escrever.");
|
System.out.println("Erro ao escrever.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,7 +241,6 @@ public class Mavenproject4 {
|
|||||||
private static String[] lerFicheiro(String nomeFicheiro) {
|
private static String[] lerFicheiro(String nomeFicheiro) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
File ficheiro = new File(nomeFicheiro);
|
File ficheiro = new File(nomeFicheiro);
|
||||||
|
|
||||||
if (!ficheiro.exists()) {
|
if (!ficheiro.exists()) {
|
||||||
@@ -415,7 +248,6 @@ public class Mavenproject4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Scanner leitor = new Scanner(ficheiro);
|
Scanner leitor = new Scanner(ficheiro);
|
||||||
|
|
||||||
String conteudo = "";
|
String conteudo = "";
|
||||||
|
|
||||||
while (leitor.hasNextLine()) {
|
while (leitor.hasNextLine()) {
|
||||||
@@ -427,7 +259,6 @@ public class Mavenproject4 {
|
|||||||
return conteudo.split("\n");
|
return conteudo.split("\n");
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
System.out.println("Erro ao ler ficheiro.");
|
System.out.println("Erro ao ler ficheiro.");
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
@@ -437,7 +268,6 @@ public class Mavenproject4 {
|
|||||||
private static boolean verificarLogin(String email, String senha, String nomeFicheiro) {
|
private static boolean verificarLogin(String email, String senha, String nomeFicheiro) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String[] dados = lerFicheiro(nomeFicheiro);
|
String[] dados = lerFicheiro(nomeFicheiro);
|
||||||
|
|
||||||
for (int i = 0; i < dados.length; i += 3) {
|
for (int i = 0; i < dados.length; i += 3) {
|
||||||
@@ -451,28 +281,18 @@ public class Mavenproject4 {
|
|||||||
|
|
||||||
int saldo = Integer.parseInt(dados[i + 2]);
|
int saldo = Integer.parseInt(dados[i + 2]);
|
||||||
|
|
||||||
if (email.equals(emailGuardado)
|
if (email.equals(emailGuardado) && senha.equals(senhaGuardada)) {
|
||||||
&& senha.equals(senhaGuardada)) {
|
|
||||||
|
|
||||||
saldoAtual = saldo;
|
saldoAtual = saldo;
|
||||||
indexUtilizador = i;
|
indexUtilizador = i;
|
||||||
|
|
||||||
// ADMIN
|
admin = email.equalsIgnoreCase("Admin");
|
||||||
if (email.equalsIgnoreCase("Admin")) {
|
|
||||||
|
|
||||||
admin = true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
admin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
System.out.println("Erro no login.");
|
System.out.println("Erro no login.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +303,6 @@ public class Mavenproject4 {
|
|||||||
private static void atualizarSaldo(String nomeFicheiro) {
|
private static void atualizarSaldo(String nomeFicheiro) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String[] dados = lerFicheiro(nomeFicheiro);
|
String[] dados = lerFicheiro(nomeFicheiro);
|
||||||
|
|
||||||
dados[indexUtilizador + 2] = String.valueOf(saldoAtual);
|
dados[indexUtilizador + 2] = String.valueOf(saldoAtual);
|
||||||
@@ -491,7 +310,6 @@ public class Mavenproject4 {
|
|||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(nomeFicheiro));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(nomeFicheiro));
|
||||||
|
|
||||||
for (String linha : dados) {
|
for (String linha : dados) {
|
||||||
|
|
||||||
bw.write(linha);
|
bw.write(linha);
|
||||||
bw.newLine();
|
bw.newLine();
|
||||||
}
|
}
|
||||||
@@ -499,7 +317,6 @@ public class Mavenproject4 {
|
|||||||
bw.close();
|
bw.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
System.out.println("Erro ao atualizar saldo.");
|
System.out.println("Erro ao atualizar saldo.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user