moving placeShip to Player
This commit is contained in:
parent
7fc9fb462c
commit
1fc316b132
@ -1,16 +1,19 @@
|
||||
package battleship.model.player;
|
||||
|
||||
import battleship.model.Direction;
|
||||
import battleship.model.Ship;
|
||||
import battleship.utils.Pair;
|
||||
import battleship.utils.Triplet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Player {
|
||||
|
||||
protected ArrayList<Ship> ships = new ArrayList<>();
|
||||
protected ArrayList<Triplet<Integer,Integer,Boolean>> moves = new ArrayList<>();
|
||||
protected int id;
|
||||
protected final int[] bato = { 5, 4, 3, 3, 2};
|
||||
|
||||
public boolean setShips(Ship ship){
|
||||
for(int i = 0; i < ship.getSize(); i++){
|
||||
@ -89,4 +92,13 @@ public abstract class Player {
|
||||
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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package battleship.view;
|
||||
import battleship.model.Game;
|
||||
import battleship.model.player.Player;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Window extends View {
|
||||
@ -26,4 +28,8 @@ public class Window extends View {
|
||||
public void displayBoard() {
|
||||
|
||||
}
|
||||
|
||||
public void designBoard(Graphics g) {
|
||||
//super.paintComponent(g);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user