moving placeShip to Player

This commit is contained in:
Antonin Boyon 2021-04-06 10:31:54 +02:00
parent 7fc9fb462c
commit 1fc316b132
2 changed files with 19 additions and 1 deletions

View File

@ -1,16 +1,19 @@
package battleship.model.player; package battleship.model.player;
import battleship.model.Direction;
import battleship.model.Ship; import battleship.model.Ship;
import battleship.utils.Pair; import battleship.utils.Pair;
import battleship.utils.Triplet; import battleship.utils.Triplet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
public abstract class Player { public abstract class Player {
protected ArrayList<Ship> ships = new ArrayList<>(); protected ArrayList<Ship> ships = new ArrayList<>();
protected ArrayList<Triplet<Integer,Integer,Boolean>> moves = new ArrayList<>(); protected ArrayList<Triplet<Integer,Integer,Boolean>> moves = new ArrayList<>();
protected int id; protected int id;
protected final int[] bato = { 5, 4, 3, 3, 2};
public boolean setShips(Ship ship){ public boolean setShips(Ship ship){
for(int i = 0; i < ship.getSize(); i++){ for(int i = 0; i < ship.getSize(); i++){
@ -88,5 +91,14 @@ public abstract class Player {
public int getId() { public int getId() {
return id; return id;
} }
public void placeShipRandomly(Player player) {
Random rand = new Random();
for(int i : bato) {
Ship ship = null;
while(ship == null || !player.setShips(ship)) {
ship = new Ship(new Pair<>(rand.nextInt(10), rand.nextInt(10)), i, Direction.values()[rand.nextInt(Direction.values().length)]);
}
}
}
} }

View File

@ -3,6 +3,8 @@ package battleship.view;
import battleship.model.Game; import battleship.model.Game;
import battleship.model.player.Player; import battleship.model.player.Player;
import java.awt.Graphics;
import javax.swing.*; import javax.swing.*;
public class Window extends View { public class Window extends View {
@ -26,4 +28,8 @@ public class Window extends View {
public void displayBoard() { public void displayBoard() {
} }
public void designBoard(Graphics g) {
//super.paintComponent(g);
}
} }