Merge branch 'master' of https://forge.info.unicaen.fr/git/legot-lalong-page-boyon
This commit is contained in:
commit
77d0c0946e
@ -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<Integer,Integer> move = currentPlayer.chooseMove();
|
||||
|
@ -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<Integer,Integer> 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){
|
||||
|
@ -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);
|
||||
|
@ -23,9 +23,9 @@ public abstract class View {
|
||||
@Override
|
||||
public String toString() {
|
||||
ArrayList<Triplet<Integer,Integer,Boolean>> 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<Integer, Integer, Boolean> ships : moves) {
|
||||
@ -35,8 +35,10 @@ public abstract class View {
|
||||
else
|
||||
chain += " .";
|
||||
|
||||
|
||||
}else
|
||||
chain += " _";
|
||||
|
||||
}
|
||||
}else
|
||||
chain += " _";
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user