Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
5
Indexable
Never
public MillionaireGame(JFrame gameSelectionFrame) {
    Random random = new Random();
    int selectedSet = random.nextInt(allQuestionSets.length);
    questionSet = allQuestionSets[selectedSet];
    optionSet = allOptionSets[selectedSet];
    answerSet = allAnswerSets[selectedSet];
    hints = allHints[selectedSet];
    this.gameSelectionFrame = gameSelectionFrame;
    createUI();
    setTitle("Who Wants to Be a Millionaire?");

    JLabel rulesLabel = new JLabel("<html><body style='width: 500px; text-align: left;'>Rules of the Game:<br><br>" +
            "The Who Wants to Be a Millionaire questions are structured according to five different Levels with each level increasing in difficulty. Each level contains three questions.<br>" +
            "Questions that are grouped into the same level will all be of similar difficulty.<br><br>" +
            "Question 1 $100<br>" +
            "Question 2 $500<br>" +
            "Question 3 $1,000<br>" +
            "Question 4 $2,500<br>" +
            "Question 5 $5,000<br><br>" +
            "Question 6 $10,000<br>" +
            "Question 7 $50,000<br>" +
            "Question 8 $100,000<br>" +
            "Question 9 $250,000<br>" +
            "Question 10 $500,000<br><br>" +
            "Question 11 $750,000<br>" +
            "Question 12 $1,000,000<br><br>" +
            "50/50 : removes two wrong answers from the multiple-choice selection, leaving the contestant with only one correct and one incorrect option. This means they have a 50/50 chance.<br><br>" +
            "Ask for a hint : Contestants can ask for a hint to the correct answer that they can use at any point during the game. They can use this option twice.<br><br>" +
            "</body></html>");

    rulesLabel.setFont(new Font("Arial", Font.PLAIN, 14));

    JPanel rulesPanel = new JPanel(new BorderLayout());
    rulesPanel.add(rulesLabel, BorderLayout.CENTER);
    rulesLabel.setForeground(Color.BLACK);

    JOptionPane.showMessageDialog(this, rulesPanel, "Rules of the Game", JOptionPane.PLAIN_MESSAGE, new ImageIcon("capsule_616x353.jpg"));

    setQuestion();

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(750, 550);
    setLocationRelativeTo(null);
    setResizable(false);

    startTimer(); // Start the timer after the rule window is closed
}


private void setQuestion() {
    if (timer != null) {
        timer.stop();
    }
    timeLeft = 20;
    updateQuestionLabel();
    option1.setText(optionSet[currentQuestion][0]);
    option2.setText(optionSet[currentQuestion][1]);
    option3.setText(optionSet[currentQuestion][2]);
    option4.setText(optionSet[currentQuestion][3]);
    correctAnswer = answerSet[currentQuestion];
    enableOptions();
}
Leave a Comment