thisSea.setWidth((50*length)-5);// sets up tiles accordingly
thisSea.setHeight(45);
thisSea.setWidth((50*length)-5);// sets up tiles accordingly
thisSea.setHeight(45);
for(intk=0;k<length;k++){
board[thisSea.x+k][thisSea.y]=shipsPlaced+1;
}
...
...
@@ -194,7 +221,7 @@ public class Main extends Application{
thisSeaCom.setWidth(45);
thisSeaCom.setHeight(45);
thisSeaCom.setCursor(Cursor.HAND);
thisSeaCom.setFill(Color.GREY);// differect colour to allied, otherwise the same creation
thisSeaCom.setFill(Color.GREY);// different colour to allied, otherwise the same creation
thisSeaCom.setOnMouseClicked(event->{// when the user shoots at a com ship
...
...
@@ -271,10 +298,7 @@ public class Main extends Application{
Randomrng=newRandom();// sets up rng
intx=rng.nextInt(10);// generates random coordinates
inty=rng.nextInt(10);
BooleancpuHorizontal=rng.nextBoolean();// randomly desides if current ship being placed is vertical or horizontal
BooleanpotentialLegalSpace=false;
BooleanlegalSpace=false;
intlegalSpaceCount=0;
BooleancpuHorizontal=rng.nextBoolean();// randomly decides if current ship being placed is vertical or horizontal
if(carriersCom>0)// variant of code above, checks each ship type and places accordingly
{
...
...
@@ -302,38 +326,7 @@ public class Main extends Application{
boatHPCom[shipsPlacedCom+1]=2;
}
if(cpuHorizontal==true&&x+lengthCPU<=10)// legal space validation is the same with the computers variables
{
potentialLegalSpace=true;
}
elseif(cpuHorizontal==false&&y+lengthCPU<=10)// checks are the same as above swapping out the user input isShiftDown for a variable to determine the same