mirror of
https://github.com/Cametendo/Cards-Gate.git
synced 2026-03-18 04:40:20 +01:00
Finished the base code
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -29,3 +29,5 @@ replay_pid*
|
||||
*.iml
|
||||
/out/
|
||||
|
||||
#personal notes
|
||||
/notes
|
||||
|
||||
3
Cards-Gate/.gitignore
vendored
3
Cards-Gate/.gitignore
vendored
@@ -14,6 +14,7 @@ out/
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
notes/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
@@ -27,3 +28,5 @@ bin/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
|
||||
.txt
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user