diff --git a/src/battleship/model/Game.java b/src/battleship/model/Game.java index 9d4f190..21b1dc0 100644 --- a/src/battleship/model/Game.java +++ b/src/battleship/model/Game.java @@ -75,6 +75,7 @@ public class Game { public Player Play(View view){ view.setShips(players[0]); view.setShips(players[1]); + System.out.println(view.toString()); while(getWinner() == null) { System.out.println(view); Pair move = currentPlayer.chooseMove(); diff --git a/src/battleship/view/View.java b/src/battleship/view/View.java index 2697562..c232910 100644 --- a/src/battleship/view/View.java +++ b/src/battleship/view/View.java @@ -25,7 +25,7 @@ public abstract class View { public abstract void displayBoard(); - protected void placeShipRandomly(Player player) { + public void placeShipRandomly(Player player) { Random rand = new Random(); for(int i : ships) { Ship ship = null; @@ -37,29 +37,36 @@ public abstract class View { @Override public String toString() { - ArrayList> moves = game.currentPlayer.getMoves(); - String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ - - - - - - - - - - +\n"; - - for(AtomicInteger i = new AtomicInteger(0); i.get() < 10;i.incrementAndGet()) { - chain += "|"; - for(AtomicInteger y = new AtomicInteger(0);y.get() < 10; y.incrementAndGet()) { - if(!moves.isEmpty()) { - Triplet move = moves.stream().filter(p -> p.getLeft() == i.get() && p.getMiddle() == y.get()).findFirst().orElse(null); - if(move != null) { - if (move.getRight()) - chain += " !"; - else - chain += " ."; - } else { - chain += " _"; - } - }else { - chain += " _"; + // String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ - - - - - - - - - - +\n"; + String chain = ""; + for(int u = 0; u < 2; ++u) { + ArrayList> moves = game.players[u].getMoves(); + chain += "Player " + (u + 1) + " :\n"; + chain += "+ - - - - - - - - - - +\n"; + for(int i = 0; i < 10;++i) { + chain += "|"; + for(int y = 0;y < 10; ++y) { + if(!moves.isEmpty()) { + for(Triplet move : moves) { + if(move.getLeft() == i && move.getMiddle() == y) { + if (move.getRight()) + chain += " !"; + else + chain += " ."; + } else { + chain += " _"; + } + break; + } + } else { + chain += " _"; + } } + chain += " |\n"; } - chain += " |\n"; + chain += "+ - - - - - - - - - - +\n"; } - chain += "+ - - - - - - - - - - +\n"; + return chain; }