Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Controlleur;
- import Modele.Bombe;
- import java.util.TimerTask;
- public class BombeCtrl implements Runnable {
- Bombe bombe;
- public BombeCtrl(Bombe b){this.bombe=b;}
- public boolean explosion(){
- //zone de deflagration
- //rayon haut
- for(int i=this.bombe.getCoordX();i>=(this.bombe.getCoordX()-this.bombe.getLargeurExplo());i--){
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()]==null
- || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()){
- break;
- }
- else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable()){
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setMurCassable(false);
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setAccessible(true);
- if(!this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable())
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].placerBonus();
- break;
- }
- else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusFlamme()){
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusFlamme(false);
- }
- else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusBombe()){
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusBombe(false);
- }
- else{
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()!=0){
- //mort du personnage qui se trouve sur la case
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==1){//mort J1
- this.bombe.getCarte().getPlayer1().perso.setMort(true);
- }
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==2){//mort J2
- this.bombe.getCarte().getPlayer2().perso.setMort(true);
- }
- }
- }
- }
- //rayon bas
- for(int i=this.bombe.getCoordX();i<=(this.bombe.getCoordX()+this.bombe.getLargeurExplo());i++){
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()]==null
- || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()){
- break;
- }
- else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable()) {
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setMurCassable(false);
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setAccessible(true);
- if(!this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurCassable())
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].placerBonus();
- break;
- }
- else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusFlamme()) {
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusFlamme(false);
- }
- else if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isBonusBombe()) {
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setBonusBombe(false);
- }
- else{
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()!=0){
- //mort du personnage qui se trouve sur la case
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==1){//mort J1
- this.bombe.getCarte().getPlayer1().perso.setMort(true);
- }
- if(this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].getPlayer()==2){//mort J2
- this.bombe.getCarte().getPlayer2().perso.setMort(true);
- }
- }
- }
- }
- //rayon gauche
- for(int i=this.bombe.getCoordY();i>=(this.bombe.getCoordY()-this.bombe.getLargeurExplo());i--){
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i]==null
- || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()){
- break;//si mur incassable ou bord de map
- }
- else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable()){
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setMurCassable(false);
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setAccessible(true);
- if(!this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable())
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].placerBonus();
- break;
- }//si mur cassable
- else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusFlamme()) {
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusFlamme(false);
- }
- else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusBombe()) {
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusBombe(false);
- }
- else{
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()!=0){
- //mort du personnage qui se trouve sur la case
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==1){//mort J1
- this.bombe.getCarte().getPlayer1().perso.setMort(true);
- }
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==2){//mort J2
- this.bombe.getCarte().getPlayer2().perso.setMort(true);
- }
- }
- }
- }
- //rayon droite
- for(int i=this.bombe.getCoordY();i<=(this.bombe.getCoordY()+this.bombe.getLargeurExplo());i++){
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i]==null
- || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()){
- break;
- }
- else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable()){
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setMurCassable(false);
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setAccessible(true);
- if(!this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurCassable())
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].placerBonus();
- break;
- }
- else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusFlamme()) {
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusFlamme(false);
- }
- else if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isBonusBombe()) {
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setBonusBombe(false);
- }
- else{
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()!=0){
- //mort du personnage qui se trouve sur la case
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==1){//mort J1
- this.bombe.getCarte().getPlayer1().perso.setMort(true);
- }
- if(this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].getPlayer()==2){//mort J2
- this.bombe.getCarte().getPlayer2().perso.setMort(true);
- }
- }
- }
- }
- //une fois la bombe explosée
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][this.bombe.getCoordY()].setBombe(false);
- // this.after_explosion();
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][this.bombe.getCoordY()].setAccessible(true);
- this.bombe.getProprietaire().setBombeDrop(/*this.bombe.getProprietaire().getBombeDrop()*/-1);
- //affichage:
- this.bombe.getProprietaire().getCarte().getGridDisplay().affichage();
- return true;
- }
- public boolean after_explosion() {
- for (int i = this.bombe.getCoordX(); i >= (this.bombe.getCoordX() - this.bombe.getLargeurExplo()); i--) {
- if (this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()] == null
- || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()) {
- break;
- } else {
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setFire(true);
- }
- }
- for (int i = this.bombe.getCoordX(); i <= (this.bombe.getCoordX() + this.bombe.getLargeurExplo()); i++) {
- if (this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()] == null
- || this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].isMurSolide()) {
- break;
- } else {
- this.bombe.getCarte().getCarte()[i][this.bombe.getCoordY()].setFire(true);
- }
- }
- for (int i = this.bombe.getCoordY(); i >= (this.bombe.getCoordY() - this.bombe.getLargeurExplo()); i--) {
- if (this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i] == null
- || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()) {
- break;//si mur incassable ou bord de map
- } else {
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setFire(true);
- }
- }
- for (int i = this.bombe.getCoordY(); i <= (this.bombe.getCoordY() + this.bombe.getLargeurExplo()); i++) {
- if (this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i] == null
- || this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].isMurSolide()) {
- break;
- } else {
- this.bombe.getCarte().getCarte()[this.bombe.getCoordX()][i].setFire(true);
- }
- }
- return true;
- }
- public void run() {
- try {
- Thread.sleep(1000);
- explosion();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- public void start() {
- Thread t = new Thread(this);
- t.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement