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
3914ec7e
Commit
3914ec7e
authored
May 15, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validation sorted, i think, plz be sorted
parent
9ecc4f25
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
+36
-18
BSMain.java
src/BSMain.java
+10
-7
ComputerInput.java
src/ComputerInput.java
+1
-1
Grid.java
src/Grid.java
+5
-1
ShipClass.java
src/ShipClass.java
+20
-9
No files found.
src/BSMain.java
View file @
3914ec7e
...
...
@@ -83,10 +83,12 @@ public class BSMain extends Application{
DPx
.
getSelectionModel
().
selectedItemProperty
().
addListener
((
ObservableValue
,
oldValue
,
newValue
)
->
{
x
=(
newValue
.
toString
());
System
.
out
.
println
(
x
);
});
DPy
.
getSelectionModel
().
selectedItemProperty
().
addListener
((
ObservableValue
,
oldValue
,
newValue
)
->
{
y
=(
newValue
.
toString
());
System
.
out
.
println
(
y
);
});
shipSelection
.
getSelectionModel
().
selectedItemProperty
().
addListener
((
ObservableValue
,
oldValue
,
newValue
)
->
{
...
...
@@ -97,14 +99,15 @@ public class BSMain extends Application{
@FXML
void
placeAction
(
ActionEvent
event
)
{
if
(!
playerG
.
MoveValidCheck
(
playerG
,
playerS
.
moves
,
playerS
)){
admiral
.
setText
(
"Cordinates are taken. not added to grid"
);
}
else
if
(
stage0
)
{
playerS
.
ShipPlacer
(
playerS
,
ship
,
x
,
y
);
if
(
stage0
)
{
playerS
.
ShipPlacer
(
playerS
,
ship
,
x
,
y
);
admiral
.
setText
(
"Admiral Nutsey: Ship placed at "
+
x
+
y
);
if
(!
playerG
.
MoveValidCheck
(
playerG
,
playerS
.
moves
,
playerS
,
ship
)){
admiral
.
setText
(
"Cordinates are taken. not added to grid"
);
}
}
else
if
(
stage1
)
{
...
...
@@ -126,9 +129,9 @@ public class BSMain extends Application{
String
CmptrMove
=
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
0
)
+
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
1
);
playerB
.
fire
(
playerB
,
computerS
,
HmnMove
,
computerB
.
Score
);
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 ="
+
computerB
.
Score
+
"/"
+
playerS
.
allMoves
.
size
()
);
System
.
out
.
println
(
computerS
.
allMoves
.
size
()
+
"Left of Computer ships"
+
playerS
.
allMoves
.
size
()
+
"Left of Player ships"
);
}
else
{
...
...
src/ComputerInput.java
View file @
3914ec7e
...
...
@@ -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
,
BSMain
.
computerS
)
)
{
if
(!
BSMain
.
computerG
.
MoveValidCheck
(
BSMain
.
computerG
,
BSMain
.
computerS
.
moves
,
BSMain
.
computerS
,
BSMain
.
ships
.
get
(
i
)
)
)
{
i
--;
...
...
src/Grid.java
View file @
3914ec7e
...
...
@@ -32,7 +32,7 @@ public class Grid {
return
z
.
Avblcords
;
}
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
<
String
>
moves
,
ShipClass
usr
)
{
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
<
String
>
moves
,
ShipClass
usr
,
String
shipType
)
{
boolean
valid
=
true
;
...
...
@@ -62,6 +62,10 @@ public class Grid {
inputer
.
Avblcords
.
remove
(
moves
.
get
(
i
));
}
int
index
=
BSMain
.
ships
.
indexOf
(
shipType
);
usr
.
shipsPlaced
[
index
]
=
true
;
}
return
valid
;
}
...
...
src/ShipClass.java
View file @
3914ec7e
...
...
@@ -12,6 +12,17 @@ public class ShipClass {
ArrayList
<
String
>
pB2
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
pB3
=
new
ArrayList
<
String
>();
Boolean
aCB
=
false
;
Boolean
dSB
=
false
;
Boolean
dS2B
=
false
;
Boolean
bSB
=
false
;
Boolean
bS2B
=
false
;
Boolean
pBB
=
false
;
Boolean
pB2B
=
false
;
Boolean
pB3B
=
false
;
Boolean
shipsPlaced
[]
=
{
aCB
,
dSB
,
dS2B
,
bSB
,
bS2B
,
pBB
,
pB2B
,
pB3B
};
...
...
@@ -32,7 +43,7 @@ public class ShipClass {
System
.
out
.
println
(
shipType
+
" "
+
x
+
" "
+
y
);
System
.
out
.
println
(
allMoves
.
toString
());
if
(
shipType
==
BSMain
.
ships
.
get
(
0
)
)
{
if
(
shipType
==
BSMain
.
ships
.
get
(
0
)
&&
!
plyr
.
shipsPlaced
[
0
]
)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -49,7 +60,7 @@ public class ShipClass {
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
1
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
1
)
&&
!
plyr
.
shipsPlaced
[
1
]
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -65,7 +76,7 @@ public class ShipClass {
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
2
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
2
)
&&
!
plyr
.
shipsPlaced
[
2
]
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -80,7 +91,7 @@ public class ShipClass {
System
.
out
.
println
(
plyr
.
bS2
.
toString
());
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
3
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
3
)
&&
!
plyr
.
shipsPlaced
[
3
]
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -96,7 +107,7 @@ public class ShipClass {
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
4
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
4
)
&&
!
plyr
.
shipsPlaced
[
4
]
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -111,7 +122,7 @@ public class ShipClass {
System
.
out
.
println
(
plyr
.
dS2
.
toString
());
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
5
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
5
)
&&
!
plyr
.
shipsPlaced
[
5
]
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -125,7 +136,7 @@ public class ShipClass {
System
.
out
.
println
(
plyr
.
pB
.
toString
());
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
6
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
6
)
&&
!
plyr
.
shipsPlaced
[
6
]
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -141,7 +152,7 @@ public class ShipClass {
}
else
if
(
shipType
==
BSMain
.
ships
.
get
(
7
)
)
{
else
if
(
shipType
==
BSMain
.
ships
.
get
(
7
)
&&
!
plyr
.
shipsPlaced
[
7
]
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
newCord
=
Grid
.
xCordL
.
get
(
xIndex
+
i
)
+
y
;
...
...
@@ -160,7 +171,7 @@ public class ShipClass {
else
{
System
.
out
.
println
(
"Type of ship not valid"
);
System
.
out
.
println
(
"Type of ship not valid
or already placed for that type
"
);
}
}
...
...
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