Commit 17fd45f1 authored by Tom's avatar Tom

upload

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DiceGame</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
import java.util.Random;
public class DiceGameClass extends javax.swing.JFrame {
public DiceGameClass() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
//here I am setting up the different GUI labels that will appear on screen when the program is run
round = new javax.swing.JLabel();
roll = new javax.swing.JButton();
dice1 = new javax.swing.JLabel();
dice2 = new javax.swing.JLabel();
turn = new javax.swing.JLabel();
p2ScoreTable = new javax.swing.JLabel();
p1ScoreTable = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
textArea = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
//Here I set the text that is displayed inside of the various labels ant buttons
round.setText("Round 1");
roll.setText("Roll");
roll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rollActionPerformed(evt);
}
});
dice1.setText("Dice 1 =");
dice2.setText("Dice 2 =");
turn.setText("Player 1's turn");
p2ScoreTable.setText("Player 2 = ");
p1ScoreTable.setText("Player 1 =");
//Setting up the text box size
textArea.setColumns(20);
textArea.setRows(5);
jScrollPane1.setViewportView(textArea);
//From here I set up the positioning of the different labels and buttons, this particular area of programming was for the horizontal positioning
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(104, 104, 104)
.addComponent(turn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(round))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(roll)
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(p1ScoreTable)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(p2ScoreTable))
.addGroup(layout.createSequentialGroup()
.addComponent(dice1)
.addGap(42, 42, 42)
.addComponent(dice2)))))
.addGap(0, 154, Short.MAX_VALUE)))
.addContainerGap())
);
//From here I set up the positioning of the different labels and buttons, this particular area of programming was for the vertical positioning
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(round, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(turn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(roll)
.addComponent(dice1)
.addComponent(dice2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(p2ScoreTable)
.addComponent(p1ScoreTable))
.addGap(55, 55, 55))
);
pack();
}
private static void rollActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
//Here I tried to replace the text of the dice1 label
int d1;
public void dice() {
dice1.setText(String.valueOf(d1));
}
public static void main(String args[]) {
//Here i set up the variables I will be using
int d1 = 0;
int d2 = 0;
int r = 0;
int proceed;
//Here is a while statement, it finds the current round, if that round is under 3 the loop will run
while(r < 3) {
r = r + 1;
Random rand = new Random();
// This gets a random number between 0 and 6
d1 = rand.nextInt(6);
//Here I added 1 to the result to reach the minimum value of 1, this was required because d1's default value is 0
d1 += 1;
// This gets a random number between 0 and 6
d2 = rand.nextInt(6);
//Here I added 1 to the result to reach the minimum value of 1, this was required because d2's default value is 0
d2 += 1;
System.out.print("Player 1 rolled a" + d1 + " and " + d2 + "!\nOverall thats " + (d1 + d2) + "!");
}
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(DiceGameClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(DiceGameClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(DiceGameClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DiceGameClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DiceGameClass().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JLabel dice1;
public javax.swing.JLabel dice2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel p1ScoreTable;
private javax.swing.JLabel p2ScoreTable;
private javax.swing.JButton roll;
private javax.swing.JLabel round;
private javax.swing.JTextArea textArea;
private javax.swing.JLabel turn;
// End of variables declaration
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment