Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.91 KB | None | 0 0
  1. package Controlleur;
  2.  
  3. import Modele.Bombe;
  4.  
  5. import java.util.TimerTask;
  6.  
  7. public class BombeCtrl implements Runnable {
  8. Bombe bombe;
  9. public BombeCtrl(Bombe b){this.bombe=b;}
  10.  
  11. public boolean explosion(){
  12. //zone de deflagration
  13. //rayon haut
  14. for(int i=this.bombe.getCoordX();i>=(this.bombe.getCoordX()-this.bombe.getLargeurExplo());i--){
  15. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()]==null
  16. || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()){
  17. break;
  18. }
  19. else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable()){
  20. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setMurCassable(false);
  21. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setAccessible(true);
  22. if(!this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable())
  23. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].placerBonus();
  24. break;
  25. }
  26. else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusFlamme()){
  27. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusFlamme(false);
  28. }
  29. else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusBombe()){
  30. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusBombe(false);
  31. }
  32. else{
  33. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()!=0){
  34. //mort du personnage qui se trouve sur la case
  35. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==1){//mort J1
  36. this.bombe.getCarte().getPlayer1().perso.setMort(true);
  37. }
  38. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==2){//mort J2
  39. this.bombe.getCarte().getPlayer2().perso.setMort(true);
  40. }
  41. }
  42. }
  43. }
  44.  
  45. //rayon bas
  46. for(int i=this.bombe.getCoordX();i<=(this.bombe.getCoordX()+this.bombe.getLargeurExplo());i++){
  47. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()]==null
  48. || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()){
  49. break;
  50. }
  51. else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable()) {
  52. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setMurCassable(false);
  53. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setAccessible(true);
  54. if(!this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable())
  55. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].placerBonus();
  56. break;
  57. }
  58. else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusFlamme()) {
  59. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusFlamme(false);
  60. }
  61. else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusBombe()) {
  62. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusBombe(false);
  63. }
  64.  
  65. else{
  66. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()!=0){
  67. //mort du personnage qui se trouve sur la case
  68. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==1){//mort J1
  69. this.bombe.getCarte().getPlayer1().perso.setMort(true);
  70. }
  71. if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==2){//mort J2
  72. this.bombe.getCarte().getPlayer2().perso.setMort(true);
  73. }
  74. }
  75. }
  76. }
  77.  
  78. //rayon gauche
  79. for(int i=this.bombe.getCoordY();i>=(this.bombe.getCoordY()-this.bombe.getLargeurExplo());i--){
  80. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i]==null
  81. || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()){
  82. break;//si mur incassable ou bord de map
  83. }
  84. else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable()){
  85. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setMurCassable(false);
  86. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setAccessible(true);
  87. if(!this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable())
  88. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].placerBonus();
  89. break;
  90. }//si mur cassable
  91. else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusFlamme()) {
  92. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusFlamme(false);
  93. }
  94. else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusBombe()) {
  95. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusBombe(false);
  96. }
  97.  
  98. else{
  99. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()!=0){
  100. //mort du personnage qui se trouve sur la case
  101. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==1){//mort J1
  102. this.bombe.getCarte().getPlayer1().perso.setMort(true);
  103. }
  104. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==2){//mort J2
  105. this.bombe.getCarte().getPlayer2().perso.setMort(true);
  106. }
  107. }
  108. }
  109. }
  110.  
  111. //rayon droite
  112. for(int i=this.bombe.getCoordY();i<=(this.bombe.getCoordY()+this.bombe.getLargeurExplo());i++){
  113. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i]==null
  114. || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()){
  115. break;
  116. }
  117. else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable()){
  118. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setMurCassable(false);
  119. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setAccessible(true);
  120. if(!this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable())
  121. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].placerBonus();
  122. break;
  123. }
  124. else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusFlamme()) {
  125. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusFlamme(false);
  126. }
  127. else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusBombe()) {
  128. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusBombe(false);
  129. }
  130. else{
  131. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()!=0){
  132. //mort du personnage qui se trouve sur la case
  133. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==1){//mort J1
  134. this.bombe.getCarte().getPlayer1().perso.setMort(true);
  135. }
  136. if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==2){//mort J2
  137. this.bombe.getCarte().getPlayer2().perso.setMort(true);
  138. }
  139. }
  140. }
  141. }
  142. //une fois la bombe explosée
  143. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][this.bombe.getCoordY()].setBombe(false);
  144. // this.after_explosion();
  145. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][this.bombe.getCoordY()].setAccessible(true);
  146. this.bombe.getProprietaire().setBombeDrop(/*this.bombe.getProprietaire().getBombeDrop()*/-1);
  147. //affichage:
  148. this.bombe.getProprietaire().getCarte().getGridDisplay().affichage();
  149. return true;
  150. }
  151.  
  152.  
  153. public boolean after_explosion() {
  154.  
  155. for (int i = this.bombe.getCoordX(); i >= (this.bombe.getCoordX() - this.bombe.getLargeurExplo()); i--) {
  156. if (this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()] == null
  157. || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()) {
  158. break;
  159. } else {
  160. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setFire(true);
  161. }
  162. }
  163.  
  164. for (int i = this.bombe.getCoordX(); i <= (this.bombe.getCoordX() + this.bombe.getLargeurExplo()); i++) {
  165. if (this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()] == null
  166. || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()) {
  167. break;
  168. } else {
  169. this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setFire(true);
  170.  
  171. }
  172. }
  173.  
  174. for (int i = this.bombe.getCoordY(); i >= (this.bombe.getCoordY() - this.bombe.getLargeurExplo()); i--) {
  175. if (this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i] == null
  176. || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()) {
  177. break;//si mur incassable ou bord de map
  178. } else {
  179. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setFire(true);
  180. }
  181. }
  182.  
  183. for (int i = this.bombe.getCoordY(); i <= (this.bombe.getCoordY() + this.bombe.getLargeurExplo()); i++) {
  184. if (this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i] == null
  185. || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()) {
  186. break;
  187. } else {
  188. this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setFire(true);
  189. }
  190. }
  191.  
  192.  
  193. return true;
  194.  
  195. }
  196.  
  197. public void run() {
  198. try {
  199. Thread.sleep(1000);
  200. explosion();
  201.  
  202.  
  203. } catch (InterruptedException e) {
  204. e.printStackTrace();
  205. }
  206. }
  207.  
  208. public void start() {
  209. Thread t = new Thread(this);
  210. t.start();
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement