This commit is contained in:
10
Desafios.txt
Normal file
10
Desafios.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Dificuldade Media; Faz 10 Flexões
|
||||||
|
Dificuldade Dificil; Faz o Pino Beber
|
||||||
|
Dificuldade Facil; 2 copos de água seguidos
|
||||||
|
Dificuldade Media; Cantar o refrão de uma música
|
||||||
|
Dificuldade Media; Dançar durante 30 segundos
|
||||||
|
Dificuldade Facil; Imitar um animal à escolha
|
||||||
|
Dificuldade Facil; Contar uma piada
|
||||||
|
Dificuldade Facil; Fazer 20 agachamentos
|
||||||
|
Dificuldade Media; Ficar 30 segundos em prancha
|
||||||
|
Dificuldade Facil; Fazer 10 saltos sem parar
|
||||||
13
pom.xml
Normal file
13
pom.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.mycompany</groupId>
|
||||||
|
<artifactId>Roleta_Desafios</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.release>24</maven.compiler.release>
|
||||||
|
<exec.mainClass>com.mycompany.roleta_desafios.Roleta_Desafios</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
121
src/main/java/com/mycompany/roleta_desafios/Roleta_Desafios.java
Normal file
121
src/main/java/com/mycompany/roleta_desafios/Roleta_Desafios.java
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mycompany.roleta_desafios;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author 250407
|
||||||
|
*/
|
||||||
|
public class Roleta_Desafios {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
String[] desafios = new String[10];
|
||||||
|
int total = lerFicheiro(desafios);
|
||||||
|
int opcao = -1;
|
||||||
|
|
||||||
|
while(opcao != 0){
|
||||||
|
System.out.println("|===Roleta de Desafios===|");
|
||||||
|
System.out.println("1 - girar roleta");
|
||||||
|
System.out.println("0 - sair");
|
||||||
|
System.out.println("|========================|");
|
||||||
|
opcao = scanner.nextInt();
|
||||||
|
|
||||||
|
switch(opcao){
|
||||||
|
case 1:
|
||||||
|
total = girar(desafios, total);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
scanner.nextLine();
|
||||||
|
System.out.println("escreve o desafio");
|
||||||
|
String novo = scanner.nextLine();
|
||||||
|
guardarDesafio(novo);
|
||||||
|
System.out.println("desafio guardado");
|
||||||
|
total = lerFicheiro(desafios);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
System.out.println("Fim!");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("opcao invalida");
|
||||||
|
}
|
||||||
|
|
||||||
|
}while(opcao != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int lerFicheiro(String[] desafios){
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Scanner file = new Scanner(new File("Desafios.txt"));
|
||||||
|
while(file.hasNextLine() && i < desafios.length){
|
||||||
|
desafios[i] = file.nextLine();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(Exception e) {
|
||||||
|
System.out.println("erro ao ler ficheiro: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void guardarDesafio(String desafio) throws IOException{
|
||||||
|
try{
|
||||||
|
FileWriter fileWriter = new FileWriter("Desafios.txt", true);
|
||||||
|
fileWriter.write(desafio);
|
||||||
|
}catch (IOException e){
|
||||||
|
System.out.println("Erro ao escrever" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static int girar(String[] desafios, int total){
|
||||||
|
if (total == 0){
|
||||||
|
System.out.println("sem deafios disponiveis!");
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
Random random = new Random();
|
||||||
|
System.out.println("A girar a Roleta...");
|
||||||
|
int delay = 50;
|
||||||
|
|
||||||
|
try{
|
||||||
|
for(int i = 0; i < 20; i++){
|
||||||
|
int indice = random .nextInt(total);
|
||||||
|
|
||||||
|
System.out.println("\rDesafio: " + desafios[indice]);
|
||||||
|
Thread.sleep(delay);
|
||||||
|
delay += 30;
|
||||||
|
}
|
||||||
|
int finalIndex = random.nextInt(total);
|
||||||
|
System.out.println(">>>>Desafio Final:<<<< " + desafios[finalIndex]);
|
||||||
|
|
||||||
|
for(int i = finalIndex; i < total - 1; i++){
|
||||||
|
desafios[i] = desafios[i + 1];
|
||||||
|
}
|
||||||
|
total--;
|
||||||
|
|
||||||
|
}catch (InterruptedException e){
|
||||||
|
System.out.println("erro na animacao.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user