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
5fe86d9e
Commit
5fe86d9e
authored
May 15, 2019
by
Darth Vernon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hits now register, score keeping fixed
parent
3893bb5e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
42 deletions
+33
-42
BSMain.java
src/BSMain.java
+6
-3
BattleClass.java
src/BattleClass.java
+8
-11
ComputerInput.java
src/ComputerInput.java
+3
-3
Grid.java
src/Grid.java
+7
-6
Players.java
src/Players.java
+7
-0
ShipClass.java
src/ShipClass.java
+2
-19
No files found.
src/BSMain.java
View file @
5fe86d9e
import
java.util.ArrayList
;
import
javafx.application.Application
;
import
javafx.application.Application
;
import
javafx.collections.FXCollections
;
import
javafx.collections.FXCollections
;
...
@@ -46,6 +46,8 @@ public class BSMain extends Application{
...
@@ -46,6 +46,8 @@ public class BSMain extends Application{
static
Grid
computerG
=
new
Grid
();
static
Grid
computerG
=
new
Grid
();
static
ShipClass
playerS
=
new
ShipClass
();
static
ShipClass
playerS
=
new
ShipClass
();
static
ShipClass
computerS
=
new
ShipClass
();
static
ShipClass
computerS
=
new
ShipClass
();
static
BattleClass
playerB
=
new
BattleClass
();
static
BattleClass
computerB
=
new
BattleClass
();
Boolean
stage0
=
true
;
Boolean
stage0
=
true
;
Boolean
stage1
=
false
;
Boolean
stage1
=
false
;
...
@@ -123,8 +125,9 @@ public class BSMain extends Application{
...
@@ -123,8 +125,9 @@ public class BSMain extends Application{
String
CmptrMove
=
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
0
)
String
CmptrMove
=
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
0
)
+
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
1
);
+
(
String
)
ComputerInput
.
CoOrdRandomiser
().
get
(
1
);
BattleClass
.
fire
(
computerS
,
HmnMove
);
playerB
.
fire
(
playerB
,
computerS
,
HmnMove
,
computerB
.
Score
);
BattleClass
.
fire
(
playerS
,
CmptrMove
);
computerB
.
fire
(
playerB
,
playerS
,
CmptrMove
,
playerB
.
Score
);
System
.
out
.
println
(
"PLAYER SCORE ="
+
playerB
.
Score
+
"/"
+
computerS
.
allMoves
.
size
()
+
" COMPUTER SCORE ="
+
playerB
.
Score
+
"/"
+
playerS
.
allMoves
.
size
());
}
}
else
{
else
{
...
...
src/BattleClass.java
View file @
5fe86d9e
...
@@ -2,18 +2,20 @@
...
@@ -2,18 +2,20 @@
public
class
BattleClass
{
public
class
BattleClass
{
Boolean
win
=
false
;
Boolean
win
=
false
;
int
playerScore
;
int
Score
;
int
computerScore
;
public
void
fire
(
BattleClass
usr
,
ShipClass
opponent
,
String
Cordinates
,
int
score
)
{
public
static
void
fire
(
ShipClass
opponent
,
String
Cordinates
)
{
if
(!
opponent
.
ScoreKepper
(
opponent
))
{
if
(
opponent
.
allMoves
.
contains
(
Cordinates
))
{
if
(
opponent
.
allMoves
.
contains
(
Cordinates
))
{
System
.
out
.
println
(
"Hit on "
+
Cordinates
);
System
.
out
.
println
(
"Hit on "
+
Cordinates
);
opponent
.
allMoves
.
remove
(
Cordinates
);
opponent
.
allMoves
.
remove
(
Cordinates
);
usr
.
Score
++;
...
@@ -22,14 +24,9 @@ public class BattleClass {
...
@@ -22,14 +24,9 @@ public class BattleClass {
System
.
out
.
println
(
"Miss at "
+
Cordinates
);
System
.
out
.
println
(
"Miss at "
+
Cordinates
);
}
}
}
else
{
System
.
out
.
println
(
"Game Finshed"
);
}
}
}
public
static
void
sunkCheck
()
{
public
static
void
sunkCheck
()
{
...
...
src/ComputerInput.java
View file @
5fe86d9e
...
@@ -3,8 +3,8 @@ import java.util.Random;
...
@@ -3,8 +3,8 @@ import java.util.Random;
public
class
ComputerInput
{
public
class
ComputerInput
{
public
static
ArrayList
CoOrdRandomiser
()
{
public
static
ArrayList
<
String
>
CoOrdRandomiser
()
{
ArrayList
coOrd
=
new
ArrayList
();
ArrayList
<
String
>
coOrd
=
new
ArrayList
<
String
>
();
Random
rand
=
new
Random
();
Random
rand
=
new
Random
();
int
indexX
=
rand
.
nextInt
(
10
);
int
indexX
=
rand
.
nextInt
(
10
);
int
indexY
=
rand
.
nextInt
(
10
);
int
indexY
=
rand
.
nextInt
(
10
);
...
@@ -26,7 +26,7 @@ public class ComputerInput {
...
@@ -26,7 +26,7 @@ public class ComputerInput {
String
x
=
(
String
)
CoOrdRandomiser
().
get
(
0
);
String
x
=
(
String
)
CoOrdRandomiser
().
get
(
0
);
String
y
=
(
String
)
CoOrdRandomiser
().
get
(
1
);
String
y
=
(
String
)
CoOrdRandomiser
().
get
(
1
);
String
coOrd
=
x
+
y
;
BSMain
.
computerS
.
ShipPlacer
(
BSMain
.
computerS
,
BSMain
.
ships
.
get
(
i
),
x
,
y
);
BSMain
.
computerS
.
ShipPlacer
(
BSMain
.
computerS
,
BSMain
.
ships
.
get
(
i
),
x
,
y
);
...
...
src/Grid.java
View file @
5fe86d9e
...
@@ -2,9 +2,9 @@ import java.util.ArrayList;
...
@@ -2,9 +2,9 @@ import java.util.ArrayList;
public
class
Grid
{
public
class
Grid
{
ArrayList
Avblcords
=
new
ArrayList
();
ArrayList
<
String
>
Avblcords
=
new
ArrayList
<
String
>
();
static
ArrayList
xCordL
=
new
ArrayList
();
static
ArrayList
<
String
>
xCordL
=
new
ArrayList
<
String
>
();
static
ArrayList
yCordL
=
new
ArrayList
();
static
ArrayList
<
String
>
yCordL
=
new
ArrayList
<
String
>
();
static
String
xCord
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
};
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"
};
static
String
yCord
[]
=
{
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
};
...
@@ -12,7 +12,7 @@ public class Grid {
...
@@ -12,7 +12,7 @@ public class Grid {
public
static
ArrayList
CoOrdGen
(
Grid
z
)
{
public
ArrayList
<
String
>
CoOrdGen
(
Grid
z
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
...
@@ -32,10 +32,10 @@ public class Grid {
...
@@ -32,10 +32,10 @@ public class Grid {
return
z
.
Avblcords
;
return
z
.
Avblcords
;
}
}
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
moves
)
{
public
boolean
MoveValidCheck
(
Grid
inputer
,
ArrayList
<
String
>
moves
)
{
boolean
valid
=
true
;
boolean
valid
=
true
;
ArrayList
validList
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
moves
.
size
()
;
i
++
)
{
for
(
int
i
=
0
;
i
<
moves
.
size
()
;
i
++
)
{
...
@@ -58,4 +58,5 @@ public class Grid {
...
@@ -58,4 +58,5 @@ public class Grid {
}
}
return
valid
;
return
valid
;
}
}
}
}
src/Players.java
0 → 100644
View file @
5fe86d9e
public
class
Players
{
Grid
GC
=
new
Grid
();
ShipClass
SC
=
new
ShipClass
();
BattleClass
BC
=
new
BattleClass
();
}
src/ShipClass.java
View file @
5fe86d9e
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
javafx.collections.FXCollections
;
import
javafx.collections.ObservableList
;
public
class
ShipClass
{
public
class
ShipClass
{
...
@@ -21,27 +18,13 @@ public class ShipClass {
...
@@ -21,27 +18,13 @@ public class ShipClass {
ArrayList
<
String
>
moves
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
moves
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
allMoves
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
allMoves
=
new
ArrayList
<
String
>();
int
score
;
Boolean
win
;
String
name
;
public
Boolean
ScoreKepper
(
ShipClass
plyr
)
{
plyr
.
score
++;
if
(
plyr
.
score
==
10
)
{
win
=
true
;
System
.
out
.
println
(
name
+
" has won!"
);
}
return
win
;
}
String
name
;
public
void
ShipPlacer
(
ShipClass
plyr
,
String
shipType
,
String
x
,
String
y
)
{
public
void
ShipPlacer
(
ShipClass
plyr
,
String
shipType
,
String
x
,
String
y
)
{
System
.
out
.
println
(
"Ships are"
+
BSMain
.
computerS
.
shipsHealth
);
System
.
out
.
println
(
"Ships are"
+
BSMain
.
computerS
.
shipsHealth
);
int
xIndex
=
Grid
.
xCordL
.
indexOf
(
x
);
int
xIndex
=
Grid
.
xCordL
.
indexOf
(
x
);
int
yIndex
=
Grid
.
yCordL
.
indexOf
(
y
);
//
int yIndex = Grid.yCordL.indexOf(y);
plyr
.
moves
.
clear
();
plyr
.
moves
.
clear
();
...
...
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