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
d2bd455e
Commit
d2bd455e
authored
May 15, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
placement modified to work with sunk - currently works.
parent
3914ec7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
35 deletions
+47
-35
BSMain.java
src/BSMain.java
+17
-6
BattleClass.java
src/BattleClass.java
+12
-13
ShipClass.java
src/ShipClass.java
+18
-16
No files found.
src/BSMain.java
View file @
d2bd455e
...
...
@@ -44,7 +44,7 @@ public class BSMain extends Application{
static
Grid
playerG
=
new
Grid
();
static
Grid
computerG
=
new
Grid
();
static
ShipClass
playerS
=
new
ShipClass
();
ShipClass
playerS
=
new
ShipClass
();
static
ShipClass
computerS
=
new
ShipClass
();
static
BattleClass
playerB
=
new
BattleClass
();
static
BattleClass
computerB
=
new
BattleClass
();
...
...
@@ -129,15 +129,27 @@ public class BSMain extends Application{
String
CmptrMove
=
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
0
)
+
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
1
);
playerB
.
fire
(
playerB
,
computerS
,
HmnMove
,
computerB
.
Scor
e
);
computerB
.
fire
(
player
B
,
playerS
,
CmptrMove
,
playerB
.
Scor
e
);
playerB
.
fire
(
computerS
,
HmnMov
e
);
computerB
.
fire
(
player
S
,
CmptrMov
e
);
System
.
out
.
println
(
computerS
.
allMoves
.
size
()
+
"Left of Computer ships"
+
playerS
.
allMoves
.
size
()
+
"Left of Player ships"
);
}
else
{
else
if
(
stage0
)
{
admiral
.
setText
(
"Place all ships before firing"
);
}
else
if
(
playerS
.
allMoves
.
isEmpty
())
{
stage1
=
false
;
admiral
.
setText
(
"You have lost :( "
);
}
else
if
(
computerS
.
allMoves
.
isEmpty
())
{
stage1
=
false
;
admiral
.
setText
(
"You have lost won!!! "
);
}
else
{
error
.
setText
(
"The Game has ended, press *QUIT*"
);
}
}
@FXML
...
...
@@ -164,8 +176,7 @@ public class BSMain extends Application{
playerG
.
CoOrdGen
(
playerG
);
computerG
.
CoOrdGen
(
computerG
);
ComputerInput
.
cmptrMoveGen
();
playerS
.
name
=
"PLAYER"
;
computerS
.
name
=
"COMPUTER"
;
launch
(
args
);
...
...
src/BattleClass.java
View file @
d2bd455e
public
class
BattleClass
{
Boolean
win
=
false
;
int
Score
;
public
void
fire
(
BattleClass
usr
,
ShipClass
opponent
,
String
Coordinates
,
int
score
)
{
public
void
fire
(
ShipClass
opponent
,
String
Coordinates
)
{
...
...
@@ -14,7 +14,6 @@ public class BattleClass {
System
.
out
.
println
(
"Hit on "
+
Coordinates
);
opponent
.
allMoves
.
remove
(
Coordinates
);
usr
.
Score
++;
ShipCheck
(
Coordinates
,
opponent
);
...
...
@@ -28,9 +27,9 @@ public class BattleClass {
}
public
static
void
ShipCheck
(
String
coordinates
,
ShipClass
opponent
)
{
public
void
ShipCheck
(
String
coordinates
,
ShipClass
opponent
)
{
System
.
out
.
println
(
"Called"
);
if
(
opponent
.
aC
.
contains
(
coordinates
))
{
opponent
.
aC
.
remove
(
coordinates
);
...
...
@@ -40,7 +39,7 @@ public class BattleClass {
}
}
if
(
opponent
.
bS
.
contains
(
coordinates
))
{
else
if
(
opponent
.
bS
.
contains
(
coordinates
))
{
opponent
.
bS
.
remove
(
coordinates
);
...
...
@@ -49,7 +48,7 @@ public class BattleClass {
}
}
if
(
opponent
.
bS2
.
contains
(
coordinates
))
{
else
if
(
opponent
.
bS2
.
contains
(
coordinates
))
{
opponent
.
bS2
.
remove
(
coordinates
);
...
...
@@ -58,7 +57,7 @@ public class BattleClass {
}
}
if
(
opponent
.
dS
.
contains
(
coordinates
))
{
else
if
(
opponent
.
dS
.
contains
(
coordinates
))
{
opponent
.
dS
.
remove
(
coordinates
);
...
...
@@ -67,7 +66,7 @@ public class BattleClass {
}
}
if
(
opponent
.
dS2
.
contains
(
coordinates
))
{
else
if
(
opponent
.
dS2
.
contains
(
coordinates
))
{
opponent
.
dS2
.
remove
(
coordinates
);
...
...
@@ -76,7 +75,7 @@ public class BattleClass {
}
}
if
(
opponent
.
pB
.
contains
(
coordinates
))
{
else
if
(
opponent
.
pB
.
contains
(
coordinates
))
{
opponent
.
pB
.
remove
(
coordinates
);
...
...
@@ -85,7 +84,7 @@ public class BattleClass {
}
}
if
(
opponent
.
pB2
.
contains
(
coordinates
))
{
else
if
(
opponent
.
pB2
.
contains
(
coordinates
))
{
opponent
.
pB2
.
remove
(
coordinates
);
...
...
@@ -94,7 +93,7 @@ public class BattleClass {
}
}
if
(
opponent
.
pB3
.
contains
(
coordinates
))
{
else
if
(
opponent
.
pB3
.
contains
(
coordinates
))
{
opponent
.
pB3
.
remove
(
coordinates
);
...
...
src/ShipClass.java
View file @
d2bd455e
...
...
@@ -34,6 +34,8 @@ public class ShipClass {
public
void
ShipPlacer
(
ShipClass
plyr
,
String
shipType
,
String
x
,
String
y
)
{
System
.
out
.
println
(
"this one "
+
plyr
.
aC
.
toString
()
+
plyr
.
dS
.
toString
()
+
plyr
.
dS2
.
toString
());
int
xIndex
=
Grid
.
xCordL
.
indexOf
(
x
);
//int yIndex = Grid.yCordL.indexOf(y);
...
...
@@ -47,13 +49,13 @@ 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
;
System
.
out
.
println
(
plyr
.
aC
.
toString
());
...
...
@@ -64,13 +66,13 @@ 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
.
bS
=
plyr
.
moves
;
System
.
out
.
println
(
plyr
.
bS
.
toString
());
...
...
@@ -80,12 +82,12 @@ 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
;
...
...
@@ -95,12 +97,12 @@ public class ShipClass {
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
;
System
.
out
.
println
(
plyr
.
dS
.
toString
());
...
...
@@ -111,12 +113,12 @@ 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
;
System
.
out
.
println
(
plyr
.
dS2
.
toString
());
...
...
@@ -126,12 +128,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
());
...
...
@@ -140,12 +142,12 @@ 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
;
System
.
out
.
println
(
plyr
.
pB2
.
toString
());
...
...
@@ -156,12 +158,12 @@ 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
;
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