package client.frame;
import general.statics.function.GUIFunctions;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import server.protocol.Message;
import client.custom.CustomMainPanel;
import client.gui.Constants;
/***
* The <code>InstructionFrame</code> class, a descendant of <code>YahtzeeFrame</code>, is the frame class for displaying
* in-game rules and other instructions. Mostly a static frame with a small number of dynamic inputs/controls.
*
* @author Priidu Neemre
*/
public class InstructionFrame extends YahtzeeFrame{
private static final long serialVersionUID = 00000001L;
//Constants for this frame
public static final int WINDOW_WIDTH = 550;
public static final int WINDOW_HEIGHT = 625;
//MAIN CONTAINER elements of the GUI
private JPanel bgPanel;
//RULES AND INSTRUCTIONS textual elements of the GUI
private JLabel txt_headingText;
private JLabel txt_descriptionText;
private JLabel txt_objectiveText;
private JLabel txt_combinationText;
private JLabel txt_onesText;
private JLabel txt_twosText;
private JLabel txt_threesText;
private JLabel txt_foursText;
private JLabel txt_fivesText;
private JLabel txt_sixesText;
private JLabel txt_upperBonusText;
private JLabel txt_intermediateSumText;
private JLabel txt_onePairText;
private JLabel txt_twoPairText;
private JLabel txt_threeOfAKindText;
private JLabel txt_fourOfAKindText;
private JLabel txt_smallStraightText;
private JLabel txt_largeStraightText;
private JLabel txt_houseText;
private JLabel txt_chanceText;
private JLabel txt_yahtzeeText;
private JLabel txt_totalSumText;
private JLabel txt_examplesText;
private JLabel txt_firstExText;
private JButton btnClose;
private JPanel instPanel;
public InstructionFrame(){
buildConfigureJFrame();
buildConfigureMainContainers();
buildConfigureInstructionTexts();
this.setVisible(true);
}
/**
* Sets the desired properties for the <code>InstructionFrame</code> itself.
*/
private void buildConfigureJFrame(){
//Panen paika m�ned �ldisemad, JFrame'i enda kohta k�ivad t�psustused
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
this.setTitle(GameplayFrame.FRAME_DEFAULT_TITLE + " - Rules and instructions");
this.setLocationRelativeTo(null); //Sean JFrame'i automaatselt ekraani keskele
}
/**
* Instantiates variables and enforces properties in connection with the main containers of the frame.
*/
private void buildConfigureMainContainers(){
//Loon JPaneli, mis hakkab t�itma JFrame'i default-content pane'i �lesannet ning mille
//sisse hakatakse lisama k�iki teisi graafilisi komponente.
bgPanel = new CustomMainPanel(new BorderLayout(), Constants.MAIN_BACKGROUND_IMAGE_PATH, Constants.REGULAR_TILE_IMAGE_PATH);
setContentPane(bgPanel);
}
/**
* Instantiates variables and enforces properties for all the elements of the GUI's "Instruction texts" area.
*/
private void buildConfigureInstructionTexts(){
txt_headingText = new JLabel("Rules and instructions");
txt_headingText.setFont(Constants.tahoma_huge_bold);
txt_headingText.setForeground(Color.WHITE);
txt_descriptionText = new JLabel("<html><font color=gray>- Description:</font> Yahtzee is an old and famous dice game with numerous variations in terms of rules and scoring. Yahtzee is said to have been developed from older dice games such as Yacht and Generala. " +
"This current version of the game, however, <font color = red>adobts most of its rules</font> from the prominent and popluar (especially in Scandinavia) version of the game called <font color = red>Yatzy</font>. </html>");
txt_descriptionText = GUIFunctions.applyJLabelStyle(txt_descriptionText, new EmptyBorder(5,0,4,0));
txt_objectiveText = new JLabel("<html><font color=gray>- Objective:</font> The main objective of the game is to score as many points as possible by rolling a set of five dice to make out one of the 13 combinations on the scoresheet. " +
"There are a total of 13 turns in the game with each player having 3 rolls per turn. Once a combination has been used (a score has been entered), it can not be used again. If, say the player runs out of suitable options to store the current score, " +
"a slot has to be picked for entering a 0-score. <font color = red>If the player skips a turn, his/her turn time runs out, then one of his/her slots is marked with a score of 0.</font></html>");
txt_objectiveText = GUIFunctions.applyJLabelStyle(txt_objectiveText, new EmptyBorder(0,0,4,0));
txt_combinationText = new JLabel("<html><font color=gray>- Combinations:</font> </html>");
txt_combinationText = GUIFunctions.applyJLabelStyle(txt_combinationText, new EmptyBorder(0,0,1,0));
txt_onesText = new JLabel("<html><font color=gray>- Ones: </font>At least one die showing the \"1\" face. <font color=red>(Maximal score: 5)</font></html>");
txt_onesText = GUIFunctions.applyJLabelStyle(txt_onesText, new EmptyBorder(0,20,1,0));
txt_twosText = new JLabel("<html><font color=gray>- Twos: </font>At least one die showing the \"2\" face. <font color=red>(Maximal score: 10)</font></html>");
txt_twosText = GUIFunctions.applyJLabelStyle(txt_twosText, new EmptyBorder(0,20,1,0));
txt_threesText = new JLabel("<html><font color=gray>- Threes: </font>At least one die showing the \"3\" face. <font color=red>(Maximal score: 15)</font></html>");
txt_threesText = GUIFunctions.applyJLabelStyle(txt_threesText, new EmptyBorder(0,20,1,0));
txt_foursText = new JLabel("<html><font color=gray>- Fours: </font>At least one die showing the \"4\" face. <font color=red>(Maximal score: 20)</font></html>");
txt_foursText = GUIFunctions.applyJLabelStyle(txt_foursText, new EmptyBorder(0,20,1,0));
txt_fivesText = new JLabel("<html><font color=gray>- Fives: </font>At least one die showing the \"5\" face. <font color=red>(Maximal score: 25)</font></html>");
txt_fivesText = GUIFunctions.applyJLabelStyle(txt_fivesText, new EmptyBorder(0,20,1,0));
txt_sixesText = new JLabel("<html><font color=gray>- Sixes: </font>At least one die showing the \"6\" face. <font color=red>(Maximal score: 30)</font></html>");
txt_sixesText = GUIFunctions.applyJLabelStyle(txt_sixesText, new EmptyBorder(0,20,1,0));
txt_upperBonusText = new JLabel("<html><font color=gray>- Upper section bonus: </font>A bonus of 50pts, which is applied if the previous slots add up to a 63-point total. Can not be used manually. <font color = red>(Maximal score: 50)</font></html>");
txt_upperBonusText = GUIFunctions.applyJLabelStyle(txt_upperBonusText, new EmptyBorder(0,20,1,0));
txt_intermediateSumText = new JLabel("<html><font color=gray>- Intermediate sum:</font> A compendious score slot, that sums up all the scores from the previous slots(ex. upper section bonus). Can not be enter manually. <font color = red>(Maximal score: 105)</font></html>");
txt_intermediateSumText = GUIFunctions.applyJLabelStyle(txt_intermediateSumText, new EmptyBorder(0,20,1,0));
txt_onePairText = new JLabel("<html><font color=gray>- One pair:</font> At least one set of 2 dice with the same face. <font color = red>(Maximal score: 12)</font></html>");
txt_onePairText = GUIFunctions.applyJLabelStyle(txt_onePairText, new EmptyBorder(0,20,1,0));
txt_twoPairText = new JLabel("<html><font color=gray>- Two pairs:</font> At least two sets of 2 dice with the same face. <font color = red>(Maximal score: 22)</font></html>");
txt_twoPairText = GUIFunctions.applyJLabelStyle(txt_twoPairText, new EmptyBorder(0,20,1,0));
txt_threeOfAKindText = new JLabel("<html><font color=gray>- Three of a kind:</font> At least three dice having the same face. <font color = red>(Maximal score: 18)</font></html>");
txt_threeOfAKindText = GUIFunctions.applyJLabelStyle(txt_threeOfAKindText, new EmptyBorder(0,20,1,0));
txt_fourOfAKindText = new JLabel("<html><font color=gray>- Four of a kind:</font> At least four dice showing the same face. <font color = red>(Maximal score: 24)</font></html>");
txt_fourOfAKindText = GUIFunctions.applyJLabelStyle(txt_fourOfAKindText, new EmptyBorder(0,20,1,0));
txt_smallStraightText = new JLabel("<html><font color=gray>- Small staight:</font> A combination of dice with the follwoing values: 1-2-3-4-5. <font color = red>(Maximal score: 15)</font></html>");
txt_smallStraightText = GUIFunctions.applyJLabelStyle(txt_smallStraightText, new EmptyBorder(0,20,1,0));
txt_largeStraightText = new JLabel("<html><font color=gray>- Large straight:</font> A combination of dice with the following values: 2-3-4-5-6. <font color = red>(Maximal score: 20)</font></html>");
txt_largeStraightText = GUIFunctions.applyJLabelStyle(txt_largeStraightText, new EmptyBorder(0,20,1,0));
txt_houseText = new JLabel("<html><font color=gray>- Full house:</font> A set of 2 dice with the same face + a set of 3 dice with another face. <font color = red>(Maximal score: 28)</font></html>");
txt_houseText = GUIFunctions.applyJLabelStyle(txt_houseText, new EmptyBorder(0,20,1,0));
txt_chanceText = new JLabel("<html><font color=gray>- Chance:</font> Any combination of dice can be entered.<font color = red>(Maximal score: 30)</font></html>");
txt_chanceText = GUIFunctions.applyJLabelStyle(txt_chanceText, new EmptyBorder(0,20,1,0));
txt_yahtzeeText = new JLabel("<html><font color=gray>- Yahtzee:</font> A set of all 5 dice with the same face. <font color = red>(Maximal score: 50)</font></html>");
txt_yahtzeeText = GUIFunctions.applyJLabelStyle(txt_yahtzeeText, new EmptyBorder(0,20,1,0));
txt_totalSumText = new JLabel("<html><font color=gray>- Total sum:</font> A compendious score slot, that sums up all the scores from the entire table. Can not be enter manually. <font color = red>(Maximal score: 374)</font></html>");
txt_totalSumText = GUIFunctions.applyJLabelStyle(txt_totalSumText, new EmptyBorder(0,20,1,0));
txt_examplesText = new JLabel("<html><font color=gray>- Examples:</font> </html>");
txt_examplesText = GUIFunctions.applyJLabelStyle(txt_examplesText, new EmptyBorder(3,0,1,0));
txt_firstExText = new JLabel("<html><font color=gray> - 1: </font> The player rolls the dice, resulting in a combination of: 4,5,6,6,1. He/she sees the potential for a good combination" +
" regarding the sixes. The player keeps dice 6,6 and rolls 4,5,1 again, getting 6,3,2. Again the player prunes the 6, storing 6,6,6 and rolls 3,2 again (third and final roll). The result of" +
" the roll is 6,1, so the player has a final set of dice with values 6,6,6,6,1. He/she decides to enter the score into the \"Four-of-a-kind\" score slot, receiving <font color = red>24pts.</font></html>");
txt_firstExText = GUIFunctions.applyJLabelStyle(txt_firstExText, new EmptyBorder(0,20,4,0));
btnClose = new JButton("Close");
btnClose.setPreferredSize(new Dimension(70,22));
btnClose.addActionListener(new CloseListener());
instPanel = new JPanel();
instPanel.setLayout(new BoxLayout(instPanel, BoxLayout.Y_AXIS));
instPanel.setBorder(new EmptyBorder(5,5,5,5));
instPanel.setPreferredSize(new Dimension(WINDOW_WIDTH, 100));
instPanel.setMaximumSize(new Dimension(WINDOW_WIDTH, 100));
instPanel.setOpaque(false);
instPanel.add(GUIFunctions.createTextContainer(txt_headingText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_descriptionText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_objectiveText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_combinationText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_onesText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_twosText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_threesText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_foursText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_fivesText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_sixesText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_upperBonusText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_intermediateSumText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_onePairText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_twoPairText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_threeOfAKindText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_fourOfAKindText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_smallStraightText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_largeStraightText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_houseText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_chanceText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_yahtzeeText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_totalSumText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_examplesText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(txt_firstExText, BoxLayout.X_AXIS, 0));
instPanel.add(GUIFunctions.createTextContainer(btnClose, BoxLayout.X_AXIS, 1));
getContentPane().add(instPanel, BorderLayout.CENTER);
}
@Override
public void updateGUIIndicators() {}
@Override
public void writeToLogArea(String message) {}
@Override
public void writeToLogArea(Message msg) {}
/**
* The <code>CloseListener</code> class is an implementation of the <code>ActionListener</code> which if
* instantiated and binded to a control, reacts an incoming event by disposing the "Instructions and rules" frame.
*/
class CloseListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
}