Commit 5fe86d9e authored by Darth Vernon's avatar Darth Vernon

hits now register, score keeping fixed

parent 3893bb5e
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 {
......
...@@ -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() {
......
...@@ -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);
......
...@@ -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;
} }
} }
public class Players {
Grid GC = new Grid();
ShipClass SC = new ShipClass();
BattleClass BC = new BattleClass();
}
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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment