Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controlleur;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import IHM.*;
- import info1.ships.*;
- public class SetupBoat implements ActionListener {
- private NavyFleet fleet;
- private Vue vue;
- private boolean retourner;
- public SetupBoat(Vue vue, NavyFleet fleet) {
- this.vue = vue;
- this.fleet = fleet;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- this.retourner=false;
- try{
- vue.getTailleBateau();
- vue.getAngle();
- vue.getText();
- /*switch (vue.getTailleBateau()) {
- case 1:
- IShip ship = new Submarine("sub", vue.getText());
- fleet.add(ship);
- case 2:
- IShip ship2 = new Destroyer("dest", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship2);
- case 3:
- IShip ship3 = new Destroyer("crui", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship3);
- case 4:
- IShip ship4 = new Destroyer("bat", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship4);
- case 5:
- IShip ship5 = new Destroyer("air", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship5);
- }*/
- if (vue.getTailleBateau()==1){
- IShip ship = new Submarine("sub", vue.getText());
- fleet.add(ship);
- }
- if (vue.getTailleBateau()==2){
- IShip ship2 = new Destroyer("dest", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship2);
- }
- if (vue.getTailleBateau()==3){
- IShip ship3 = new Cruiser("crui", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship3);
- }
- if (vue.getTailleBateau()==4){
- IShip ship4 = new Battleship("bat", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship4);
- }
- if (vue.getTailleBateau()==5){
- IShip ship5 = new AircraftCarrier("air", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
- fleet.add(ship5);
- }
- }
- catch (BadCoordException exc){
- System.out.println(exc.getMessage());
- }
- catch (CoordsBadShipException exc){
- System.out.println(exc.getMessage());
- }
- catch (IndexOutOfBoundsException exc){
- System.out.println(exc.getMessage());
- }
- for (IShip ship : this.fleet.getShips()){
- for (ICoord coord : ship.getCoords()){
- System.out.println(coord);
- }
- }
- }
- private String increment(String coord,String angle,int length){
- char[] tab=coord.toCharArray();
- String res="";
- if (angle == "Vertical"){
- char value = tab[0];
- int ascii= (int) value+length-1;
- value = (char) ascii;
- res = value+""+tab[1];
- if ((int)value>74){
- throw new IndexOutOfBoundsException("Le bateau dépasse de la grille");
- }
- }else{
- char value = tab[1];
- int ascii = (int) value+length-1;
- System.out.println(ascii);
- /*if (ascii >= 10){
- ascii = value-2*length;
- if (ascii>=10){
- throw new IndexOutOfBoundsException("Le bateau dépasse de la grille");
- }
- }*/
- value = (char) ascii;
- res = tab[0]+""+value;
- }
- return res;
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement