diff --git a/src/battleship/model/Game.java b/src/battleship/model/Game.java index 9d4f190..430bb26 100644 --- a/src/battleship/model/Game.java +++ b/src/battleship/model/Game.java @@ -73,8 +73,8 @@ public class Game { } public Player Play(View view){ - view.setShips(players[0]); - view.setShips(players[1]); + //view.setShips(players[0]); + //view.setShips(players[1]); while(getWinner() == null) { System.out.println(view); Pair move = currentPlayer.chooseMove(); diff --git a/src/battleship/model/player/Human.java b/src/battleship/model/player/Human.java index 3386d79..a5272a1 100644 --- a/src/battleship/model/player/Human.java +++ b/src/battleship/model/player/Human.java @@ -2,6 +2,7 @@ package battleship.model.player; import battleship.utils.Pair; import battleship.utils.Triplet; +import battleship.view.Terminal; import java.util.Scanner; @@ -12,14 +13,13 @@ public class Human extends Player { @Override public Pair chooseMove() { int x = -1, y = -1; - Scanner scanner = new Scanner(System.in); + Scanner scanner = Terminal.scanner; while(!areValid(x,y)) { System.out.println("Veuillez indiquer la coordonée x de votre coup"); x = scanner.nextInt(); System.out.println("Veuillez indiquer la coordonée y de votre coup"); y = scanner.nextInt(); } - scanner.close(); return new Pair<>(x,y); } public boolean areValid(int x,int y){ diff --git a/src/battleship/view/Terminal.java b/src/battleship/view/Terminal.java index ece0807..af9fb3a 100644 --- a/src/battleship/view/Terminal.java +++ b/src/battleship/view/Terminal.java @@ -10,7 +10,7 @@ import java.util.Scanner; public class Terminal extends View { - private Scanner scanner = new Scanner(System.in); + public static Scanner scanner = new Scanner(System.in); public Terminal(Game game) { super(game); diff --git a/src/battleship/view/View.java b/src/battleship/view/View.java index 04de367..9656cc0 100644 --- a/src/battleship/view/View.java +++ b/src/battleship/view/View.java @@ -23,20 +23,22 @@ public abstract class View { @Override public String toString() { ArrayList> moves = game.currentPlayer.getMoves(); - String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ - - - - - - - - - - +\n"; + String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ A B C D E F G H I J +\n"; for(int i = 0; i<10;i++){ - chain += "|"; + chain += i+1; for(int y = 0;y<10;y++){ if(!moves.isEmpty()) { for (Triplet ships : moves) { if (i == ships.getLeft() && y == ships.getMiddle()) { - if (ships.getRight()) + if(ships.getRight()) chain += " !"; else chain += " ."; + }else chain += " _"; + } }else chain += " _"; diff --git a/src/battleship/view/Window.java b/src/battleship/view/Window.java index 2ee5343..72146f6 100644 --- a/src/battleship/view/Window.java +++ b/src/battleship/view/Window.java @@ -3,10 +3,18 @@ package battleship.view; import battleship.model.Game; import battleship.model.player.Player; +import javax.swing.*; + public class Window extends View { + private JFrame frame; + public Window(Game game) { super(game); + this.frame = new JFrame("Battleship"); + frame.setSize(600,400); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setVisible(true); } @Override