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
9ecc4f25
Commit
9ecc4f25
authored
May 15, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validation fully functional
parent
5fe86d9e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
39 deletions
+128
-39
BSMain.java
src/BSMain.java
+3
-2
BattleClass.java
src/BattleClass.java
+79
-7
ComputerInput.java
src/ComputerInput.java
+2
-2
Grid.java
src/Grid.java
+8
-1
ShipClass.java
src/ShipClass.java
+36
-27
No files found.
src/BSMain.java
View file @
9ecc4f25
...
...
@@ -97,7 +97,7 @@ public class BSMain extends Application{
@FXML
void
placeAction
(
ActionEvent
event
)
{
if
(!
playerG
.
MoveValidCheck
(
playerG
,
playerS
.
moves
)){
if
(!
playerG
.
MoveValidCheck
(
playerG
,
playerS
.
moves
,
playerS
)){
admiral
.
setText
(
"Cordinates are taken. not added to grid"
);
}
else
if
(
stage0
)
{
...
...
@@ -110,6 +110,7 @@ public class BSMain extends Application{
else
if
(
stage1
)
{
admiral
.
setText
(
"Your in Battle, try *FIRE*"
);
}
}
...
...
@@ -127,7 +128,7 @@ public class BSMain extends Application{
playerB
.
fire
(
playerB
,
computerS
,
HmnMove
,
computerB
.
Score
);
computerB
.
fire
(
playerB
,
playerS
,
CmptrMove
,
playerB
.
Score
);
System
.
out
.
println
(
"PLAYER SCORE ="
+
playerB
.
Score
+
"/"
+
computerS
.
allMoves
.
size
()
+
" COMPUTER SCORE ="
+
play
erB
.
Score
+
"/"
+
playerS
.
allMoves
.
size
());
System
.
out
.
println
(
"PLAYER SCORE ="
+
playerB
.
Score
+
"/"
+
computerS
.
allMoves
.
size
()
+
" COMPUTER SCORE ="
+
comput
erB
.
Score
+
"/"
+
playerS
.
allMoves
.
size
());
}
else
{
...
...
src/BattleClass.java
View file @
9ecc4f25
...
...
@@ -5,35 +5,107 @@ public class BattleClass {
int
Score
;
public
void
fire
(
BattleClass
usr
,
ShipClass
opponent
,
String
Cordinates
,
int
score
)
{
public
void
fire
(
BattleClass
usr
,
ShipClass
opponent
,
String
Co
o
rdinates
,
int
score
)
{
if
(
opponent
.
allMoves
.
contains
(
Cordinates
))
{
if
(
opponent
.
allMoves
.
contains
(
Co
o
rdinates
))
{
System
.
out
.
println
(
"Hit on "
+
Cordinates
);
opponent
.
allMoves
.
remove
(
Cordinates
);
System
.
out
.
println
(
"Hit on "
+
Co
o
rdinates
);
opponent
.
allMoves
.
remove
(
Co
o
rdinates
);
usr
.
Score
++;
ShipCheck
(
Coordinates
,
opponent
);
}
else
{
System
.
out
.
println
(
"Miss at "
+
Cordinates
);
System
.
out
.
println
(
"Miss at "
+
Coordinates
);
}
}
public
static
void
ShipCheck
(
String
coordinates
,
ShipClass
opponent
)
{
System
.
out
.
println
(
"Called"
);
if
(
opponent
.
aC
.
contains
(
coordinates
))
{
opponent
.
aC
.
remove
(
coordinates
);
if
(
opponent
.
aC
.
isEmpty
())
{
System
.
out
.
println
(
"Aircarft one is sunk!"
);
}
}
if
(
opponent
.
bS
.
contains
(
coordinates
))
{
opponent
.
bS
.
remove
(
coordinates
);
if
(
opponent
.
bS
.
isEmpty
())
{
System
.
out
.
println
(
"BattleShip one is sunk!"
);
}
}
if
(
opponent
.
bS2
.
contains
(
coordinates
))
{
public
static
void
sunkCheck
()
{
opponent
.
bS2
.
remove
(
coordinates
);
if
(
opponent
.
bS2
.
isEmpty
())
{
System
.
out
.
println
(
"Battleship two is sunk!"
);
}
}
if
(
opponent
.
dS
.
contains
(
coordinates
))
{
opponent
.
dS
.
remove
(
coordinates
);
if
(
opponent
.
dS
.
isEmpty
())
{
System
.
out
.
println
(
"Destroyer one is sunk!"
);
}
}
if
(
opponent
.
dS2
.
contains
(
coordinates
))
{
opponent
.
dS2
.
remove
(
coordinates
);
if
(
opponent
.
dS2
.
isEmpty
())
{
System
.
out
.
println
(
"Destroyer two is sunk!"
);
}
}
if
(
opponent
.
pB
.
contains
(
coordinates
))
{
opponent
.
pB
.
remove
(
coordinates
);
if
(
opponent
.
pB
.
isEmpty
())
{
System
.
out
.
println
(
"Patrol boat one is sunk!"
);
}
}
if
(
opponent
.
pB2
.
contains
(
coordinates
))
{
opponent
.
pB2
.
remove
(
coordinates
);
if
(
opponent
.
pB2
.
isEmpty
())
{
System
.
out
.
println
(
"Patrol boat two is sunk!"
);
}
}
if
(
opponent
.
pB3
.
contains
(
coordinates
))
{
opponent
.
pB3
.
remove
(
coordinates
);
if
(
opponent
.
pB3
.
isEmpty
())
{
System
.
out
.
println
(
"Patrol boat three is sunk!"
);
}
}
}
}
...
...
src/ComputerInput.java
View file @
9ecc4f25
...
...
@@ -30,7 +30,7 @@ public class ComputerInput {
BSMain
.
computerS
.
ShipPlacer
(
BSMain
.
computerS
,
BSMain
.
ships
.
get
(
i
),
x
,
y
);
if
(!
BSMain
.
computerG
.
MoveValidCheck
(
BSMain
.
computerG
,
BSMain
.
computerS
.
moves
)
)
{
if
(!
BSMain
.
computerG
.
MoveValidCheck
(
BSMain
.
computerG
,
BSMain
.
computerS
.
moves
,
BSMain
.
computerS
)
)
{
i
--;
...
...
@@ -39,7 +39,7 @@ public class ComputerInput {
}
System
.
out
.
println
(
BSMain
.
computerS
.
allMoves
.
toString
());
}
}
src/Grid.java
View file @
9ecc4f25
...
...
@@ -32,7 +32,7 @@ public class Grid {
return
z
.
Avblcords
;
}
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
<
String
>
moves
)
{
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
<
String
>
moves
,
ShipClass
usr
)
{
boolean
valid
=
true
;
...
...
@@ -45,6 +45,13 @@ public class Grid {
valid
=
false
;
i
=
moves
.
size
();
System
.
out
.
println
(
move
+
"Rejected"
);
for
(
int
j
=
0
;
j
<
moves
.
size
()
;
j
++
)
{
usr
.
allMoves
.
remove
(
moves
.
get
(
j
));
}
}}
...
...
src/ShipClass.java
View file @
9ecc4f25
...
...
@@ -14,7 +14,7 @@ public class ShipClass {
ArrayList
<
ArrayList
<
String
>>
shipsHealth
=
new
ArrayList
<
ArrayList
<
String
>>();
ArrayList
<
String
>
moves
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
allMoves
=
new
ArrayList
<
String
>();
...
...
@@ -22,7 +22,7 @@ public class ShipClass {
String
name
;
public
void
ShipPlacer
(
ShipClass
plyr
,
String
shipType
,
String
x
,
String
y
)
{
System
.
out
.
println
(
"Ships are"
+
BSMain
.
computerS
.
shipsHealth
);
int
xIndex
=
Grid
.
xCordL
.
indexOf
(
x
);
//int yIndex = Grid.yCordL.indexOf(y);
...
...
@@ -36,14 +36,15 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
aC
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
aC
=
plyr
.
moves
;
plyr
.
moves
=
plyr
.
aC
;
plyr
.
shipsHealth
.
add
(
plyr
.
aC
);
System
.
out
.
println
(
plyr
.
aC
.
toString
());
}
...
...
@@ -52,13 +53,14 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
bS
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
moves
=
plyr
.
bS
;
plyr
.
shipsHealth
.
add
(
plyr
.
bS
);
plyr
.
bS
=
plyr
.
moves
;
System
.
out
.
println
(
plyr
.
bS
.
toString
());
}
...
...
@@ -67,26 +69,29 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
bS2
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
bS2
=
plyr
.
moves
;
plyr
.
moves
=
plyr
.
bS2
;
plyr
.
shipsHealth
.
add
(
plyr
.
bS2
);
System
.
out
.
println
(
plyr
.
bS2
.
toString
());
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
3
)
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
dS
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
dS
=
plyr
.
moves
;
plyr
.
moves
=
plyr
.
dS
;
plyr
.
shipsHealth
.
add
(
plyr
.
dS
);
System
.
out
.
println
(
plyr
.
dS
.
toString
());
}
...
...
@@ -95,13 +100,14 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
dS2
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
dS2
=
plyr
.
moves
;
plyr
.
moves
=
plyr
.
dS2
;
plyr
.
shipsHealth
.
add
(
plyr
.
dS2
);
System
.
out
.
println
(
plyr
.
dS2
.
toString
());
}
...
...
@@ -109,11 +115,12 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
pB
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
pB
=
plyr
.
moves
;
System
.
out
.
println
(
plyr
.
pB
.
toString
());
...
...
@@ -122,13 +129,14 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
pB2
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
pB2
=
plyr
.
moves
;
plyr
.
moves
=
plyr
.
pB2
;
plyr
.
shipsHealth
.
add
(
plyr
.
pB2
);
System
.
out
.
println
(
plyr
.
pB2
.
toString
());
}
...
...
@@ -137,13 +145,14 @@ public class ShipClass {
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
plyr
.
pB3
.
add
(
newCord
);
plyr
.
moves
.
add
(
newCord
);
plyr
.
allMoves
.
add
(
newCord
);
}
plyr
.
pB3
=
plyr
.
moves
;
plyr
.
moves
=
plyr
.
pB3
;
plyr
.
shipsHealth
.
add
(
plyr
.
pB3
);
System
.
out
.
println
(
plyr
.
pB3
.
toString
());
...
...
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