Finished the base code

This commit is contained in:
Cametendo
2025-10-02 08:55:16 +02:00
parent df6a5a256c
commit d35d81c9f1
3 changed files with 121 additions and 1 deletions

2
.gitignore vendored
View File

@@ -29,3 +29,5 @@ replay_pid*
*.iml *.iml
/out/ /out/
#personal notes
/notes

View File

@@ -14,6 +14,7 @@ out/
bin/ bin/
!**/src/main/**/bin/ !**/src/main/**/bin/
!**/src/test/**/bin/ !**/src/test/**/bin/
notes/
### NetBeans ### ### NetBeans ###
/nbproject/private/ /nbproject/private/
@@ -26,4 +27,6 @@ bin/
.vscode/ .vscode/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
.txt

View File

@@ -0,0 +1,115 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.internal.bind.util.ISO8601Utils;
import java.io.FileReader;
import java.util.Scanner;
class CardsClass {
public String question = "";
public String answer = "";
public CardsClass(String question, String answer) {
this.question = question;
this.answer = answer;
}
}
class Wrapper {
List<CardsClass> cards;
}
public class Main {
public static void main(String[] args) {
Gson gson = new Gson();
Scanner jsonPath = new Scanner(System.in);
Scanner userAnswers = new Scanner(System.in);
System.out.println("Welcome to: Cards Gate");
System.out.println("-----------------------------------------------------------------------");
System.out.println("| ##### ##### |");
System.out.println("| # # ## ##### ##### #### ### # # ## ##### ###### |");
System.out.println("| # # # # # # # # ### # # # # # |");
System.out.println("| # # # # # # # #### # #### # # # ##### |");
System.out.println("| # ###### ##### # # # ### # # ###### # # |");
System.out.println("| # # # # # # # # # # ### # # # # # # |");
System.out.println("| ##### # # # # ##### #### # ##### # # # ###### |");
System.out.println("| # |");
System.out.println("-----------------------------------------------------------------------");
String start = "";
while (true) {
System.out.println("Would you like to start or read the manual? (y/n/m)");
start = userAnswers.nextLine();
if (start.equalsIgnoreCase("n")) {
System.exit(0); // Exit program
} else if (start.equalsIgnoreCase("m")) {
System.out.println("The rules:");
System.out.println("You are allowed to redo a card / deck as many times as you want.");
System.out.println("You can skip a question, look at the answer or go back to the previous question.");
System.out.println("You always have a re-order of your cards / deck");
System.out.println("That's it. For more details: Read the manual");
System.out.println("");
System.out.println("Have fun!!");
// Loop back to ask again
} else if (start.equalsIgnoreCase("y")) {
System.out.println("Please enter the path of the file you would like to read: ");
String filePath = jsonPath.nextLine();
Wrapper wrapper = new Wrapper();
try (Reader fileReader = new FileReader(filePath)) {
wrapper = new Gson().fromJson(fileReader, Wrapper.class);
} catch (IOException e) {
e.printStackTrace();
}
int cardNumber = 0;
while (true) {
String question = wrapper.cards.get(cardNumber).question;
String answer = wrapper.cards.get(cardNumber).answer;
System.out.println("What's: " + question + "?");
System.out.println("Available options: back, answer, skip");
String userInput = userAnswers.nextLine();
/*
In-session Settings
*/
if (userInput.equalsIgnoreCase("back")) {
cardNumber--;
} else if (userInput.equalsIgnoreCase("answer")) {
System.out.println(answer);
} else if (userInput.equalsIgnoreCase("skip")) {
cardNumber++;
}
/*
Deck Settings
*/
if (userInput.equalsIgnoreCase(answer)) {
cardNumber++;
if (cardNumber >= wrapper.cards.size()) {
System.out.println("You've answered all cards");
System.out.println("Redo Deck? (y/n)");
String finishedDeck = userAnswers.nextLine();
if (finishedDeck.equalsIgnoreCase("y")) {
System.out.println("Restarting Deck...");
cardNumber = 0; // Restart deck
} else if(finishedDeck.equalsIgnoreCase("n")) {
System.out.println("Another Deck? (y/n)");
String anotherDeck = userAnswers.nextLine();
if (anotherDeck.equalsIgnoreCase("y")) {
break; // Exit card loop
} else if (anotherDeck.equalsIgnoreCase("n")) {
System.exit(0);
}
}
} else {
System.out.println("Wrong, try again...");
}
}
}
} else {
System.out.println("Invalid choice, please enter y, n or m.");
}
}
}
}