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.collections.FXCollections;
......@@ -46,6 +46,8 @@ public class BSMain extends Application{
static Grid computerG = new Grid();
static ShipClass playerS = new ShipClass();
static ShipClass computerS = new ShipClass();
static BattleClass playerB = new BattleClass();
static BattleClass computerB = new BattleClass();
Boolean stage0= true;
Boolean stage1=false;
......@@ -123,8 +125,9 @@ public class BSMain extends Application{
String CmptrMove = (String) ComputerInput.CoOrdRandomiser().get(0)
+ (String) ComputerInput.CoOrdRandomiser().get(1);
BattleClass.fire(computerS, HmnMove);
BattleClass.fire(playerS, CmptrMove);
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 =" + playerB.Score + "/" + playerS.allMoves.size());
}
else {
......
......@@ -2,18 +2,20 @@
public class BattleClass {
Boolean win = false;
int playerScore;
int computerScore;
int Score;
public static void fire (ShipClass opponent, String Cordinates) {
public void fire (BattleClass usr, ShipClass opponent, String Cordinates, int score) {
if (!opponent.ScoreKepper(opponent)) {
if(opponent.allMoves.contains(Cordinates)) {
System.out.println("Hit on " + Cordinates);
opponent.allMoves.remove(Cordinates);
usr.Score++;
......@@ -22,14 +24,9 @@ public class BattleClass {
System.out.println("Miss at " + Cordinates );
}
}
else {
System.out.println("Game Finshed");
}
}
public static void sunkCheck() {
......
......@@ -3,8 +3,8 @@ import java.util.Random;
public class ComputerInput {
public static ArrayList CoOrdRandomiser() {
ArrayList coOrd = new ArrayList();
public static ArrayList<String> CoOrdRandomiser() {
ArrayList<String> coOrd = new ArrayList<String>();
Random rand = new Random();
int indexX = rand.nextInt(10);
int indexY = rand.nextInt(10);
......@@ -26,7 +26,7 @@ public class ComputerInput {
String x = (String) CoOrdRandomiser().get(0);
String y = (String) CoOrdRandomiser().get(1);
String coOrd = x + y ;
BSMain.computerS.ShipPlacer(BSMain.computerS,BSMain.ships.get(i),x,y);
......
......@@ -2,9 +2,9 @@ import java.util.ArrayList;
public class Grid {
ArrayList Avblcords = new ArrayList();
static ArrayList xCordL = new ArrayList();
static ArrayList yCordL = new ArrayList();
ArrayList<String> Avblcords = new ArrayList<String>();
static ArrayList<String> xCordL = new ArrayList<String>();
static ArrayList<String> yCordL = new ArrayList<String>();
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"};
......@@ -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 ++ ) {
......@@ -32,10 +32,10 @@ public class Grid {
return z.Avblcords;
}
public boolean MoveValidCheck(Grid inputer, ArrayList moves ) {
public boolean MoveValidCheck(Grid inputer, ArrayList<String> moves ) {
boolean valid = true;
ArrayList validList = new ArrayList();
for (int i=0 ; i < moves.size() ; i++ ) {
......@@ -58,4 +58,5 @@ public class Grid {
}
return valid;
}
}
public class Players {
Grid GC = new Grid();
ShipClass SC = new ShipClass();
BattleClass BC = new BattleClass();
}
import java.util.ArrayList;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class ShipClass {
......@@ -21,27 +18,13 @@ public class ShipClass {
ArrayList<String> moves = 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) {
System.out.println("Ships are" + BSMain.computerS.shipsHealth);
int xIndex = Grid.xCordL.indexOf(x);
int yIndex = Grid.yCordL.indexOf(y);
//int yIndex = Grid.yCordL.indexOf(y);
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