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
96685993
Commit
96685993
authored
May 17, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ship Class comments
parent
c6018061
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
ShipClass.java
src/ShipClass.java
+12
-11
No files found.
src/ShipClass.java
View file @
96685993
...
...
@@ -3,7 +3,7 @@ import java.util.ArrayList;
public
class
ShipClass
{
ArrayList
<
String
>
aC
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
aC
=
new
ArrayList
<
String
>();
//Holds coordinates of each ship
ArrayList
<
String
>
dS
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
dS2
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
bS
=
new
ArrayList
<
String
>();
...
...
@@ -12,7 +12,7 @@ public class ShipClass {
ArrayList
<
String
>
pB2
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
pB3
=
new
ArrayList
<
String
>();
Boolean
aCB
=
false
;
Boolean
aCB
=
false
;
//Booleans to see if a ship is placed or not.
Boolean
dSB
=
false
;
Boolean
dS2B
=
false
;
Boolean
bSB
=
false
;
...
...
@@ -21,16 +21,16 @@ public class ShipClass {
Boolean
pB2B
=
false
;
Boolean
pB3B
=
false
;
Boolean
shipsPlaced
[]
=
{
aCB
,
dSB
,
dS2B
,
bSB
,
bS2B
,
pBB
,
pB2B
,
pB3B
};
Boolean
shipsPlaced
[]
=
{
aCB
,
dSB
,
dS2B
,
bSB
,
bS2B
,
pBB
,
pB2B
,
pB3B
};
//list of booleans for easier access.
ArrayList
<
String
>
moves
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
allMoves
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
moves
=
new
ArrayList
<
String
>();
//Holds current set of moves
ArrayList
<
String
>
allMoves
=
new
ArrayList
<
String
>();
//Holds all placements of player made
String
name
;
public
ArrayList
ShipPlacer
(
ShipClass
plyr
,
String
shipType
,
String
x
,
String
y
)
{
...
...
@@ -39,17 +39,18 @@ public class ShipClass {
int
xIndex
=
Grid
.
xCordL
.
indexOf
(
x
);
//int yIndex = Grid.yCordL.indexOf(y);
plyr
.
moves
.
clear
();
plyr
.
moves
.
clear
();
// Moves are reset every time method is called, to ensure only current placements are stored.
System
.
out
.
println
(
shipType
+
" "
+
x
+
" "
+
y
);
System
.
out
.
println
(
allMoves
.
toString
());
if
(
shipType
==
BSMain
.
ships
.
get
(
0
)
&&
!
plyr
.
shipsPlaced
[
0
])
{
//Each of these if statements varies only by the ship it refers to.
if
(
shipType
==
BSMain
.
ships
.
get
(
0
)
&&
!
plyr
.
shipsPlaced
[
0
])
{
//If users ship input is equal the first index and that ship has not been placed.
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
aC
.
add
(
newCord
);
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
//increase x coordinate by i. This creates the span of the ship.
plyr
.
aC
.
add
(
newCord
);
//Add to relevant lists.
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
...
...
@@ -176,7 +177,7 @@ public class ShipClass {
System
.
out
.
println
(
"Type of ship not valid or already placed for that type"
);
}
return
moves
;
return
moves
;
// returns empty if selected ship is placed.
}
}
...
...
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