main
unknown
plain_text
3 years ago
11 kB
4
Indexable
package millionaire; import java.util.*; import java.awt.Color; import java.io.File; import enigma.core.Enigma; public class Main { public static void main(String[] args) { enigma.console.Console cn = Enigma.getConsole("The Game", 120, 30, 15); EnigmaWrapper wrapper = new EnigmaWrapper(cn); InfoBox box = new InfoBox(cn); Thread thread = new Thread(box); String[] statics = {}; String selection = ""; int answered = 0; Scanner scanner = new Scanner(System.in); Question[] questions = new Question[0]; Participant[] participants = new Participant[0]; String contestant = ""; String[] word_cloud; boolean j_double = true; boolean j_50 = true; int money_tier, money_won = 0, difficulty, id = -1, random_contestant = -1; // File file = new File("result.txt"); // file.delete(); while (true) { System.out.print("***** Menu *****\r\n" + "1.Load questions\r\n" + "2.Load participants\r\n" + "3.Start competition \r\n" + "4.Show statistics\r\n" + "5.Exit\r\n" + "\n" + "Please make a choice: "); String option = scanner.nextLine(); if (option.equalsIgnoreCase("1")) { System.out.print("Please enter the file name to load for questions: "); //String fileName_1 = scanner.nextLine(); String fileName_1 = "questions.txt"; questions = Millionaire.get_questions("stop_words.txt", fileName_1); if (questions.length != 0) { System.out.println("\nThe file is loaded."); String[] categories = new String[questions.length]; int index = 0; for (int i = 0; i < questions.length; i++) { categories[index] = questions[i].getCategory(); for (int j = 0; j < categories.length; j++) { if (j != index && categories[index].equals(categories[j])) { categories[j] = null; } } index++; } System.out.println("Category\t\t\tThe Number of Questions"); System.out.println("--------\t\t\t-----------------------"); int count; for (String category : categories) { count = 0; if (category == null) continue; for (Question quest : questions) { if (quest.getCategory().equals(category)) count++; } System.out.print(category); for (int i = 0; i < 30-category.length(); i++) { System.out.print(" "); } System.out.println(count); } System.out.println(); int diffcounter1 = 0; int diffcounter2 = 0; int diffcounter3 = 0; int diffcounter4 = 0; int diffcounter5 = 0; for (int i = 0; i < questions.length; i++) { if (questions[i].getDifficulty() == 1) { diffcounter1 ++; }else if (questions[i].getDifficulty() == 2) { diffcounter2 ++; } else if (questions[i].getDifficulty() == 3) { diffcounter3 ++; } else if (questions[i].getDifficulty() == 4) { diffcounter4 ++; } else if (questions[i].getDifficulty() == 5) { diffcounter5 ++; } } System.out.println(); System.out.println("Difficulty level \t The number of questions"); System.out.println("---------------- \t -----------------------"); System.out.println("\t\t1 \t\t\t\t " + diffcounter1); System.out.println("\t\t2 \t\t\t\t " + diffcounter2); System.out.println("\t\t3 \t\t\t\t " + diffcounter3); System.out.println("\t\t4 \t\t\t\t " + diffcounter4); System.out.println("\t\t5 \t\t\t\t " + diffcounter5); System.out.println(); } } else if (option.equalsIgnoreCase("2")) { System.out.print("Please enter the file name to load for participants: "); //String fileName_2 = scanner.nextLine(); String fileName_2 = "participants.txt"; participants = Millionaire.get_participants(fileName_2); if (participants.length != 0) { System.out.println("\nThe file is loaded."); System.out.println(); } } else if (option.equalsIgnoreCase("3")) { if (questions.length == 0 || participants.length == 0) { System.out.println("First load the files, please.\n"); continue; } j_double = true; j_50 = true; for (int i = 0; i < 1; i++) { random_contestant = Millionaire.randomInt(0, participants.length); if (participants[random_contestant].getisPlayed() == false) { contestant = participants[random_contestant].getName(); participants[random_contestant].isPlayed = true; } else { i--; } } System.out.println("\nContestant: " + contestant); System.out.println("-----------------------------------------------------------"); for (int i = 1; i < 6; i++) { word_cloud = Millionaire.generate_word_cloud(i, questions); System.out.println("\nQ" + i + " Word Cloud:\n"); for (int j = 0; j < word_cloud.length; j++) { System.out.print(word_cloud[j] + "\t"); } while (true) { System.out.println(); System.out.println("> Enter your selection: "); selection = scanner.nextLine(); if (Millionaire.isStringInArray(selection, word_cloud)) { break; } else { System.out.println("Please enter correct word"); } } id = Millionaire.get_question_id(i, selection, questions); System.out.println("Q" + i + ") " + questions[id].getText()); System.out.println("A) " + questions[id].getChoiceA()); System.out.println("B) " + questions[id].getChoiceB()); System.out.println("C) " + questions[id].getChoiceC()); System.out.println("D) " + questions[id].getChoiceD()); System.out.println("Enter your choice (E:Exit): "); String answer = scanner.nextLine(); if (answer.equalsIgnoreCase("x") && j_50 == true) { // 50% System.out.println("Q" + i + ") " + questions[id].getText()); Millionaire.j_50(questions[id].getChoiceA(), questions[id].getChoiceB(), questions[id].getChoiceC(), questions[id].getChoiceD(), questions[id].getCorrectAnswer()); j_50 = false; System.out.println("Enter your choice (E:Exit): "); answer = scanner.nextLine(); } if (answer.equalsIgnoreCase("z")) { //double if (j_50 == false) { Millionaire.j_50(questions[id].getChoiceA(), questions[id].getChoiceB(), questions[id].getChoiceC(), questions[id].getChoiceD(), questions[id].getCorrectAnswer()); } System.out.println("Enter your choice (E:Exit): "); answer = scanner.nextLine(); if (answer.equalsIgnoreCase(questions[id].getCorrectAnswer())) { System.out.println("Correct Answer!"); money_won = Millionaire.get_money_won(i); System.out.println("You have: $" + money_won); answered = 1; } else{ if (answer.equalsIgnoreCase("A")) { System.out.println("A) " + questions[id].getChoiceA()); } else { System.out.println("A) "); } if (answer.equalsIgnoreCase("B")) { System.out.println("B) " + questions[id].getChoiceB()); } else { System.out.println("B) "); } if (answer.equalsIgnoreCase("C")) { System.out.println("C) " + questions[id].getChoiceC()); } else { System.out.println("C) "); } if (answer.equalsIgnoreCase("D")) { System.out.println("D) " + questions[id].getChoiceD()); } else { System.out.println("D) "); } System.out.println("Enter your choice (E:Exit): "); answer = scanner.nextLine(); if (answer.equalsIgnoreCase(questions[id].getCorrectAnswer())) { System.out.println("Correct Answer!"); money_won = Millionaire.get_money_won(i); System.out.println("You have: $" + money_won); answered = 1; continue; } else { System.out.println("Wrong Answer"); System.out.println("Correct Answer is " + questions[id].getCorrectAnswer()); System.out.println("You won: $" + money_won); answered = 0; break; } } } else if (answer.equalsIgnoreCase("e")) { System.out.println("You won: $" + money_won); System.out.println("Correct Answer is " + questions[id].getCorrectAnswer()); answered = 0; break; } else if (answer.equalsIgnoreCase(questions[id].getCorrectAnswer())) { System.out.println("Correct Answer!"); money_won = Millionaire.get_money_won(i); System.out.println("You have: $" + money_won); answered = 1; continue; } else if(!answer.equalsIgnoreCase(questions[id].getCorrectAnswer())){ System.out.println("Wrong Answer"); System.out.println("Correct Answer is " + questions[id].getCorrectAnswer()); System.out.println("You won: $" + money_won); answered = 0; break; } } FileOperations.writeToFile("result.txt", id + "#" + random_contestant + "#" + answered); } else if (option.equalsIgnoreCase("4")) { if (questions.length == 0 || participants.length == 0) { System.out.println("First load the files, please.\n"); continue; } statics = FileOperations.arrayCreater("result.txt"); Millionaire.print_statics(statics, questions, participants); } else if (option.equalsIgnoreCase("5")) { System.out.println("The game closed."); break; } else { System.out.println("\nUnknown option."); } } } }
Editor is loading...