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
85916d50
Commit
85916d50
authored
May 17, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grid comments
parent
a0fb468d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
Grid.java
src/Grid.java
+14
-14
No files found.
src/Grid.java
View file @
85916d50
...
...
@@ -2,9 +2,9 @@ import java.util.ArrayList;
public
class
Grid
{
ArrayList
<
String
>
Avblcords
=
new
ArrayList
<
String
>();
static
ArrayList
<
String
>
xCordL
=
new
ArrayList
<
String
>();
static
ArrayList
<
String
>
yCordL
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
Avblcords
=
new
ArrayList
<
String
>();
//Holds coordinates of which user is allowed to use.
static
ArrayList
<
String
>
xCordL
=
new
ArrayList
<
String
>();
//Holds X coordinates
static
ArrayList
<
String
>
yCordL
=
new
ArrayList
<
String
>();
//Holds Y coordinates
static
String
xCord
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
};
static
String
yCord
[]
=
{
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
};
...
...
@@ -12,9 +12,9 @@ public class Grid {
public
ArrayList
<
String
>
CoOrdGen
(
Grid
z
)
{
public
ArrayList
<
String
>
CoOrdGen
(
Grid
z
)
{
//Takes a grid object and generates a list of available coordinates.
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
//Loads arrays into more useful ArrayLists.
yCordL
.
add
(
yCord
[
i
]);
xCordL
.
add
(
xCord
[
i
]);
...
...
@@ -22,7 +22,7 @@ public class Grid {
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
//Loops through both x and y lists to generate the entire grid.
String
letter
=
yCord
[
i
];
for
(
int
j
=
0
;
j
<
10
;
j
++
)
{
String
number
=
xCord
[
j
];
...
...
@@ -34,21 +34,21 @@ public class Grid {
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
<
String
>
moves
,
ShipClass
usr
,
String
shipType
)
{
boolean
valid
=
true
;
boolean
valid
=
true
;
//Coordinates assumed to be valid until proven otherwise.
for
(
int
i
=
0
;
i
<
moves
.
size
()
;
i
++
)
{
String
move
=
(
String
)
moves
.
get
(
i
);
String
move
=
(
String
)
moves
.
get
(
i
);
//Takes each move from moves to test individually.
if
(!
inputer
.
Avblcords
.
contains
(
move
)
&&
(
valid
))
{
if
(!
inputer
.
Avblcords
.
contains
(
move
)
&&
(
valid
))
{
//If move is not in the grid objects available coordinates it is rejected.
valid
=
false
;
valid
=
false
;
//Stops all checking and renders entire list of moves as invalid.
i
=
moves
.
size
();
System
.
out
.
println
(
move
+
"Rejected"
);
for
(
int
j
=
0
;
j
<
moves
.
size
()
;
j
++
)
{
usr
.
allMoves
.
remove
(
moves
.
get
(
j
));
usr
.
allMoves
.
remove
(
moves
.
get
(
j
));
//Invalid moves are removed from ships class objects All moves list.
}
...
...
@@ -59,13 +59,13 @@ public class Grid {
for
(
int
i
=
0
;
i
<
moves
.
size
()
;
i
++
)
{
inputer
.
Avblcords
.
remove
(
moves
.
get
(
i
));
inputer
.
Avblcords
.
remove
(
moves
.
get
(
i
));
//Removes from available Coordinates so, they can't be used again.
}
int
index
=
BSMain
.
ships
.
indexOf
(
shipType
);
if
(!(
index
==
-
1
))
{
usr
.
shipsPlaced
[
index
]
=
true
;
if
(!(
index
==
-
1
))
{
//Averts out of bounds error.
usr
.
shipsPlaced
[
index
]
=
true
;
//Sets as true so that ship can't be placed again.
}
}
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