Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. package controlleur;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import IHM.*;
  6. import info1.ships.*;
  7.  
  8.  
  9. public class SetupBoat implements ActionListener {
  10.  
  11. private NavyFleet fleet;
  12. private Vue vue;
  13. private boolean retourner;
  14.  
  15. public SetupBoat(Vue vue, NavyFleet fleet) {
  16. this.vue = vue;
  17. this.fleet = fleet;
  18. }
  19.  
  20. @Override
  21. public void actionPerformed(ActionEvent e) {
  22. this.retourner=false;
  23. try{
  24. vue.getTailleBateau();
  25. vue.getAngle();
  26. vue.getText();
  27. /*switch (vue.getTailleBateau()) {
  28. case 1:
  29. IShip ship = new Submarine("sub", vue.getText());
  30. fleet.add(ship);
  31. case 2:
  32. IShip ship2 = new Destroyer("dest", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  33. fleet.add(ship2);
  34. case 3:
  35. IShip ship3 = new Destroyer("crui", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  36. fleet.add(ship3);
  37. case 4:
  38. IShip ship4 = new Destroyer("bat", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  39. fleet.add(ship4);
  40. case 5:
  41. IShip ship5 = new Destroyer("air", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  42. fleet.add(ship5);
  43. }*/
  44. if (vue.getTailleBateau()==1){
  45. IShip ship = new Submarine("sub", vue.getText());
  46. fleet.add(ship);
  47. }
  48. if (vue.getTailleBateau()==2){
  49. IShip ship2 = new Destroyer("dest", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  50. fleet.add(ship2);
  51. }
  52. if (vue.getTailleBateau()==3){
  53. IShip ship3 = new Cruiser("crui", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  54. fleet.add(ship3);
  55. }
  56. if (vue.getTailleBateau()==4){
  57. IShip ship4 = new Battleship("bat", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  58. fleet.add(ship4);
  59. }
  60. if (vue.getTailleBateau()==5){
  61. IShip ship5 = new AircraftCarrier("air", vue.getText(),this.increment(vue.getText(),vue.getAngle(),vue.getTailleBateau()));
  62. fleet.add(ship5);
  63. }
  64. }
  65. catch (BadCoordException exc){
  66. System.out.println(exc.getMessage());
  67. }
  68. catch (CoordsBadShipException exc){
  69. System.out.println(exc.getMessage());
  70. }
  71. catch (IndexOutOfBoundsException exc){
  72. System.out.println(exc.getMessage());
  73. }
  74. for (IShip ship : this.fleet.getShips()){
  75. for (ICoord coord : ship.getCoords()){
  76. System.out.println(coord);
  77. }
  78. }
  79.  
  80. }
  81.  
  82. private String increment(String coord,String angle,int length){
  83. char[] tab=coord.toCharArray();
  84. String res="";
  85. if (angle == "Vertical"){
  86. char value = tab[0];
  87. int ascii= (int) value+length-1;
  88. value = (char) ascii;
  89. res = value+""+tab[1];
  90. if ((int)value>74){
  91. throw new IndexOutOfBoundsException("Le bateau dépasse de la grille");
  92. }
  93. }else{
  94. char value = tab[1];
  95. int ascii = (int) value+length-1;
  96. System.out.println(ascii);
  97. /*if (ascii >= 10){
  98. ascii = value-2*length;
  99. if (ascii>=10){
  100. throw new IndexOutOfBoundsException("Le bateau dépasse de la grille");
  101. }
  102. }*/
  103. value = (char) ascii;
  104. res = tab[0]+""+value;
  105. }
  106. return res;
  107. }
  108.  
  109. public static void main(String[] args) {
  110.  
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement