fix View.toString()

This commit is contained in:
Quentin Legot 2021-03-30 10:33:02 +02:00
parent 77d0c0946e
commit 5098d46e5c
2 changed files with 22 additions and 18 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
out/ out/
.idea .idea
*.iml *.iml
.classpath
.project
.settings/
/bin/

View File

@ -5,6 +5,7 @@ import battleship.model.player.Player;
import battleship.utils.Triplet; import battleship.utils.Triplet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class View { public abstract class View {
@ -23,25 +24,24 @@ public abstract class View {
@Override @Override
public String toString() { public String toString() {
ArrayList<Triplet<Integer,Integer,Boolean>> moves = game.currentPlayer.getMoves(); ArrayList<Triplet<Integer,Integer,Boolean>> moves = game.currentPlayer.getMoves();
String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ A B C D E F G H I J +\n"; String chain = "A vous de joueur "+game.currentPlayer.toString()+ "\n+ - - - - - - - - - - +\n";
for(int i = 0; i<10;i++){
chain += i+1; for(AtomicInteger i = new AtomicInteger(0); i.get() < 10;i.incrementAndGet()) {
for(int y = 0;y<10;y++){ chain += "|";
for(AtomicInteger y = new AtomicInteger(0);y.get() < 10; y.incrementAndGet()) {
if(!moves.isEmpty()) { if(!moves.isEmpty()) {
for (Triplet<Integer, Integer, Boolean> ships : moves) { Triplet<Integer, Integer, Boolean> move = moves.stream().filter(p -> p.getLeft() == i.get() && p.getMiddle() == y.get()).findFirst().orElse(null);
if (i == ships.getLeft() && y == ships.getMiddle()) { if(move != null) {
if(ships.getRight()) if (move.getRight())
chain += " !"; chain += " !";
else else
chain += " ."; chain += " .";
} else {
chain += " _";
}else }
chain += " _"; }else {
chain += " _";
} }
}else
chain += " _";
} }
chain += " |\n"; chain += " |\n";
} }