Hébergeur de fichiers indépendant

fenetrePrincipale.java

À propos

Type de fichier
Fichier JAVA de 29 Ko (text/plain)
Confidentialité
Fichier public, envoyé le 16 novembre 2012 à 18:47, depuis l'adresse IP 92.90.x.x (France)
Sécurité
Ne contient aucun Virus ou Malware connus - Dernière vérification: 2 jours
Statistiques
La présente page de téléchargement a été vue 394 fois depuis l'envoi du fichier
Page de téléchargement

Aperçu du fichier


package TM;

import javax.imageio.ImageIO;

import javax.imageio.ImageReader;

import java.awt.Component;
import java.awt.Container;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.imageio.ImageReader;

import java.awt.Component;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class fenetrePrincipale {
	  
	//PRINCIPAUX COMPOSANTS
	
	public static boolean begin = true;
	
	JButton mario = new JButton();
	int marioX = mario.getX();
	int marioY = mario.getY();
	
	JButton ennemi[] = new JButton[25];
	int eX[] = new int[25];
	int eY[] = new int[25];
	
	JButton peach = new JButton();
	int peachX = peach.getX();
	int peachY = peach.getY();
	
	JButton bas = new JButton();
	int basY = bas.getY();
	
	JButton etage1 = new JButton();
	int etage1Y = etage1.getY();
	
	JButton etage2 = new JButton();
	int etage2Y = etage2.getY();
	
	JButton bloc[] = new JButton[69];
	int bX[] = new int[69];
	int bY[] = new int[69];
	
	JButton pieces = new JButton();
	
	JButton vies = new JButton();

	JButton countdown = new JButton();
	
	JButton Score = new JButton();

	int secondes;
	int totalPieces = 0;
	int vie = 3;
	int score = 0;
	int w = 19;
	int h = 20;
	int wE = 17;
	int hE = 16;
	int wP = 24;
	int hP = 39;
	int wPi = 12;
	int hPi = 12;
	int wC = 20;
	int hC = 20;
	int wT = 20;
	int hT = 33;
	int wB = 16;
	int hB = 16;
	int i;	
	int j;
	
	
	
	boolean tortueDebout = true;
	boolean marioDroite;
	boolean marioToucheEnnemi = false;
	boolean marioToucheTortue = false;
	boolean marioTouchePiece = false;
	boolean marioToucheChampi = false;
	boolean marioToucheBlocDroite = false;
	boolean marioToucheBlocGauche = false;
	boolean marioATerre = true;
	boolean marioPetit = true;
	boolean marioBas = true;
	boolean marioEtage1;
	boolean marioEtage2;
	 
	
	
	Point p = mario.getLocation();
	
		//METHODE DE LA FENETRE PRINCIPALE (CONSTRUCTEURS)

		public fenetrePrincipale() {
			
			JFrame fenetre = new JFrame();
			JPanel panneauPrincipal = new JPanel(){
	            /**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				protected void paintComponent(Graphics g) 					//DESSINE L'IMAGE DE FOND
	            {
	                super.paintComponent(g);
	 
	                ImageIcon m = new ImageIcon("fondBleu.jpg");
	                Image monImage = m.getImage();
	                g.drawImage(monImage, 0, 0,this);
	 
	            }
	        										};
			panneauPrincipal.setLayout(null);	        
			
			fenetre.setTitle("Super Mario 2012");
			fenetre.setSize(1680, 1050);
			fenetre.add(panneauPrincipal);
			fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			fenetre.setVisible(true);
		
			pieces.setText("Total de pieces:" +totalPieces);
			pieces.setBounds(730,10,150,50);
			
			vies.setText("Vies restantes:" +vie);
			vies.setBounds(940,10,150,50);
			
			Score.setText("score:" +score);
			Score.setBounds(400,10,100,50);
			
			countdown.setBounds(560,10,150,50);
		
			mario.setIcon(new ImageIcon("petit normal.png"));
			mario.setBounds(10,904,w,h);
			marioX = mario.getX();
			marioY = mario.getY();
			marioDroite = true;
			p = mario.getLocation();
			
			eX[0] = 50;
			eX[1] = 150;
			eX[2] = 250;
			eX[3] = 350;
			eX[4] = 450;
			eX[5] = 550;
			eX[6] = 650;
			eX[7] = 750;
			eX[8] = 850;
			eX[9] = 50;
			eX[10] = 150;
			eX[11] = 250;
			eX[12] = 350;
			eX[13] = 450;
			eX[14] = 550;
			eX[15] = 650;
			eX[16] = 750;
			eX[17] = 50;
			eX[18] = 150;
			eX[19] = 250;
			eX[20] = 350;
			eX[21] = 450;
			eX[22] = 550;
			eX[23] = 650;
			eX[24] = 750;
			
			eY[0] = 908;
			eY[1] = 908;
			eY[2] = 908;
			eY[3] = 908;
			eY[4] = 908;
			eY[5] = 908;
			eY[6] = 908;
			eY[7] = 908;
			eY[8] = 908;
			eY[9] = 624;
			eY[10] = 624;
			eY[11] = 624;
			eY[12] = 624;
			eY[13] = 624;
			eY[14] = 624;
			eY[15] = 624;
			eY[16] = 624;
			eY[17] = 340;
			eY[18] = 340;
			eY[19] = 340;
			eY[20] = 340;
			eY[21] = 340;
			eY[22] = 340;
			eY[23] = 340;
			eY[24] = 340;
			
			/*for (i=0; i<0; i++)	{
			    ennemi[i] = new JButton();
			    ennemi[i].setIcon(new ImageIcon("mŽchant.png"));
				ennemi[i].setFocusable(false);
			    ennemi[i].setBounds(eX[i], eY[i] , wE, hE);
			    eX[i] = ennemi[i].getX();
			    eY[i] = ennemi[i].getY();
				panneauPrincipal.add(ennemi[i]);
				}
			*/
			peach.setIcon(new ImageIcon("peach.png"));
			peach.setBounds(1640,318,wP, hP);
			peachX = peach.getX();
			peachY = peach.getY();
			
			bas.setBounds(0,924,1700,20);
			bas.setIcon(new ImageIcon("bas.png"));
			basY = bas.getY();
			
			etage1.setBounds(0,640,1680,10);
			etage1.setIcon(new ImageIcon("etage.png"));
			etage1Y = etage1.getY();
			
			etage2.setBounds(0,356,1680,10);
			etage2.setIcon(new ImageIcon("etage.png"));
			etage2Y = etage2.getY();
			
			bX[0] = 105;
			bX[1] = 121;
			bX[2] = 137;
			bX[3] = 153;
			bX[4] = 272;
			bX[5] = 288;
			bX[6] = 302;
			bX[7] = 318;
			bX[8] = 334;
			bX[9] = 350;
			bX[10] = 366;
			bX[11] = 382;
			bX[12] = 570;
			bX[13] = 586;
			bX[14] = 586;
			bX[15] = 602;
			bX[16] = 602;
			bX[17] = 602;
			bX[18] = 618;
			bX[19] = 618;
			bX[20] = 618;
			bX[21] = 618;
			bX[22] = 634;
			bX[23] = 634;
			bX[24] = 634;
			bX[25] = 634;
			bX[26] = 634;
			bX[27] = 1320;
			bX[28] = 1336;
			bX[29] = 1336;
			bX[30] = 1352;
			bX[31] = 1352;
			bX[32] = 1352;
			bX[33] = 1368;
			bX[34] = 1368;
			bX[35] = 1384;
			
			bX[36] = 135;
			bX[37] = 175;
			bX[38] = 215;
			bX[39] = 255;
			bX[40] = 295;
			bX[41] = 335;
			bX[42] = 375;
			bX[43] = 415;
			bX[44] = 431;
			bX[45] = 447;
			bX[46] = 455;
			bX[47] = 471;
			bX[48] = 487;
			bX[49] = 495;
			bX[50] = 527;
			bX[51] = 550;
			bX[52] = 590;
			bX[53] = 630;
			bX[54] = 670;
			bX[55] = 710;
			bX[56] = 750;
			bX[57] = 790;
			bX[58] = 830;
			bX[59] = 870;
			bX[60] = 910;
			bX[61] = 950;
			bX[62] = 1000;
			bX[63] = 1000;
			bX[64] = 1084;
			bX[65] = 1084;
			bX[66] = 1168;
			bX[67] = 1168;
			bX[68] = 1300;
			
			
			bY[0] = 884;
			bY[1] = 884;
			bY[2] = 884;
			bY[3] = 884;
			bY[4] = 908;
			bY[5] = 908;
			bY[6] = 908;
			bY[7] = 908;
			bY[8] = 908;
			bY[9] = 908;
			bY[10] = 908;
			bY[11] = 908;
			bY[12] = 908;
			bY[13] = 908;
			bY[14] = 892;
			bY[15] = 908;
			bY[16] = 892;
			bY[17] = 876;
			bY[18] = 908;
			bY[19] = 892;
			bY[20] = 876;
			bY[21] = 860;
			bY[22] = 908;
			bY[23] = 892;
			bY[24] = 876;
			bY[25] = 860;
			bY[26] = 844;
			bY[27] = 908;
			bY[28] = 908;
			bY[29] = 892;
			bY[30] = 908;
			bY[31] = 892;
			bY[32] = 876;
			bY[33] = 908;
			bY[34] = 892;
			bY[35] = 908;
			
			bY[36] = 624;
			bY[37] = 575;
			bY[38] = 540;
			bY[39] = 575;
			bY[40] = 540;
			bY[41] = 505;
			bY[42] = 470;
			bY[43] = 435;
			bY[44] = 508;
			bY[45] = 585;
			bY[46] = 435;
			bY[47] = 508;
			bY[48] = 600;
			bY[49] = 435;
			bY[50] = 624;
			bY[51] = 410;
			bY[52] = 410;
			bY[53] = 410;
			bY[54] = 410;
			bY[55] = 410;
			bY[56] = 410;
			bY[57] = 410;
			bY[58] = 410;
			bY[59] = 410;
			bY[60] = 410;
			bY[61] = 410;
			bY[62] = 624;
			bY[63] = 608;
			bY[64] = 624;
			bY[65] = 608;
			bY[66] = 624;
			bY[67] = 608;
			bY[68] = 624;
			
			
			for (i=0; i<bloc.length; i++)	{
			    bloc[i] = new JButton();
			    bloc[i].setIcon(new ImageIcon("mur.png"));
			    bloc[i].setBounds(bX[i], bY[i] , wB, hB);
			    bX[i] = bloc[i].getX();
			    bY[i] = bloc[i].getY();
				panneauPrincipal.add(bloc[i]);
				bloc[i].setFocusable(false);
				}
			
			panneauPrincipal.add(peach);
			panneauPrincipal.add(vies);
			panneauPrincipal.add(mario);
			panneauPrincipal.add(etage2);
			panneauPrincipal.add(bas);
			panneauPrincipal.add(etage1);
			panneauPrincipal.add(countdown);
			panneauPrincipal.add(Score);
			panneauPrincipal.add(pieces);
			
			
			vies.setFocusable(false);
			peach.setFocusable(false);
			etage2.setFocusable(false);
			etage1.setFocusable(false);
			bas.setFocusable(false);
			pieces.setFocusable(false);
			Score.setFocusable(false);
			countdown.setFocusable(false);			
		
		
						
			Thread s = new Thread() {
				public void run() {
					for (secondes = 100; secondes >= 0; secondes--)
					{
					    countdown.setText("temps restant:" +secondes);
					    if (secondes == 0)
					    	gameOver();
					    try { Thread.sleep(1000); } catch (InterruptedException e) { } 
					}


					}
			
				};
				s.start();
		
				//DEPLACEMENTS DE MARIO
				
				mario.addKeyListener(controleMario());
							
	} // public fenetrePrincipale() 
		
		
		
		//METHODE DE FIN (DEFAITE)
		
		public void gameOver() {
			
			JFrame gameOver = new JFrame();
			
			
			JPanel panneauGameOver = new JPanel();
			panneauGameOver.setLayout(new GridLayout(4,1));
			
			gameOver.setLocationRelativeTo(null);
			gameOver.setTitle("Game Over");
			gameOver.setSize(447, 600);
			
			
			JButton perdu = new JButton("VOUS AVEZ PERDU!");
			perdu.setIcon(new ImageIcon("marioDefaite0.jpg"));
			perdu.setFocusable(false);
			
			JButton enregistrer = new JButton();
			enregistrer.setIcon(new ImageIcon("marioDefaite1.jpg"));
			enregistrer.addActionListener(new Action1());
			enregistrer.setFocusable(false);
			
			JButton recommencer = new JButton();
			recommencer.setIcon(new ImageIcon("marioDefaite2.jpg"));
			recommencer.addActionListener(new Action2());
			recommencer.setFocusable(false);
			
			JButton quitter = new JButton();
			quitter.setIcon(new ImageIcon("marioDefaite3.jpg"));
			quitter.addActionListener(new Action3());
			quitter.setFocusable(false);

			panneauGameOver.add(perdu);
			panneauGameOver.add(enregistrer);
			panneauGameOver.add(recommencer);
			panneauGameOver.add(quitter);
			
			gameOver.add(panneauGameOver);
			gameOver.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			gameOver.setVisible(true);
		}
		
		
		//METHODE DE FIN (VICTOIRE)
		
		public void victoire(){
			JFrame victoire = new JFrame();
			
			JPanel panneauVictoire = new JPanel();
			panneauVictoire.setLayout(new GridLayout(4,1));
			
			victoire.setTitle("Victoire!");
			victoire.setSize(700,933);
			victoire.setLocationRelativeTo(null);
			
			
			JButton bravo = new JButton();
			bravo.setIcon(new ImageIcon("marioVictoire0.jpg"));
			
			JButton enregistrer = new JButton();
			enregistrer.setIcon(new ImageIcon("marioVictoire1.jpg"));
			enregistrer.addActionListener(new Action1());
			
			JButton recommencer = new JButton();
			recommencer.setIcon(new ImageIcon("marioVictoire2.jpg"));
			recommencer.addActionListener(new Action2());
			
			JButton quitter = new JButton();
			quitter.setIcon(new ImageIcon("marioVictoire3.jpg"));
			quitter.addActionListener(new Action3());
			
			panneauVictoire.add(bravo);
			panneauVictoire.add(enregistrer);
			panneauVictoire.add(recommencer);
			panneauVictoire.add(quitter);
			
			victoire.getContentPane().add(panneauVictoire);
			victoire.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			victoire.setVisible(true);
			
		}
		

		class Action1 implements ActionListener {
			@Override
			public void actionPerformed(ActionEvent e) {
				enregistrerScore();
			}
		}
		
		class Action2 implements ActionListener {
			@Override
			public void actionPerformed(ActionEvent e) {
				TM.fenetrePrincipale fenetre3 = new fenetrePrincipale();
			}
		}
		
		class Action3 implements ActionListener {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		}
		
		//METHODE POUR ENREGISTRER LE SCORE
		
		public void enregistrerScore()		{
			String nom;
			String chaine ="";
			String fichier = "meilleurs scores.txt";
			//demande le nom du joueur pour les highscores.
			nom=(String)JOptionPane.showInputDialog("Entrez votre nom:");
			 	
			
			 	try{
					InputStream ips=new FileInputStream(fichier); 
					InputStreamReader ipsr=new InputStreamReader(ips);
					BufferedReader br=new BufferedReader(ipsr);
					String ligne;
					while ((ligne=br.readLine())!=null){
						chaine+=ligne+"\n";
					}
					br.close(); 
				}		
				catch (Exception e)
				{
					System.out.println(e.toString());
				}
			 	try {
					FileWriter fw = new FileWriter (fichier);
					BufferedWriter bw = new BufferedWriter (fw);
					PrintWriter fichierSortie = new PrintWriter (bw); 
						fichierSortie.println ("\n" +chaine+ "\n" + nom + " a fait " + score + "points"); 
					fichierSortie.close();
				}
				catch (Exception e)
				{
					System.out.println(e.toString());
				}		
			
		}
		
		//METHODE DU CONTACT

		public void contact() {	
			
			
			
			
			//CONTACT MARIO + ENNEMI
		
			/*for (i=0;i<0;i++)	
				
			if	((marioX + w >= eX[i])							//CONTACT PAR LE HAUT AVEC ENNEMI
					&!(marioX > eX[i] + wE)
					&(marioY + h >= eY[i])
					&!(marioY > eY[i] + hE)
					&(marioY + h -5 <= eY[i])
					&(ennemi[i].isEnabled()))	 {
				
				ennemi[i].setEnabled(false);
				ennemi[i].setVisible(false);
				score = score + 50;
				Score.setText("score:" +score);
				
			}
				
			if	((marioX + w >= eX[i])								//CONTACT PAR LE COTE AVEC ENNEMI
					&!(marioX > eX[i] + wE)
					&(marioY + h >= eY[i])
					&!(marioY > eY[i] + hE)
					&!(marioY + h -5 <= eY[i])
					&(ennemi[i].isEnabled()))	{
				
				if (marioPetit) {
				marioToucheEnnemi = true;
				vie--;
				vies.setText("Vies restantes:" +vie);
							if (vie == 0) 
								gameOver();
				mario.setBounds(10,904,w,h);
	 			marioX = mario.getX();
	 			marioY = mario.getY();
	 			p = mario.getLocation();
				}
				
				else {
					mario.setSize(w,h);
					
					if (marioDroite)
					mario.setIcon(new ImageIcon("petit normal.png"));
					else
						
						mario.setIcon(new ImageIcon("petit normal 2.png"));
					
				}
											}
			
			
			
				//CONTACT MARIO + PIECE
				for (i=0; i<XX; i++)
				if	((marioX + w >= piX[i])
						&!(marioX > piX[i] + wPi)
						&(marioY + h >= piY[i])
						&!(marioY > piY[i] + hPi)
						&(piece.isEnabled()))	
				{
					piece[i].setEnabled(false);
					piece[i].setVisible(false);
					totalPieces++;
					pieces.setText("Total de pieces:" + totalPieces);
					if (totalPieces == 10) {
						totalPieces = 0;
						vie++;
						vies.setText("Vies restantes:" +vie);
						}
					score = score + 10;
					Score.setText("score:" +score);
				}
				*/
				//CONTACT MARIO + PEACH
				
				if	((marioX + w >= peachX)
					&!(marioX > peachX + wP)
					&(marioY + h >= peachY)
					&!(marioY > peachY + hP))											
					
					victoire();
				
				//CONTACT MARIO + TORTUE					//CONTACT DEPUIS DESSUS SUR TORTUE DEBOUT
				/*	for (i=0; i<XX; i++)
				if		((marioX + w >= tX[i])
						&!(marioX > tX[i] + wT)
						&(marioY + h >= tY[i])
						&!(marioY > tY[i] + hT)
						&(marioY + h -5 <= tY[i])
						&(tortue.isEnabled())
						&(tortueDebout[i]))	 {
					
					tortueDebout[i] = false;
					tortue[i].setSize(12,12);
					tortue[i].setIcon(new ImageIcon("carapace.png"));
					
						score = score + 50;
						Score.setText("score:" +score);
												}
					
				if		((marioX + w >= tX[i])				//CONTACT DEPUIS LE COTE AVEC TORTUE DEBOUT
						&!(marioX > tX[i] + wT)
						&(marioY + h >= tY[i])
						&!(marioY > tortueY + hT)
						&!(marioY + h -5 <= tY[i])
						&(tortue.isEnabled())
						&(tortueDebout[i]))		{
					
					
						if (marioPetit) {
						marioToucheTortue = true;
									vie--;
									vies.setText("Vies restantes:" +vie);
									if (vie == 0) 
										gameOver();
						 			mario.setBounds(10,904,w,h);
						 			marioX = mario.getX();
						 			marioY = mario.getY();
						 			p = mario.getLocation();
													}
						else {
							if (marioDroite)
							mario.setIcon(new ImageIcon("petit normal.png"));
							else
								mario.setIcon(new ImageIcon("petit normal 2.png"));
							
							mario.setSize(w,h);
							tortue[i].setEnabled(false);
							tortue[i].setVisible(false);
						}
					}
										
			 	if		((marioX + w >= tX[i])				//CONTACT TORTUE CARAPACE
						&!(marioX > tX[i] + wT)
						&(marioY + h >= tY[i])
						&!(marioY > tY[i] + hT)
						&(tortue.isEnabled())
						&!(tortueDebout[i]) {
						
						tortue[i].setEnabled(false);
						tortue[i].setVisible(false);
						score = score + 50;
						Score.setText("score:" +score);
												}
				
				
				//CONTACT MARIO + CHAMPI
				for (i=0; i<champi.length; i++)
				if	((marioX + w >= cX[i])
						&!(marioX > cX[i] + wC)
						&(marioY + h >= cY[i])
						&!(marioY > cY[i] + hC)
						&(champi.isEnabled())
						&(marioATerre))	{
					
					champi[i].setEnabled(false);
					champi[i].setVisible(false);
					
				if (marioPetit) {
					
					if (marioDroite){
					marioPetit =false;
					mario.setLocation(p.x,p.y-12);
					mario.setIcon(new ImageIcon("gros normal.png"));
					mario.setSize(19,32);
					}
					else {
						marioPetit =false;
						mario.setLocation(p.x,p.y-14);
						mario.setIcon(new ImageIcon("gros normal 2.png"));
						mario.setSize(20,34);
					}
				}
				else {
					score = score + 50;
					Score.setText("score:" +score);
				}
				}
				*/
			
			//CHANGEMENT D'ETAGE
			
			if ((marioATerre)
				&(marioX >= 1630)
				&(marioY>324))	{
				
				if (marioBas) {
					marioBas = false;
					marioEtage1 = true;
				}
				
				else
				
				if (marioEtage1) {
					marioEtage1 = false;
					marioEtage2 = true;
				}
				
				mario.setLocation(p.x-1630, p.y-284);
				marioX = mario.getX();
				marioY = mario.getY();
				p = mario.getLocation();
			}
			
			//CONTACT BORD GAUCHE
			
			if (marioX<=3) {
				i = 1;
				if (marioBas) {
					if (marioPetit) {
					while (marioY + h < basY)
	        		 {
					mario.setLocation(p.x-4, p.y+i);
					marioX = mario.getX();
					marioY = mario.getY();
					p = mario.getLocation();
					try {
						Thread.sleep(30);
					}
					catch (InterruptedException e) {
						e.printStackTrace();
						}
					marioATerre = false;
					i++;
	        		}
					}
					else {
						while (marioY + 34 < etage2Y) {
							mario.setLocation(p.x-4, p.y+i);
							marioX = mario.getX();
							marioY = mario.getY();
							p = mario.getLocation();
							try {
								Thread.sleep(30);
							}
							catch (InterruptedException e) {
								e.printStackTrace();
								}
							marioATerre = false;
							i++;
						}
					}
				}
				if (marioEtage1) {
					if (marioPetit) {
					while (marioY + h < etage1Y) {
						mario.setLocation(p.x-4, p.y+i);
						marioX = mario.getX();
						marioY = mario.getY();
						p = mario.getLocation();
						try {
							Thread.sleep(30);
						}
						catch (InterruptedException e) {
							e.printStackTrace();
							}
						marioATerre = false;
						i++;
					}
					}
					else {
						while (marioY + 34 < etage2Y) {
							mario.setLocation(p.x-4, p.y+i);
							marioX = mario.getX();
							marioY = mario.getY();
							p = mario.getLocation();
							try {
								Thread.sleep(30);
							}
							catch (InterruptedException e) {
								e.printStackTrace();
								}
							marioATerre = false;
							i++;
						}
					}
				}
				if (marioEtage2) {
					if (marioPetit){
					while (marioY + h < etage2Y) {
						mario.setLocation(p.x-4, p.y+i);
						marioX = mario.getX();
						marioY = mario.getY();
						p = mario.getLocation();
						try {
							Thread.sleep(30);
						}
						catch (InterruptedException e) {
							e.printStackTrace();
							}
						marioATerre = false;
						i++;
					}
					}
					else {
						while (marioY + 34 < etage2Y) {
							mario.setLocation(p.x-4, p.y+i);
							marioX = mario.getX();
							marioY = mario.getY();
							p = mario.getLocation();
							try {
								Thread.sleep(30);
							}
							catch (InterruptedException e) {
								e.printStackTrace();
								}
							marioATerre = false;
							i++;
						}
					}
				}
				marioATerre = true;
			}
		}
				
	/**
	 * Déplacement de Mario
	 * @param dx déplacement sur les X
	 * @param dy déplacement sur les Y
	 */
private void deplacementMario(int dx, int dy)
{
	double dxy = Math.sqrt(dx*dx+dy*dy); // distance à parcourir
	
	LinkedList<Point> chemin = new LinkedList<Point>(); // points à traverser au cours du déplacement
	int x = mario.getX(), y = mario.getY();
	Point r = null;
	for (double d=0; d<=dxy; d+=0.5)
	{
		Point p = new Point((int) (x+d*dx/dxy),(int) (y+d*dy/dxy)); // le prochain point de déplacement
		if (!p.equals(r)) // s'il s'agit d'un nouveau point on l'ajoute à la liste
		{
			chemin.add(p);
			r = p;
		}
	}
	r = null;
	
	// On contrôle que chaque point de déplacement n'est pas sur un obstacle
	// Au premier obstacle on s'arrête
p:	for (Point p : chemin) // pour chaque case du chemin
	{
		for (int i=0; i<bloc.length; i++) // pour chaque obstacle
		{
			if (((bX[i]>=p.x && bX[i]<=p.x+w) // si le bord gauche d'un obstacle est sur le trajet de Mario


Partager le fichier

Télécharger fenetrePrincipale.java

Télécharger le fichier (29 Ko)