From d35d81c9f15a5ad77d6441011ae7110786d28f7b Mon Sep 17 00:00:00 2001 From: Cametendo Date: Thu, 2 Oct 2025 08:55:16 +0200 Subject: [PATCH] Finished the base code --- .gitignore | 2 + Cards-Gate/.gitignore | 5 +- Cards-Gate/src/Main.java | 115 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a0510aa..0b30cc5 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ replay_pid* *.iml /out/ +#personal notes +/notes diff --git a/Cards-Gate/.gitignore b/Cards-Gate/.gitignore index f68d109..83a3f2f 100644 --- a/Cards-Gate/.gitignore +++ b/Cards-Gate/.gitignore @@ -14,6 +14,7 @@ out/ bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ +notes/ ### NetBeans ### /nbproject/private/ @@ -26,4 +27,6 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +.txt diff --git a/Cards-Gate/src/Main.java b/Cards-Gate/src/Main.java index e69de29..9ec420c 100644 --- a/Cards-Gate/src/Main.java +++ b/Cards-Gate/src/Main.java @@ -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 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."); + } + } + } +} \ No newline at end of file