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
f3b4f80c
Commit
f3b4f80c
authored
May 17, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Battle class comments
parent
96685993
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
+10
-8
BattleClass.java
src/BattleClass.java
+10
-8
No files found.
src/BattleClass.java
View file @
f3b4f80c
...
...
@@ -5,34 +5,36 @@ public class BattleClass {
public
Boolean
fire
(
ShipClass
opponent
,
String
Coordinates
)
{
public
Boolean
fire
(
ShipClass
opponent
,
String
Coordinates
)
{
//Takes shipClass object of fired upon player, and the coordinates of that fire.
Boolean
hit
=
false
;
if
(
opponent
.
allMoves
.
contains
(
Coordinates
))
{
//Fire successful
opponent
.
allMoves
.
remove
(
Coordinates
);
opponent
.
allMoves
.
remove
(
Coordinates
);
//Ship destroyed, thus removed.
hit
=
true
;
}
return
hit
;
return
hit
;
//Returns true if hit.
}
public
static
String
ShipCheck
(
String
coordinates
,
ShipClass
opponent
)
{
public
static
String
ShipCheck
(
String
coordinates
,
ShipClass
opponent
)
{
//Takes shipClass object of fired upon player, and the coordinates of that fire.
String
response
=
"Hit "
;
//Only called if hit (from fire) is true, so it is assumed one of the opponent's ship list contains the entered.
if
(
opponent
.
aC
.
contains
(
coordinates
))
{
opponent
.
aC
.
remove
(
coordinates
);
opponent
.
aC
.
remove
(
coordinates
);
//Coordinates are removed, as part of ship is destroyed.
if
(
opponent
.
aC
.
isEmpty
())
{
response
=
(
"sunk Aircarft one"
);
response
=
(
"sunk Aircarft one"
);
//Ship list is empty and can therefore be reported as sunk.
}
}
...
...
@@ -98,7 +100,7 @@ public class BattleClass {
response
=
(
"sunk Patrol boat three"
);
}
}
return
response
;
return
response
;
//Defaults to hit if nothing is sunk.
}
...
...
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