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
96b49fcb
Commit
96b49fcb
authored
May 16, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GUI ERROR
parent
7ca9d1b4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
24 deletions
+74
-24
BSGUI.fxml
src/BSGUI.fxml
+4
-2
BSMain.java
src/BSMain.java
+41
-10
BattleClass.java
src/BattleClass.java
+11
-11
ComputerInput.java
src/ComputerInput.java
+16
-0
Grid.java
src/Grid.java
+2
-1
No files found.
src/BSGUI.fxml
View file @
96b49fcb
...
...
@@ -17,9 +17,9 @@
<children>
<ChoiceBox
fx:id=
"DPx"
layoutX=
"164.0"
layoutY=
"617.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<ChoiceBox
fx:id=
"shipSelection"
layoutX=
"164.0"
layoutY=
"645.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<Label
fx:id=
"admiral"
layoutX=
"165.0"
layoutY=
"600.0"
prefHeight=
"17.0"
prefWidth=
"
734
.0"
text=
"Admiral Nutsey : "Place your ships Captain!!!""
/>
<Label
fx:id=
"admiral"
layoutX=
"165.0"
layoutY=
"600.0"
prefHeight=
"17.0"
prefWidth=
"
368
.0"
text=
"Admiral Nutsey : "Place your ships Captain!!!""
/>
<ChoiceBox
fx:id=
"DPy"
layoutX=
"348.0"
layoutY=
"617.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
/>
<Label
fx:id=
"
error
"
alignment=
"CENTER"
contentDisplay=
"CENTER"
layoutX=
"348.0"
layoutY=
"645.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"Stage : Preperation"
textAlignment=
"JUSTIFY"
wrapText=
"true"
/>
<Label
fx:id=
"
stage
"
alignment=
"CENTER"
contentDisplay=
"CENTER"
layoutX=
"348.0"
layoutY=
"645.0"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"Stage : Preperation"
textAlignment=
"JUSTIFY"
wrapText=
"true"
/>
<Button
fx:id=
"place"
layoutX=
"716.0"
layoutY=
"617.0"
mnemonicParsing=
"false"
onAction=
"#placeAction"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"*PLACE A SHIP*"
textAlignment=
"CENTER"
/>
<Button
fx:id=
"fire"
layoutX=
"532.0"
layoutY=
"617.0"
mnemonicParsing=
"false"
onAction=
"#fireAction"
prefHeight=
"28.0"
prefWidth=
"184.0"
text=
"*FIRE*"
/>
<Button
fx:id=
"quit"
layoutX=
"532.0"
layoutY=
"646.0"
mnemonicParsing=
"false"
onAction=
"#quitAction"
prefHeight=
"25.0"
prefWidth=
"184.0"
text=
"*QUIT*"
/>
...
...
@@ -281,6 +281,8 @@
<Label
fx:id=
"c0A"
layoutX=
"460.0"
layoutY=
"342.0"
prefHeight=
"67.0"
prefWidth=
"53.0"
text=
"Label"
/>
</children>
</GridPane>
<Label
fx:id=
"occupiedSpace"
layoutX=
"165.0"
layoutY=
"690.0"
prefHeight=
"17.0"
prefWidth=
"734.0"
text=
"Your ships are :"
/>
<Label
fx:id=
"EnemyHM"
layoutX=
"532.0"
layoutY=
"600.0"
prefHeight=
"17.0"
prefWidth=
"368.0"
text=
"Computer: Prepare to die!"
/>
</children>
</AnchorPane>
</children>
...
...
src/BSMain.java
View file @
96b49fcb
...
...
@@ -29,6 +29,8 @@ public class BSMain extends Application{
@FXML
public
ChoiceBox
<
String
>
DPx
;
@FXML
public
ChoiceBox
<
String
>
DPy
;
@FXML
public
ChoiceBox
<
String
>
shipSelection
;
@FXML
public
Label
occupiedSpace
;
@FXML
public
Label
EnemyHM
;
@FXML
private
Button
place
;
...
...
@@ -36,7 +38,7 @@ public class BSMain extends Application{
@FXML
private
Button
battleStage
;
@FXML
private
Button
quit
;
@FXML
public
Label
error
;
@FXML
public
Label
stage
;
@FXML
public
Label
admiral
;
@FXML
public
Label
status
;
...
...
@@ -340,10 +342,17 @@ public class BSMain extends Application{
void
placeAction
(
ActionEvent
event
)
{
if
(
stage0
)
{
String
response
=
""
;
if
(!
playerS
.
ShipPlacer
(
playerS
,
ship
,
x
,
y
).
isEmpty
())
{
admiral
.
setText
(
"Admiral Nutsey: Ship placed at "
+
(
playerS
.
ShipPlacer
(
playerS
,
ship
,
x
,
y
).
toString
())
);
response
=
playerS
.
moves
.
toString
();
admiral
.
setText
(
"Admiral Nutsey: Ship placed at "
+
response
);
playerLabels
[
1
].
setText
(
"Ship placed"
);
}
else
{
admiral
.
setText
(
"Admiral: Ship type is already Placed"
);
}
...
...
@@ -355,22 +364,28 @@ public class BSMain extends Application{
else
if
(
stage1
)
{
admiral
.
setText
(
"Admiral Nutsey: Your in Battle, try *FIRE*"
);
}
occupiedSpace
.
setText
(
playerS
.
allMoves
.
toString
());
}
@FXML
void
fireAction
(
ActionEvent
event
)
{
if
(
playerS
.
allMoves
.
isEmpty
())
{
Boolean
win
=
true
;
stage1
=
false
;
admiral
.
setText
(
"Admiral Nutsey: You have lost :( "
);
EnemyHM
.
setText
(
ComputerInput
.
talk
(
win
));
stage
.
setText
(
"Stage: GAME OVER"
);
}
else
if
(
computerS
.
allMoves
.
isEmpty
())
{
Boolean
win
=
false
;
stage1
=
false
;
admiral
.
setText
(
"Admiral Nutsey: You have won!!! "
);
admiral
.
setText
(
"Admiral Nutsey: You have won!!!"
);
EnemyHM
.
setText
(
ComputerInput
.
talk
(
win
));
}
else
if
(
stage1
)
{
...
...
@@ -380,10 +395,22 @@ public class BSMain extends Application{
+
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
1
);
if
(
playerB
.
fire
(
computerS
,
HmnMove
))
{
admiral
.
setText
(
BattleClass
.
ShipCheck
(
HmnMove
,
computerS
));
admiral
.
setText
(
"Player has "
+
BattleClass
.
ShipCheck
(
HmnMove
,
computerS
));
}
else
if
(!
playerB
.
fire
(
computerS
,
HmnMove
))
{
admiral
.
setText
(
"Player has missed at "
+
HmnMove
);
}
if
(
computerB
.
fire
(
playerS
,
CmptrMove
))
{
admiral
.
setText
(
BattleClass
.
ShipCheck
(
CmptrMove
,
playerS
));
EnemyHM
.
setText
(
"Computer: I have hit "
+
BattleClass
.
ShipCheck
(
CmptrMove
,
playerS
));
}
else
if
(!
computerB
.
fire
(
playerS
,
CmptrMove
))
{
EnemyHM
.
setText
(
"Computer: I have missed at "
+
CmptrMove
);
}
status
.
setText
(
"Computer status: "
+
computerS
.
allMoves
.
size
()
+
" Player Status: "
+
playerS
.
allMoves
.
size
());
...
...
@@ -393,6 +420,8 @@ public class BSMain extends Application{
admiral
.
setText
(
"Place all ships before firing"
);
}
occupiedSpace
.
setText
(
playerS
.
allMoves
.
toString
());
}
@FXML
...
...
@@ -400,6 +429,8 @@ public class BSMain extends Application{
stage0
=
false
;
stage1
=
true
;
admiral
.
setText
(
"Admiral Nutsey: Fire on the enemy"
);
stage
.
setText
(
"Stage: Battle"
);
}
@FXML
...
...
src/BattleClass.java
View file @
96b49fcb
...
...
@@ -12,7 +12,7 @@ public class BattleClass {
if
(
opponent
.
allMoves
.
contains
(
Coordinates
))
{
System
.
out
.
println
(
"Hit on "
+
Coordinates
);
opponent
.
allMoves
.
remove
(
Coordinates
);
hit
=
true
;
...
...
@@ -32,7 +32,7 @@ public class BattleClass {
opponent
.
aC
.
remove
(
coordinates
);
if
(
opponent
.
aC
.
isEmpty
())
{
response
=
(
"
Aircarft one is sunk!
"
);
response
=
(
"
sunk Aircarft one
"
);
}
}
...
...
@@ -41,7 +41,7 @@ public class BattleClass {
opponent
.
bS
.
remove
(
coordinates
);
if
(
opponent
.
bS
.
isEmpty
())
{
response
=
(
"
BattleShip one is sunk!
"
);
response
=
(
"
sunk BattleShip
"
);
}
}
...
...
@@ -50,7 +50,7 @@ public class BattleClass {
opponent
.
bS2
.
remove
(
coordinates
);
if
(
opponent
.
bS2
.
isEmpty
())
{
response
=
(
"
Battleship two is sunk!
"
);
response
=
(
"
sunk Battleship two
"
);
}
}
...
...
@@ -59,7 +59,7 @@ public class BattleClass {
opponent
.
dS
.
remove
(
coordinates
);
if
(
opponent
.
dS
.
isEmpty
())
{
response
=
(
"
Destroyer one is sunk!
"
);
response
=
(
"
sunk Destroyer one
"
);
}
}
...
...
@@ -68,7 +68,7 @@ public class BattleClass {
opponent
.
dS2
.
remove
(
coordinates
);
if
(
opponent
.
dS2
.
isEmpty
())
{
response
=
(
"
Destroyer two is sunk!
"
);
response
=
(
"
sunk Destroyer two
"
);
}
}
...
...
@@ -77,7 +77,7 @@ public class BattleClass {
opponent
.
pB
.
remove
(
coordinates
);
if
(
opponent
.
pB
.
isEmpty
())
{
response
=
(
"
Patrol boat one is sunk
!"
);
response
=
(
"
sunk Patrol boat
!"
);
}
}
...
...
@@ -86,7 +86,7 @@ public class BattleClass {
opponent
.
pB2
.
remove
(
coordinates
);
if
(
opponent
.
pB2
.
isEmpty
())
{
response
=
(
"
Patrol boat two is sunk!
"
);
response
=
(
"
sunk Patrol boat two
"
);
}
}
...
...
@@ -95,7 +95,7 @@ public class BattleClass {
opponent
.
pB3
.
remove
(
coordinates
);
if
(
opponent
.
pB3
.
isEmpty
())
{
response
=
(
"
Patrol boat three is sunk!
"
);
response
=
(
"
sunk Patrol boat three
"
);
}
}
return
response
;
...
...
src/ComputerInput.java
View file @
96b49fcb
...
...
@@ -2,6 +2,21 @@ import java.util.ArrayList;
import
java.util.Random
;
public
class
ComputerInput
{
static
String
cmptrWin
[]
=
{
"DIE"
,
"Yesss"
,
"To easy"
};
static
String
cmptrLose
[]
=
{
"Noooo"
,
"How can this be"
,
"Cheat!"
};
Boolean
win
=
false
;
public
static
String
talk
(
Boolean
win
)
{
String
speach
=
""
;
Random
rand
=
new
Random
();
if
(
win
)
{
speach
=
cmptrWin
[
rand
.
nextInt
(
2
)];
}
else
{
speach
=
cmptrLose
[
rand
.
nextInt
(
2
)];
}
return
speach
;
}
public
static
ArrayList
<
String
>
CoOrdRandomiser
()
{
ArrayList
<
String
>
coOrd
=
new
ArrayList
<
String
>();
...
...
@@ -18,6 +33,7 @@ public class ComputerInput {
}
public
static
void
cmptrMoveGen
()
{
...
...
src/Grid.java
View file @
96b49fcb
...
...
@@ -64,8 +64,9 @@ public class Grid {
}
int
index
=
BSMain
.
ships
.
indexOf
(
shipType
);
if
(!(
index
==
-
1
))
{
usr
.
shipsPlaced
[
index
]
=
true
;
}
}
return
valid
;
}
...
...
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