displayBoard now hide opponents ships when playing
This commit is contained in:
parent
2ed5251f9b
commit
5bdc772f29
@ -88,7 +88,9 @@ public class Game {
|
||||
public void Play(View view) {
|
||||
try {
|
||||
view.setShips(players[0]);
|
||||
changeCurrentPlayer();
|
||||
view.setShips(players[1]);
|
||||
changeCurrentPlayer();
|
||||
Player winner = null;
|
||||
while (winner == null) {
|
||||
System.out.println("Au tour du joueur " + currentPlayer.getId());
|
||||
|
@ -29,14 +29,18 @@ public abstract class AbstractView implements View {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
public String toString(boolean debug) {
|
||||
String chain = "";
|
||||
for(int u = 0; u < 2; ++u) {
|
||||
Player player = game.players[u];
|
||||
ArrayList<Ship> ships = game.players[u].getShips();
|
||||
chain += "Joueur " + player.getId() + " :\n";
|
||||
chain += "+ - - - - - - - - - - +\n";
|
||||
chain += "+ 0 1 2 3 4 5 6 7 8 9 +\n";
|
||||
for(int x = 0; x < 10; ++x) {
|
||||
chain += "|";
|
||||
chain += x;
|
||||
for(int y = 0; y < 10; ++y) {
|
||||
Pair<Integer, Integer> pair = new Pair<>(x, y);
|
||||
boolean isPosition = false;
|
||||
@ -48,8 +52,10 @@ public abstract class AbstractView implements View {
|
||||
chain += " X";
|
||||
} else if (result == 2){
|
||||
chain += " !";
|
||||
} else {
|
||||
} else if(debug || game.getCurrentPlayer() == player) {
|
||||
chain += " .";
|
||||
} else {
|
||||
chain += " _";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class Terminal extends AbstractView {
|
||||
*/
|
||||
@Override
|
||||
public void displayBoard() {
|
||||
System.out.println(this);
|
||||
System.out.println(this.toString(false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,6 +242,7 @@ public class Window extends AbstractView {
|
||||
for(int i = 1; i < 3; ++i) {
|
||||
Player player = game.players[i-1];
|
||||
for(Ship ship : player.getShips()) {
|
||||
if(player == game.getCurrentPlayer() ||ship.isDrown()) {
|
||||
int x1 = i == 1 ? initialWidth : initialWidth * 13;
|
||||
int y1 = initialHeight * 2;
|
||||
int shipWidth = initialWidth;
|
||||
@ -275,10 +276,9 @@ public class Window extends AbstractView {
|
||||
g2d.fillRoundRect(x1 + 1, y1 + 1, shipWidth - 1, shipHeight - 1, 25, 25);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 1; i < 3; ++i) {
|
||||
Player player = game.players[i-1];
|
||||
int halfBoxSizeWidth = initialWidth / 2;
|
||||
int halfBoxSizeHeight = initialHeight / 2;
|
||||
float rectangleSize = initialWidth / 4f;
|
||||
int sqrt = (int) Math.sqrt(initialHeight * initialHeight + initialWidth * initialWidth) - 10;
|
||||
for(Triplet<Integer, Integer, Boolean> move : player.getMoves()) {
|
||||
|
Loading…
Reference in New Issue
Block a user