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/
.idea
*.iml
.classpath
.project
.settings/
/bin/

View File

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