Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
DiceGame_Thomas_Barraclough_Resit
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
thomas.barraclough
DiceGame_Thomas_Barraclough_Resit
Commits
17fd45f1
Commit
17fd45f1
authored
Jan 13, 2020
by
Tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upload
parents
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
236 additions
and
0 deletions
+236
-0
.classpath
.classpath
+6
-0
.gitignore
.gitignore
+1
-0
.project
.project
+17
-0
org.eclipse.jdt.core.prefs
.settings/org.eclipse.jdt.core.prefs
+11
-0
DiceGameClass.java
src/DiceGameClass.java
+201
-0
No files found.
.classpath
0 → 100644
View file @
17fd45f1
<?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>
.gitignore
0 → 100644
View file @
17fd45f1
/bin/
.project
0 → 100644
View file @
17fd45f1
<?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>
.settings/org.eclipse.jdt.core.prefs
0 → 100644
View file @
17fd45f1
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
src/DiceGameClass.java
0 → 100644
View file @
17fd45f1
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment