starting the GUI - grid
This commit is contained in:
parent
1fc316b132
commit
d0a517efe3
@ -13,7 +13,7 @@ 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};
|
||||
protected final static int[] bato = { 5, 4, 3, 3, 2};
|
||||
|
||||
public boolean setShips(Ship ship){
|
||||
for(int i = 0; i < ship.getSize(); i++){
|
||||
@ -92,7 +92,7 @@ public abstract class Player {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void placeShipRandomly(Player player) {
|
||||
public static void placeShipRandomly(Player player) {
|
||||
Random rand = new Random();
|
||||
for(int i : bato) {
|
||||
Ship ship = null;
|
||||
|
@ -54,7 +54,7 @@ public class Terminal extends View {
|
||||
}
|
||||
} else {
|
||||
// Random
|
||||
placeShipRandomly(player);
|
||||
Player.placeShipRandomly(player);
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import battleship.model.player.Player;
|
||||
import battleship.utils.Pair;
|
||||
import battleship.utils.Triplet;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -23,17 +24,9 @@ public abstract class View {
|
||||
|
||||
public abstract void setShips(Player player);
|
||||
|
||||
public abstract void displayBoard();
|
||||
|
||||
public void placeShipRandomly(Player player) {
|
||||
Random rand = new Random();
|
||||
for(int i : ships) {
|
||||
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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract void displayBoard();
|
||||
public abstract void displayBoard(Graphics g);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -3,18 +3,24 @@ package battleship.view;
|
||||
import battleship.model.Game;
|
||||
import battleship.model.player.Player;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Window extends View {
|
||||
|
||||
private JFrame frame;
|
||||
private final int hauteur = 750;
|
||||
private final int largeur = 1250;
|
||||
|
||||
public Window(Game game) {
|
||||
super(game);
|
||||
this.frame = new JFrame("Battleship");
|
||||
frame.setSize(600,400);
|
||||
frame.setSize(largeur,hauteur);
|
||||
frame.setContentPane(new Draw());
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
@ -25,11 +31,33 @@ public class Window extends View {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayBoard() {
|
||||
public void displayBoard(Graphics g) {
|
||||
|
||||
}
|
||||
class Draw extends JPanel {
|
||||
public void paintComponent(Graphics g) {
|
||||
/*JTextArea area = new JTextArea();
|
||||
area.setBounds(20,10,400,20);
|
||||
//area.append("A B C D E F G H I J");
|
||||
frame.add(area);*/
|
||||
//23 - 12
|
||||
for (int i=100; i<largeur; i+=largeur/23) {
|
||||
g.drawLine(i, largeur/12, i, largeur-(largeur/12));
|
||||
if (i > (largeur / 23) * 10 && i < (largeur / 23) * 12 - (largeur/40)) i += largeur/23 ;
|
||||
}
|
||||
for (int j=100; j<hauteur; j+=hauteur/10) {
|
||||
g.drawLine(hauteur/10, j, hauteur - (hauteur/10), j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void designBoard(Graphics g) {
|
||||
//super.paintComponent(g);
|
||||
frame.paintComponents(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayBoard() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user