From eddd1940f81a822c3fc7481cf36d4f4b9346158e Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 6 Apr 2021 10:36:47 +0200 Subject: [PATCH] delete Add View.placeShipRandomly (already in Player.java) --- src/battleship/model/player/Player.java | 4 ++-- src/battleship/view/Terminal.java | 2 +- src/battleship/view/View.java | 10 ---------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/battleship/model/player/Player.java b/src/battleship/model/player/Player.java index fab9ec6..33789be 100644 --- a/src/battleship/model/player/Player.java +++ b/src/battleship/model/player/Player.java @@ -92,11 +92,11 @@ public abstract class Player { return id; } - public void placeShipRandomly(Player player) { + public void placeShipRandomly() { Random rand = new Random(); for(int i : bato) { Ship ship = null; - while(ship == null || !player.setShips(ship)) { + while(ship == null || !setShips(ship)) { ship = new Ship(new Pair<>(rand.nextInt(10), rand.nextInt(10)), i, Direction.values()[rand.nextInt(Direction.values().length)]); } } diff --git a/src/battleship/view/Terminal.java b/src/battleship/view/Terminal.java index 96f6554..38eb3bb 100644 --- a/src/battleship/view/Terminal.java +++ b/src/battleship/view/Terminal.java @@ -54,7 +54,7 @@ public class Terminal extends View { } } else { // Random - placeShipRandomly(player); + player.placeShipRandomly(); } diff --git a/src/battleship/view/View.java b/src/battleship/view/View.java index c232910..263b05e 100644 --- a/src/battleship/view/View.java +++ b/src/battleship/view/View.java @@ -25,16 +25,6 @@ public abstract class View { public abstract void displayBoard(); - public void placeShipRandomly(Player player) { - Random rand = new Random(); - for(int i : ships) { - Ship ship = null; - while(ship == null || !player.setShips(ship)) { - ship = new Ship(new Pair<>(rand.nextInt(10), rand.nextInt(10)), i, Direction.values()[rand.nextInt(Direction.values().length)]); - } - } - } - @Override public String toString() { // String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ - - - - - - - - - - +\n";