Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
battleships
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
bradley.vernon
battleships
Commits
47506859
Commit
47506859
authored
May 03, 2019
by
BVBra_000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
label issues, test on previous versions of eclipse.
parent
17858211
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
17 deletions
+50
-17
BSGUI.fxml
src/BSGUI.fxml
+4
-4
BSMain.java
src/BSMain.java
+28
-12
BattleClass.java
src/BattleClass.java
+18
-1
No files found.
src/BSGUI.fxml
View file @
47506859
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<Pane
maxHeight=
"1.7976931348623157E308"
maxWidth=
"1.7976931348623157E308"
prefHeight=
"749.0"
prefWidth=
"1054.0"
xmlns=
"http://javafx.com/javafx/11.0.1"
xmlns:fx=
"http://javafx.com/fxml/1"
fx:controller=
"BSMain"
>
<Pane
maxHeight=
"1.7976931348623157E308"
maxWidth=
"1.7976931348623157E308"
prefHeight=
"749.0"
prefWidth=
"1054.0"
xmlns=
"http://javafx.com/javafx/11.0.1"
xmlns:fx=
"http://javafx.com/fxml/1"
fx:controller=
"BSMain"
>
<children>
<children>
<Pane
accessibleRole=
"COMBO_BOX"
layoutY=
"-14.0"
maxHeight=
"1.7976931348623157E308"
maxWidth=
"1.7976931348623157E308"
prefHeight=
"749.0"
prefWidth=
"1054.0"
>
<Pane
fx:id=
"admiral"
accessibleRole=
"COMBO_BOX"
layoutY=
"-14.0"
maxHeight=
"1.7976931348623157E308"
maxWidth=
"1.7976931348623157E308"
prefHeight=
"749.0"
prefWidth=
"1054.0"
>
<children>
<children>
<ChoiceBox
fx:id=
"DPx"
layoutX=
"30.0"
layoutY=
"651.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<ChoiceBox
fx:id=
"DPx"
layoutX=
"30.0"
layoutY=
"651.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<ChoiceBox
fx:id=
"DPy"
layoutX=
"214.0"
layoutY=
"651.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<ChoiceBox
fx:id=
"DPy"
layoutX=
"214.0"
layoutY=
"651.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
...
@@ -15,9 +15,9 @@
...
@@ -15,9 +15,9 @@
<ChoiceBox
fx:id=
"shipSelection"
layoutX=
"30.0"
layoutY=
"679.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<ChoiceBox
fx:id=
"shipSelection"
layoutX=
"30.0"
layoutY=
"679.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<Label
fx:id=
"label"
alignment=
"CENTER"
contentDisplay=
"CENTER"
layoutX=
"214.0"
layoutY=
"680.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"Stage : Preperation"
textAlignment=
"JUSTIFY"
wrapText=
"true"
/>
<Label
fx:id=
"label"
alignment=
"CENTER"
contentDisplay=
"CENTER"
layoutX=
"214.0"
layoutY=
"680.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"Stage : Preperation"
textAlignment=
"JUSTIFY"
wrapText=
"true"
/>
<Button
fx:id=
"fire"
layoutX=
"582.0"
layoutY=
"651.0"
mnemonicParsing=
"false"
onAction=
"#fireAction"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"*FIRE*"
/>
<Button
fx:id=
"fire"
layoutX=
"582.0"
layoutY=
"651.0"
mnemonicParsing=
"false"
onAction=
"#fireAction"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"*FIRE*"
/>
<Button
fx:id=
"quit"
layoutX=
"398.0"
layoutY=
"681.0"
mnemonicParsing=
"false"
prefHeight=
"25.0"
prefWidth=
"184.0"
text=
"*Quit
*"
/>
<Button
fx:id=
"quit"
layoutX=
"398.0"
layoutY=
"681.0"
mnemonicParsing=
"false"
onAction=
"#quitAction"
prefHeight=
"25.0"
prefWidth=
"184.0"
text=
"*QUIT
*"
/>
<Button
fx:id=
"battleStage"
layoutX=
"582.0"
layoutY=
"681.0"
mnemonicParsing=
"false"
prefHeight=
"25.0"
prefWidth=
"184.0"
text=
"*Battle Stage
*"
/>
<Button
fx:id=
"battleStage"
layoutX=
"582.0"
layoutY=
"681.0"
mnemonicParsing=
"false"
onAction=
"#stageAction"
prefHeight=
"25.0"
prefWidth=
"184.0"
text=
"*BATTLE STAGE
*"
/>
<Label
fx:id=
"admiral"
layoutX=
"30.0"
layoutY=
"634.0"
prefHeight=
"17.0"
prefWidth=
"734.0"
text=
"Admiral Nutsey : "Place your ships Captain!!!""
/>
<Label
layoutX=
"30.0"
layoutY=
"634.0"
prefHeight=
"17.0"
prefWidth=
"734.0"
text=
"Admiral Nutsey : "Place your ships Captain!!!""
/>
</children>
</children>
</Pane>
</Pane>
</children>
</children>
...
...
src/BSMain.java
View file @
47506859
...
@@ -31,7 +31,8 @@ public class BSMain extends Application{
...
@@ -31,7 +31,8 @@ public class BSMain extends Application{
@FXML
private
Button
quit
;
@FXML
private
Button
quit
;
@FXML
private
Label
label
;
@FXML
private
Label
label
;
@FXML
private
Label
admiral
;
@FXML
static
Label
admiral
;
static
ObservableList
<
String
>
numbrz
=
FXCollections
.
observableArrayList
(
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
);
static
ObservableList
<
String
>
numbrz
=
FXCollections
.
observableArrayList
(
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
);
static
ObservableList
<
String
>
ltrz
=
FXCollections
.
observableArrayList
(
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
);
static
ObservableList
<
String
>
ltrz
=
FXCollections
.
observableArrayList
(
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
);
...
@@ -47,12 +48,15 @@ public class BSMain extends Application{
...
@@ -47,12 +48,15 @@ public class BSMain extends Application{
static
ShipClass
playerS
=
new
ShipClass
();
static
ShipClass
playerS
=
new
ShipClass
();
static
ShipClass
computerS
=
new
ShipClass
();
static
ShipClass
computerS
=
new
ShipClass
();
Boolean
stage0
=
true
;
Boolean
stage1
=
false
;
@Override
@Override
public
void
start
(
Stage
arg0
)
throws
Exception
{
public
void
start
(
Stage
arg0
)
throws
Exception
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
Parent
root
=
FXMLLoader
.
load
(
getClass
().
getResource
(
"/BSGUI.fxml"
));
Parent
root
=
FXMLLoader
.
load
(
getClass
().
getResource
(
"/BSGUI.fxml"
));
//System.out.println(DPx);
...
@@ -93,6 +97,7 @@ public class BSMain extends Application{
...
@@ -93,6 +97,7 @@ public class BSMain extends Application{
@FXML
@FXML
void
placeAction
(
ActionEvent
event
)
{
void
placeAction
(
ActionEvent
event
)
{
if
(
stage0
)
{
playerS
.
ShipPlacer
(
ship
,
x
,
y
);
playerS
.
ShipPlacer
(
ship
,
x
,
y
);
...
@@ -101,21 +106,18 @@ public class BSMain extends Application{
...
@@ -101,21 +106,18 @@ public class BSMain extends Application{
if
(!
playerG
.
MoveValidCheck
(
playerG
,
playerS
.
moves
)){
if
(!
playerG
.
MoveValidCheck
(
playerG
,
playerS
.
moves
)){
label
.
setText
(
"Cordinates are taken. not added to grid"
);
label
.
setText
(
"Cordinates are taken. not added to grid"
);
}
}
else
{
admiral
.
setText
(
"Your in Battle now son, try *FIRE*"
);
}
}
}
}
@FXML
@FXML
void
fireAction
(
ActionEvent
event
)
{
void
fireAction
(
ActionEvent
event
)
{
// disable during placing stage
// enable once all ships are placed
// notify user in changing of stages
// figure out how to do all of the above
Boolean
tempStage
=
false
;
if
(
stage1
)
{
if
(
tempStage
)
{
String
HmnMove
=
x
+
y
;
String
HmnMove
=
x
+
y
;
String
CmptrMove
=
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
0
)
String
CmptrMove
=
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
0
)
...
@@ -126,10 +128,24 @@ public class BSMain extends Application{
...
@@ -126,10 +128,24 @@ public class BSMain extends Application{
}
}
else
{
else
{
labe
l
.
setText
(
"Place all ships before firing"
);
admira
l
.
setText
(
"Place all ships before firing"
);
}
}
}
}
@FXML
void
stageAction
(
ActionEvent
event
)
{
stage0
=
false
;
stage1
=
true
;
admiral
.
setText
(
"Fire on the enemy"
);
}
@FXML
void
quitAction
(
ActionEvent
event
)
{
//Add save function
System
.
exit
(
0
);
}
...
...
src/BattleClass.java
View file @
47506859
...
@@ -2,12 +2,29 @@
...
@@ -2,12 +2,29 @@
public
class
BattleClass
{
public
class
BattleClass
{
public
static
void
fire
(
ShipClass
opponent
,
String
Cordinates
)
{
public
static
void
fire
(
ShipClass
opponent
,
String
Cordinates
)
{
// loop through shipsHealth array and
// loop through shipsHealth array and
// use .contains to see if any ships contain the fired upon coordinates
// use .contains to see if any ships contain the fired upon coordinates
// then use Grid.sunk() to check if the the entire ship has gone.
// then use Grid.sunk() to check if the the entire ship has gone.
for
(
int
i
=
0
;
i
<
opponent
.
shipsHealth
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
opponent
.
shipsHealth
.
get
(
i
).
size
();
j
++
)
{
if
(
opponent
.
shipsHealth
.
get
(
i
).
contains
(
Cordinates
))
{
BSMain
.
admiral
.
setText
(
"Hit on "
+
Cordinates
);
opponent
.
shipsHealth
.
get
(
i
).
remove
(
Cordinates
);
opponent
.
SunkCheck
(
opponent
);
}
else
{
BSMain
.
admiral
.
setText
(
"Miss at "
+
Cordinates
);
}
}
}
}
}
...
...
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