19 Mai
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Arme.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Arme.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										20
									
								
								SAe2.1/Arme.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								SAe2.1/Arme.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| public class Arme extends CaseBonus{ | ||||
| 	public int value; | ||||
|  | ||||
| 	public Arme(int v, int x, int y){ | ||||
| 		super(x, y, "arme"); | ||||
| 		this.value = v; | ||||
| 	} | ||||
|  | ||||
| 	public String getLabel(){ | ||||
| 		return (""+this.value); | ||||
| 	} | ||||
|  | ||||
| 	public int getValue(){ | ||||
| 		return this.value; | ||||
| 	} | ||||
|  | ||||
| 	public void setValue(int val){ | ||||
| 		this.value = val; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Case.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Case.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										80
									
								
								SAe2.1/Case.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								SAe2.1/Case.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.util.*; | ||||
|  | ||||
| public class Case { | ||||
|  | ||||
|     protected int valeurX; | ||||
|     protected int valeurY; | ||||
|     public String type; | ||||
|     public int value; | ||||
|  | ||||
|     public Case(int x, int y, String t){ | ||||
|         this.valeurX = x; | ||||
|         this.valeurY = y; | ||||
|         this.type = t; | ||||
|     } | ||||
|  | ||||
| 	public String getLabel(){ | ||||
| 		return (""); | ||||
| 	} | ||||
|  | ||||
| 	public String getLabelPv(){ | ||||
| 		return (""); | ||||
| 	} | ||||
|  | ||||
|     public int getValeurX(){ | ||||
|         return this.valeurX; | ||||
|     } | ||||
|  | ||||
|     public int getValeurY(){ | ||||
|         return this.valeurY; | ||||
|     } | ||||
|  | ||||
| 	public int getValue(){ | ||||
| 		return this.value; | ||||
| 	} | ||||
|  | ||||
| 	public void setValue(int val){ | ||||
| 		this.value = val; | ||||
| 	} | ||||
|  | ||||
|     public int getPv(){ | ||||
| 		return 0; | ||||
| 	} | ||||
|  | ||||
| 	public void setPv(int pdv){ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	public Arme getArme(){ | ||||
| 		return new Arme(0, 0, 0); | ||||
| 	} | ||||
|  | ||||
| 	public void setArme(int atk){ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	public boolean rencontrer(Case c){ | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
|     public Case newRandomCase(int x, int y){ | ||||
|         Random rand = new Random(); | ||||
|         int aleatoire = rand.nextInt(); | ||||
|         if(aleatoire < 0){ | ||||
| 			aleatoire = -aleatoire; | ||||
| 		} | ||||
|         if (aleatoire % 2 == 0){ | ||||
|         	aleatoire = rand.nextInt(); | ||||
|         	if(aleatoire < 0){ | ||||
| 				aleatoire = -aleatoire; | ||||
| 			} | ||||
|  | ||||
|             return new Monstre(aleatoire % 40 + 1, x, y); | ||||
|         } else { | ||||
|             return new CaseBonus(x, y, "temp").newRandomCaseBonus(x, y); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/CaseBonus.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/CaseBonus.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										40
									
								
								SAe2.1/CaseBonus.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								SAe2.1/CaseBonus.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.util.*; | ||||
|  | ||||
| public class CaseBonus extends Case { | ||||
|  | ||||
| 	public CaseBonus(int x, int y, String type){ | ||||
| 		super(x, y, type); | ||||
| 	} | ||||
|  | ||||
| 	public CaseBonus newRandomCaseBonus(int x, int y){ | ||||
| 		Random rand = new Random(); | ||||
| 		int aleatoire = rand.nextInt(); | ||||
| 		if(aleatoire < 0){ | ||||
| 			aleatoire = -aleatoire; | ||||
| 		} | ||||
| 		if (aleatoire % 100 < 25){ | ||||
| 			aleatoire = rand.nextInt(); | ||||
| 			if(aleatoire < 0){ | ||||
| 				aleatoire = -aleatoire; | ||||
| 			} | ||||
| 			return new Potion(aleatoire % 40 + 1, x, y); | ||||
| 		} else { | ||||
| 			if (aleatoire % 100 > 64){ | ||||
| 				aleatoire = rand.nextInt(); | ||||
| 				if(aleatoire < 0){ | ||||
| 					aleatoire = -aleatoire; | ||||
| 				} | ||||
| 				return new Arme(aleatoire % 50 + 1, x, y); | ||||
| 			} else { | ||||
| 				aleatoire = rand.nextInt(); | ||||
| 				if(aleatoire < 0){ | ||||
| 					aleatoire = -aleatoire; | ||||
| 				} | ||||
| 				return new Or(aleatoire % 100 + 1, x, y); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Controleur.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Controleur.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										225
									
								
								SAe2.1/Controleur.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										225
									
								
								SAe2.1/Controleur.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,225 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.util.*; | ||||
| import java.awt.event.*; | ||||
|  | ||||
| public class Controleur extends JFrame implements KeyListener { | ||||
|  | ||||
| 	private Case[][] tableauCase; | ||||
| 	private VuePlateau plateau; | ||||
| 	private int xHeros; | ||||
| 	private int yHeros; | ||||
| 	private int points; | ||||
|  | ||||
| 	public Controleur() { | ||||
| 		this.xHeros = 1; | ||||
| 		this.yHeros = 1; | ||||
| 		this.points = 0; | ||||
| 		this.tableauCase = new Case[3][3]; | ||||
| 		VueCase[][] tabCase = new VueCase[3][3]; | ||||
|  | ||||
| 		for (int i = 0; i < 3; i++) { | ||||
| 			for (int j = 0; j < 3; j++) { | ||||
| 				if (i == this.xHeros && j == this.yHeros) { | ||||
| 					this.tableauCase[i][j] = new Heros(i, j); | ||||
| 					tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 					tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 					tabCase[i][j].setSize(200, 200); | ||||
| 					this.add(tabCase[i][j]); | ||||
| 				} else { | ||||
| 					Case c = new Case(i, j, "temp"); | ||||
| 					this.tableauCase[i][j] = c.newRandomCase(i, j); | ||||
| 					tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 					tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 					tabCase[i][j].setSize(200, 200); | ||||
| 					this.add(tabCase[i][j]); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		this.plateau = new VuePlateau(tabCase); | ||||
| 		this.add(this.plateau); | ||||
|  | ||||
| 		for (int i = 0; i < 3; i++) { | ||||
| 			for (int j = 0; j < 3; j++) { | ||||
| 				this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		this.addKeyListener(this); | ||||
| 	} | ||||
|  | ||||
| 	private void rencontre(int xNew, int yNew) { | ||||
| 		int tempX = xHeros; | ||||
| 		int tempY = yHeros; | ||||
| 		int tempZ; | ||||
|  | ||||
| 		if (!this.tableauCase[xHeros][yHeros].rencontrer(this.tableauCase[xNew][yNew])) { | ||||
| 			if (this.tableauCase[xHeros][yHeros].getArme().getValue() > 0) { | ||||
| 				if (this.tableauCase[xHeros][yHeros].getArme().getValue() > this.tableauCase[xNew][yNew].getPv()) { | ||||
| 					tempZ=this.tableauCase[xNew][yNew].getPv(); | ||||
| 					this.tableauCase[xHeros][yHeros].setArme(this.tableauCase[xHeros][yHeros].getArme().getValue()-tempZ); | ||||
| 					this.tableauCase[xNew][yNew] = new Or(this.tableauCase[xNew][yNew].getPv() ,xNew ,yNew ); | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 				} else { | ||||
| 					this.tableauCase[xNew][yNew].setPv(this.tableauCase[xNew][yNew].getPv() - this.tableauCase[xHeros][yHeros].getArme().getValue()); | ||||
| 					this.tableauCase[xHeros][yHeros].setArme(0); | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					}				 | ||||
| 				} | ||||
| 			} | ||||
| 		} else { | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("or")) { | ||||
| 				this.points += this.tableauCase[xNew][yNew].getValue(); | ||||
| 				this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 				this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros]; | ||||
| 				this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros); | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 				xHeros = xNew; | ||||
| 				yHeros = yNew; | ||||
| 			} | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("arme")) { | ||||
| 				if (this.tableauCase[xHeros][yHeros].getArme().getValue() < this.tableauCase[xNew][yNew].getValue()) { | ||||
| 					this.tableauCase[xHeros][yHeros].setArme(this.tableauCase[xNew][yNew].getValue()); | ||||
| 					this.points += this.tableauCase[xNew][yNew].getValue(); | ||||
| 					this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 					this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros]; | ||||
| 					this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros); | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 					xHeros = xNew; | ||||
| 					yHeros = yNew; | ||||
| 				} else { | ||||
| 					this.points += this.tableauCase[xNew][yNew].getValue(); | ||||
| 					this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 					this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros]; | ||||
| 					this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros); | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 					xHeros = xNew; | ||||
| 					yHeros = yNew; | ||||
| 				} | ||||
| 			} | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("potion")) { | ||||
| 				this.points += this.tableauCase[xNew][yNew].getValue(); | ||||
| 				this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 				this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros]; | ||||
| 				this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros); | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 				xHeros = xNew; | ||||
| 				yHeros = yNew; | ||||
| 			} | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("monstre")) { | ||||
| 				this.tableauCase[xHeros][yHeros].setPv(this.tableauCase[xHeros][yHeros].getPv()-this.tableauCase[xNew][yNew].getPv()); | ||||
| 				if (this.tableauCase[xHeros][yHeros].getPv() <= 0) { | ||||
| 					System.out.println("GameOver, votre score final est de : " + this.points); | ||||
| 					this.dispose(); | ||||
| 				} else { | ||||
| 					this.points += this.tableauCase[xNew][yNew].getValue(); | ||||
| 					this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 					this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros]; | ||||
| 					this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros); | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 					xHeros = xNew; | ||||
| 					yHeros = yNew; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void keyTyped(KeyEvent e) { | ||||
|  | ||||
| 	} | ||||
| 	@Override | ||||
| 	public void keyPressed(KeyEvent e) { | ||||
|  | ||||
| 	} | ||||
| 	@Override | ||||
| 	public void keyReleased(KeyEvent e) { | ||||
| 		int tempX = xHeros; | ||||
| 		int tempY = yHeros; | ||||
|  | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_DOWN) { | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempY + 1 > 2) { | ||||
| 				System.out.println("Impossible d'aller plus bas."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX, tempY + 1); | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_UP) { | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempY - 1 < 0) { | ||||
| 				System.out.println("Impossible d'aller plus haut."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX, tempY - 1); | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_LEFT) { | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempX - 1 < 0) { | ||||
| 				System.out.println("Impossible d'aller plus à gauche."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX - 1, tempY); | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_RIGHT) { | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempX + 1 > 2) { | ||||
| 				System.out.println("Impossible d'aller plus à droite."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX + 1, tempY); | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/DonjonInfini.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/DonjonInfini.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										18
									
								
								SAe2.1/DonjonInfini.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								SAe2.1/DonjonInfini.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.lang.*; | ||||
|  | ||||
| public class DonjonInfini{ | ||||
|  | ||||
| 	private Controleur donjon; | ||||
|  | ||||
| 	public static void main(String[] args) { | ||||
| 		 | ||||
| 		Controleur fenetre = new Controleur(); | ||||
| 		fenetre.setSize(600, 680); | ||||
|     	fenetre.setLocation(0, 0); | ||||
|     	fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||
| 		fenetre.setVisible(true); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Heros.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Heros.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										52
									
								
								SAe2.1/Heros.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								SAe2.1/Heros.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| public class Heros extends Case { | ||||
|  | ||||
|     private Arme arme; | ||||
|     private int pv; | ||||
|  | ||||
|     public Heros(int x, int y) { | ||||
|         super(x, y, "hero"); | ||||
|         this.pv = 250; | ||||
|         this.arme = new Arme(0, x, y); | ||||
|     } | ||||
|  | ||||
|     public String getLabelPv() { | ||||
|         return String.valueOf(this.pv); | ||||
|     } | ||||
|  | ||||
|     public int getPv(){ | ||||
| 		return this.pv; | ||||
| 	} | ||||
|  | ||||
| 	public void setPv(int pdv){ | ||||
| 		this.pv=pdv; | ||||
| 	} | ||||
|  | ||||
| 	public Arme getArme(){ | ||||
| 		return this.arme; | ||||
| 	} | ||||
|  | ||||
| 	public void setArme(int atk){ | ||||
| 		this.arme.value=atk; | ||||
| 	} | ||||
|  | ||||
|     public boolean rencontrer(Case c) { | ||||
|         if (c.type.equals("or")) { | ||||
|             return true; | ||||
|         } | ||||
|         if (c.type.equals("arme")) { | ||||
|             return true; | ||||
|         } | ||||
|         if (c.type.equals("potion")) { | ||||
|             this.pv += c.getValue(); | ||||
|             return true; | ||||
|         } | ||||
|         if (c.type.equals("monstre")) { | ||||
|             if (this.arme.value > 0) { | ||||
|                 return false; | ||||
|             } else { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Monstre.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Monstre.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										22
									
								
								SAe2.1/Monstre.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								SAe2.1/Monstre.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| public class Monstre extends Case{ | ||||
|  | ||||
| 	private int pv; | ||||
|  | ||||
| 	public Monstre(int pdv, int x, int y){ | ||||
| 		super(x, y, "monstre"); | ||||
| 		this.pv = pdv; | ||||
| 	} | ||||
|  | ||||
| 	public String getLabelPv(){ | ||||
| 		return (""+this.pv); | ||||
| 	} | ||||
|  | ||||
| 	public int getPv(){ | ||||
| 		return this.pv; | ||||
| 	} | ||||
|  | ||||
| 	public void setPv(int pdv){ | ||||
| 		this.pv=pdv; | ||||
| 	} | ||||
|  | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Or.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Or.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										20
									
								
								SAe2.1/Or.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								SAe2.1/Or.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| public class Or extends CaseBonus{ | ||||
| 	public int value; | ||||
|  | ||||
| 	public Or(int v, int x, int y){ | ||||
| 		super(x, y, "or"); | ||||
| 		this.value = v; | ||||
| 	} | ||||
|  | ||||
| 	public String getLabel(){ | ||||
| 		return (""+this.value); | ||||
| 	} | ||||
|  | ||||
| 	public int getValue(){ | ||||
| 		return this.value; | ||||
| 	} | ||||
|  | ||||
| 	public void setValue(int val){ | ||||
| 		this.value = val; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Potion.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Potion.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										20
									
								
								SAe2.1/Potion.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								SAe2.1/Potion.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| public class Potion extends CaseBonus{ | ||||
| 	public int value; | ||||
|  | ||||
| 	public Potion(int v, int x, int y){ | ||||
| 		super(x, y, "potion"); | ||||
| 		this.value = v; | ||||
| 	} | ||||
|  | ||||
| 	public String getLabel(){ | ||||
| 		return (""+this.value); | ||||
| 	} | ||||
|  | ||||
| 	public int getValue(){ | ||||
| 		return this.value; | ||||
| 	} | ||||
|  | ||||
| 	public void setValue(int val){ | ||||
| 		this.value = val; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/SAe2.1.tar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/SAe2.1.tar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/Sujet.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/Sujet.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/VueCase.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/VueCase.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										58
									
								
								SAe2.1/VueCase.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								SAe2.1/VueCase.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
|  | ||||
| public class VueCase extends JPanel { | ||||
|  | ||||
|     private Case caseN; | ||||
|  | ||||
|     public VueCase(Case c) { | ||||
|         this.caseN = c; | ||||
|         this.repaint(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void paintComponent(Graphics p) { | ||||
|         super.paintComponent(p); | ||||
|         Graphics p2 = p.create(); | ||||
|         if (this.isOpaque()) { | ||||
|             // Obligatoire : on repeint toute la surface avec la couleur de fond | ||||
|             p2.setColor(this.getBackground()); | ||||
|             p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|         } | ||||
|         if (this.caseN.type.equals("monstre")) { | ||||
|             p2.setColor(Color.RED); | ||||
|             p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|             p2.setColor(Color.BLACK); | ||||
|             p2.drawString("Monstre, Pv restant :" + caseN.getLabelPv(), (this.getWidth() / 2) - 50, (this.getHeight() / 2) - 10); | ||||
|         } | ||||
|         if (this.caseN.type.equals("or")) { | ||||
|             p2.setColor(Color.YELLOW); | ||||
|             p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|             p2.setColor(Color.BLACK); | ||||
|             p2.drawString("Or, Points obtenu :" + caseN.getLabel(), (this.getWidth() / 2) - 50, (this.getHeight() / 2) - 10); | ||||
|         } | ||||
|         if (this.caseN.type.equals("hero")) { | ||||
|             p2.setColor(Color.CYAN); | ||||
|             p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|             p2.setColor(Color.BLACK); | ||||
|             p2.drawString("Hero, Pv :" + caseN.getLabelPv(), (this.getWidth() / 2) - 30, (this.getHeight() / 2) - 10); | ||||
|         } | ||||
|         if (this.caseN.type.equals("potion")) { | ||||
|             p2.setColor(Color.GREEN); | ||||
|             p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|             p2.setColor(Color.BLACK); | ||||
|             p2.drawString("Potion, Pv rendu:  " + caseN.getLabel(), (this.getWidth() / 2) - 60, (this.getHeight() / 2) - 10); | ||||
|         } | ||||
|         if (this.caseN.type.equals("arme")) { | ||||
|             p2.setColor(Color.BLUE); | ||||
|             p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|             p2.setColor(Color.BLACK); | ||||
|             p2.drawString("Arme, Atk: " + caseN.getLabel(), (this.getWidth() / 2) - 40, (this.getHeight() / 2) - 10); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void setCase(Case c) { | ||||
|         this.caseN = c; | ||||
|         this.repaint(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/VuePlateau.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/VuePlateau.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										39
									
								
								SAe2.1/VuePlateau.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								SAe2.1/VuePlateau.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.lang.*; | ||||
|  | ||||
| public class VuePlateau  extends JPanel{ | ||||
|  | ||||
| 	private VueCase[][] tableauCase; | ||||
| 	private int vuePoints; | ||||
|  | ||||
| 	public VuePlateau(VueCase[][] tabl){ | ||||
| 		this.tableauCase=tabl; | ||||
| 		this.vuePoints=0; | ||||
| 	} | ||||
|  | ||||
| 	public void upPoint(int c){ | ||||
| 		this.vuePoints += c; | ||||
| 		this.repaint(); | ||||
| 	} | ||||
|  | ||||
| 	public void paintComponent(Graphics g) { | ||||
| 	super.paintComponent(g); | ||||
| 	Graphics p2 = g.create(); | ||||
| 	if (this.isOpaque()) { | ||||
| 		// obligatoire : on repeint toute la surface avec la couleur de fond | ||||
| 		p2.setColor(this.getBackground()); | ||||
| 		p2.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
| 	} | ||||
| 		p2.setColor(Color.BLACK); | ||||
| 		p2.drawString("Points :" + this.vuePoints, this.getWidth() - 70, this.getHeight() - 10); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	public void update(Case nc, int x, int y){ | ||||
| 		tableauCase[x][y].setCase(nc); | ||||
| 		this.repaint(); | ||||
| 	} | ||||
|  | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAe_commente.tar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAe_commente.tar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Arme.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Arme.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										20
									
								
								SAe2.1/commentente/SAé/Arme.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								SAe2.1/commentente/SAé/Arme.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| public class Arme extends CaseBonus{ | ||||
| 	public int value; | ||||
|  | ||||
| 	public Arme(int v, int x, int y){ | ||||
| 		super(x, y, "arme"); | ||||
| 		this.value = v; | ||||
| 	} | ||||
|  | ||||
| 	public String getLabel(){ | ||||
| 		return (""+this.value); | ||||
| 	} | ||||
|  | ||||
| 	public int getValue(){ | ||||
| 		return this.value; | ||||
| 	} | ||||
|  | ||||
| 	public void setValue(int val){ | ||||
| 		this.value = val; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Case.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Case.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										80
									
								
								SAe2.1/commentente/SAé/Case.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								SAe2.1/commentente/SAé/Case.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.util.*; | ||||
|  | ||||
| public class Case { | ||||
| 	//Variables pour stocker les coordonnées x et y de la case, ainsi que son type et sa valeur | ||||
|     protected int valeurX; | ||||
|     protected int valeurY; | ||||
|     public String type; | ||||
|     public int value; | ||||
|  | ||||
|     public Case(int x, int y, String t){ | ||||
|         this.valeurX = x; | ||||
|         this.valeurY = y; | ||||
|         this.type = t; | ||||
|     } | ||||
|     //Méthode pour obtenir le label de la case | ||||
| 	public String getLabel(){ | ||||
| 		return (""); | ||||
| 	} | ||||
| 	//Méthode pour obtenir le label des points de vie de la case | ||||
| 	public String getLabelPv(){ | ||||
| 		return (""); | ||||
| 	} | ||||
| 	//Méthode pour obtenir la valeur de la coordonnée x de la case | ||||
|     public int getValeurX(){ | ||||
|         return this.valeurX; | ||||
|     } | ||||
|     //Méthode pour obtenir la valeur de la coordonnée y de la case | ||||
|     public int getValeurY(){ | ||||
|         return this.valeurY; | ||||
|     } | ||||
|     //Méthode pour obtenir la valeur de la case | ||||
| 	public int getValue(){ | ||||
| 		return this.value; | ||||
| 	} | ||||
| 	//Méthode pour définir la valeur de la case | ||||
| 	public void setValue(int val){ | ||||
| 		this.value = val; | ||||
| 	} | ||||
| 	//Méthode pour obtenir les points de vie de la case | ||||
|     public int getPv(){ | ||||
| 		return 0; | ||||
| 	} | ||||
| 	//Méthode pour définir les points de vie de la case | ||||
| 	public void setPv(int pdv){ | ||||
|  | ||||
| 	} | ||||
| 	//Méthode pour obtenir l'arme de la case | ||||
| 	public Arme getArme(){ | ||||
| 		return new Arme(0, 0, 0); | ||||
| 	} | ||||
| 	//Méthode pour définir l'arme de la case | ||||
| 	public void setArme(int atk){ | ||||
|  | ||||
| 	} | ||||
| 	//Méthode pour vérifier si on rencontre une case | ||||
| 	public boolean rencontrer(Case c){ | ||||
| 		return false; | ||||
| 	} | ||||
| 	//Méthode pour générer une nouvelle case aléatoire | ||||
|     public Case newRandomCase(int x, int y){ | ||||
|         Random rand = new Random(); | ||||
|         int aleatoire = rand.nextInt();  //Création de la variable aleatoire et incrémentation d'une valeur aléatoire | ||||
|         if(aleatoire < 0){				 //Si la valeur de aleatoire est inférieure à 0 | ||||
| 			aleatoire = -aleatoire;			//Alors on change le signe pour qu'il soit positif | ||||
| 		} | ||||
|         if (aleatoire % 2 == 0){ 	//Si le reste de la division d'aleatoire par 2 vaut 0 (donc pair) | ||||
|         	aleatoire = rand.nextInt(); | ||||
|         	if(aleatoire < 0){ | ||||
| 				aleatoire = -aleatoire; | ||||
| 			} | ||||
|  | ||||
|             return new Monstre(aleatoire % 40 + 1, x, y); | ||||
|         } else { | ||||
|             return new CaseBonus(x, y, "temp").newRandomCaseBonus(x, y); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/CaseBonus.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/CaseBonus.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										40
									
								
								SAe2.1/commentente/SAé/CaseBonus.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								SAe2.1/commentente/SAé/CaseBonus.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.util.*; | ||||
|  | ||||
| public class CaseBonus extends Case { | ||||
|  | ||||
| 	public CaseBonus(int x, int y, String type){ | ||||
| 		super(x, y, type); | ||||
| 	} | ||||
|  | ||||
| 	public CaseBonus newRandomCaseBonus(int x, int y){ | ||||
| 		Random rand = new Random(); | ||||
| 		int aleatoire = rand.nextInt(); | ||||
| 		if(aleatoire < 0){ | ||||
| 			aleatoire = -aleatoire; | ||||
| 		} | ||||
| 		if (aleatoire % 100 < 25){ | ||||
| 			aleatoire = rand.nextInt(); | ||||
| 			if(aleatoire < 0){ | ||||
| 				aleatoire = -aleatoire; | ||||
| 			} | ||||
| 			return new Potion(aleatoire % 40 + 1, x, y); | ||||
| 		} else { | ||||
| 			if (aleatoire % 100 > 64){ | ||||
| 				aleatoire = rand.nextInt(); | ||||
| 				if(aleatoire < 0){ | ||||
| 					aleatoire = -aleatoire; | ||||
| 				} | ||||
| 				return new Arme(aleatoire % 50 + 1, x, y); | ||||
| 			} else { | ||||
| 				aleatoire = rand.nextInt(); | ||||
| 				if(aleatoire < 0){ | ||||
| 					aleatoire = -aleatoire; | ||||
| 				} | ||||
| 				return new Or(aleatoire % 100 + 1, x, y); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Controleur.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Controleur.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										295
									
								
								SAe2.1/commentente/SAé/Controleur.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										295
									
								
								SAe2.1/commentente/SAé/Controleur.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,295 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.util.*; | ||||
| import java.awt.event.*; | ||||
|  | ||||
| public class Controleur extends JFrame implements KeyListener { | ||||
|  | ||||
| 	private Case[][] tableauCase;	//Création d'un tableau pour stocker les cases du plateau de jeu | ||||
| 	private VuePlateau plateau;		//Création d'une variable vue du plateau de jeu | ||||
| 	private int xHeros;				//Création d'une variable coordonées x du héros | ||||
| 	private int yHeros;				//Création d'une variable coordonées Y du héros | ||||
| 	private int points;				//Création d'une variable points | ||||
|  | ||||
| 	public Controleur() { | ||||
| 		 | ||||
| 		//Initialisation des coordonnées du héros et des points | ||||
| 		this.xHeros = 1; | ||||
| 		this.yHeros = 1; | ||||
| 		this.points = 0; | ||||
|  | ||||
| 		//Création du tableau de cases et de vues de cases | ||||
| 		this.tableauCase = new Case[3][3]; | ||||
| 		VueCase[][] tabCase = new VueCase[3][3]; | ||||
|  | ||||
| 		//Parcours du tableau de cases | ||||
| 		for (int i = 0; i < 3; i++) { | ||||
| 			for (int j = 0; j < 3; j++) { | ||||
| 				if (i == this.xHeros && j == this.yHeros) { | ||||
|  | ||||
| 					//Création d'une instance de la classe Heros pour le héros | ||||
| 					this.tableauCase[i][j] = new Heros(i, j); | ||||
| 					//Création d'une vue de case pour le héros | ||||
| 					tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 					this.add(tabCase[i][j]); | ||||
| 				} else { | ||||
| 					//Création d'une instance de la classe Case pour les autres cases | ||||
| 					Case c = new Case(i, j, "temp"); | ||||
|  | ||||
| 					//Génération d'une case aléatoire | ||||
| 					this.tableauCase[i][j] = c.newRandomCase(i, j); | ||||
|  | ||||
| 					//Création d'une vue de case pour la case aléatoire | ||||
| 					tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 					this.add(tabCase[i][j]); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		//Création de la vue du plateau en utilisant le tableau de vues de cases | ||||
| 		this.setLayout(new GridLayout(4,4)); | ||||
| 		this.plateau = new VuePlateau(tabCase); | ||||
| 		this.add(this.plateau); | ||||
|  | ||||
| 		//Mise à jour de la vue du plateau avec les cases du tableau | ||||
| 		for (int i = 0; i < 3; i++) { | ||||
| 			for (int j = 0; j < 3; j++) { | ||||
| 				this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 			} | ||||
| 		} | ||||
| 		//Ajout du contrôleur en tant que KeyListener pour gérer les événements clavier | ||||
| 		this.addKeyListener(this); | ||||
| 	} | ||||
|  | ||||
| 	private void rencontre(int xNew, int yNew) { | ||||
| 		int tempX = xHeros; | ||||
| 		int tempY = yHeros; | ||||
| 		int tempZ; | ||||
| 		VueCase[][] tabCase = new VueCase[3][3]; | ||||
|  | ||||
| 		if (!this.tableauCase[xHeros][yHeros].rencontrer(this.tableauCase[xNew][yNew])) {  								//Vérifie si le héros peut rencontrer la case aux nouvelles coordonnées | ||||
| 			if (this.tableauCase[xHeros][yHeros].getArme().getValue() > 0) {											//Vérifie si le héros a une arme et si sa valeur est supérieure à 0 | ||||
| 				if (this.tableauCase[xHeros][yHeros].getArme().getValue() > this.tableauCase[xNew][yNew].getPv()) {		// Vérifie si la valeur de l'arme du héros est supérieure aux points de vie de la case | ||||
| 					tempZ=this.tableauCase[xNew][yNew].getPv();   														//Réduit la valeur de l'arme du héros de la valeur des points de vie de la case | ||||
| 					this.tableauCase[xHeros][yHeros].setArme(this.tableauCase[xHeros][yHeros].getArme().getValue()-tempZ); | ||||
| 					this.tableauCase[xNew][yNew] = new Or(this.tableauCase[xNew][yNew].getPv() ,xNew ,yNew );		//Remplace la case par une case "Or" avec la valeur des points de vie | ||||
| 					 | ||||
| 					//Met à jour la vue du plateau | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 						} | ||||
| 					} | ||||
| 				} else { | ||||
|  | ||||
| 					this.tableauCase[xNew][yNew].setPv(this.tableauCase[xNew][yNew].getPv() - this.tableauCase[xHeros][yHeros].getArme().getValue());	//Réduit les points de vie de la case par la valeur de l'arme du héros | ||||
| 					this.tableauCase[xHeros][yHeros].setArme(0); | ||||
|  | ||||
| 					//Met à jour la vue du plateau | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 						} | ||||
| 					}				 | ||||
| 				} | ||||
| 			} | ||||
| 		} else { | ||||
|  | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("or")) {										//Vérifie si la case aux nouvelles coordonnées est de type "or" | ||||
| 				this.points += this.tableauCase[xNew][yNew].getValue();									//Ajoute la valeur de la case aux points du héros et met à jour la vue du plateau | ||||
| 				this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 				this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros];						//Remplace la case par le héros | ||||
| 				this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros);	//Génère une nouvelle case aléatoire à l'ancienne position du héros | ||||
| 				 | ||||
| 				//Met à jour la vue du plateau | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 						} | ||||
| 					} | ||||
|  | ||||
| 				//On met à jour les coordonnées du héros | ||||
| 				xHeros = xNew; | ||||
| 				yHeros = yNew; | ||||
| 			} | ||||
|  | ||||
|  | ||||
| 			 | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("arme")) {			//Vérifie si la case aux nouvelles coordonnées est de type "arme" | ||||
| 				if (this.tableauCase[xHeros][yHeros].getArme().getValue() < this.tableauCase[xNew][yNew].getValue()) {	//Vérifie si la valeur de l'arme du héros est inférieure à la valeur de l'arme de la case | ||||
| 					this.tableauCase[xHeros][yHeros].setArme(this.tableauCase[xNew][yNew].getValue());			//Si c'est le cas, le héros récupère l'arme de la case | ||||
| 					this.points += this.tableauCase[xNew][yNew].getValue();										//Ajoute la valeur de la case aux points du héros et met à jour la vue du plateau | ||||
| 					this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 					this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros];							//Remplace la case par le héros | ||||
| 					this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros); | ||||
| 					 | ||||
| 					//Met à jour la vue du plateau | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 						} | ||||
| 					} | ||||
| 					//Met à jour les coordonnées du héros | ||||
| 					xHeros = xNew; | ||||
| 					yHeros = yNew; | ||||
| 				} else { | ||||
| 					this.points += this.tableauCase[xNew][yNew].getValue();											//Ajoute la valeur de la case aux points du héros et met à jour la vue du plateau | ||||
| 					this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue());	 | ||||
| 					this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros];								//Remplace la case par le héros | ||||
| 					this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros);	//Génère une nouvelle case aléatoire à l'ancienne position du héros | ||||
| 					 | ||||
| 					//Met à jour la vue du plateau | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 						} | ||||
| 					} | ||||
| 					//On met à jour les coordonnées du héros | ||||
| 					xHeros = xNew; | ||||
| 					yHeros = yNew; | ||||
| 				} | ||||
| 			} | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("potion")) {		//Vérifie si la case aux nouvelles coordonnées est de type "potion" | ||||
| 				this.points += this.tableauCase[xNew][yNew].getValue();		//Ajoute la valeur de la case aux points du héros et met à jour la vue du plateau | ||||
| 				this.plateau.upPoint(this.tableauCase[xNew][yNew].getValue()); | ||||
| 				this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros];	//Remplace la case par le héros	 | ||||
| 				this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros);	//Génère une nouvelle case aléatoire à l'ancienne position du héros | ||||
| 				//On met à jour la vue du plateau | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 						} | ||||
| 					} | ||||
| 				//On met à jour les coordonnées du héros | ||||
| 				xHeros = xNew; | ||||
| 				yHeros = yNew; | ||||
| 			} | ||||
| 			if (this.tableauCase[xNew][yNew].type.equals("monstre")) {									//Vérifie si la case aux nouvelles coordonnées est de type "monstre" | ||||
| 				this.tableauCase[xHeros][yHeros].setPv(this.tableauCase[xHeros][yHeros].getPv()-this.tableauCase[xNew][yNew].getPv());		//Réduit les points de vie du héros par la valeur des points de vie du monstre | ||||
| 				if (this.tableauCase[xHeros][yHeros].getPv() <= 0) {			//Si les points de vie du héros sont inférieurs ou égaux à 0, affiche un message de Game Over et termine le jeu							 | ||||
| 					System.out.println("GameOver, votre score final est de : " + this.points); | ||||
| 					this.dispose(); | ||||
| 				} else { | ||||
| 					this.points += this.tableauCase[xNew][yNew].getPv();			//Ajoute la valeur de la case aux points du héros et met à jour la vue du plateau | ||||
| 					this.plateau.upPoint(this.tableauCase[xNew][yNew].getPv()); | ||||
| 					this.tableauCase[xNew][yNew] = this.tableauCase[xHeros][yHeros];			//Remplace la case par le héros | ||||
| 					this.tableauCase[xHeros][yHeros] = new Case(xHeros, yHeros, "temp").newRandomCase(xHeros, yHeros);	//Génère une nouvelle case aléatoire à l'ancienne position du héros | ||||
| 					//On met à jour la vue du plateau | ||||
| 					for (int i = 0; i < 3; i++) { | ||||
| 						for (int j = 0; j < 3; j++) { | ||||
| 							this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 							tabCase[i][j] = new VueCase(tableauCase[i][j]); | ||||
| 							tabCase[i][j].setLocation(i * 200, j * 200); | ||||
| 							tabCase[i][j].setSize(200, 200); | ||||
| 							this.add(tabCase[i][j]); | ||||
| 						} | ||||
| 					} | ||||
| 					//On met à jour les coordonnées du héros | ||||
| 					xHeros = xNew; | ||||
| 					yHeros = yNew; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void keyTyped(KeyEvent e) {		//Cette méthode est appelée lorsqu'une touche est tapée (enfoncée puis relâchée) sur le clavier | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void keyPressed(KeyEvent e) { | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void keyReleased(KeyEvent e) { | ||||
| 		//On récupère les coordonnées actuelles du héros | ||||
| 		int tempX = xHeros; | ||||
| 		int tempY = yHeros; | ||||
|  | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_RIGHT) {	//Si la touche enfoncée est la flèche du bas | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempY + 1 > 2) {		//Vérifie si le déplacement vers le bas est possible | ||||
| 				System.out.println("Impossible d'aller plus à droite."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX, tempY + 1);		//Appelle la méthode "rencontre" pour gérer la rencontre avec la case en bas | ||||
| 				//On met à jour l'affichage du plateau | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_LEFT) {   //Si la touche enfoncée est la flèche du haut | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempY - 1 < 0) {	//Vérifie si le déplacement vers le haut est possible | ||||
| 				System.out.println("Impossible d'aller plus à gauche."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX, tempY - 1);	//Appelle la méthode "rencontre" pour gérer la rencontre avec la case en haut | ||||
| 				//On met à jour l'affichage du plateau | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_UP) {	//Si la touche enfoncée est la flèche à gauche | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempX - 1 < 0) {	//Vérifie si le déplacement vers la gauche est possible | ||||
| 				System.out.println("Impossible d'aller plus haut."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX - 1, tempY);	//Appelle la méthode "rencontre" pour gérer la rencontre avec la case à gauche | ||||
| 				//On met à jour l'affichage du plat | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (e.getKeyCode() == KeyEvent.VK_DOWN) {	//Si la touche enfoncée est la flèche à droite | ||||
| 			tempX = xHeros; | ||||
| 			tempY = yHeros; | ||||
| 			if (tempX + 1 > 2) {				//Vérifie si le déplacement vers la droite est possible | ||||
| 				System.out.println("Impossible d'aller plus bas."); | ||||
| 			} else { | ||||
| 				this.rencontre(tempX + 1, tempY);	//Appelle la méthode "rencontre" pour gérer la rencontre avec la case à droite | ||||
| 				//On met à jour l'affichage du plat | ||||
| 				for (int i = 0; i < 3; i++) { | ||||
| 					for (int j = 0; j < 3; j++) { | ||||
| 						this.plateau.update(this.tableauCase[i][j], i, j); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/DonjonInfini.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/DonjonInfini.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										18
									
								
								SAe2.1/commentente/SAé/DonjonInfini.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								SAe2.1/commentente/SAé/DonjonInfini.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.event.*; | ||||
| import java.lang.*; | ||||
|  | ||||
| public class DonjonInfini{ | ||||
|  | ||||
| 	private Controleur donjon; | ||||
|  | ||||
| 	public static void main(String[] args) { | ||||
| 		 | ||||
| 		Controleur fenetre = new Controleur(); | ||||
| 		fenetre.setSize(600, 680); | ||||
|     	fenetre.setLocation(0, 0); | ||||
|     	fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||
| 		fenetre.setVisible(true); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Heros.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Heros.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										52
									
								
								SAe2.1/commentente/SAé/Heros.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								SAe2.1/commentente/SAé/Heros.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| public class Heros extends Case { | ||||
|  | ||||
|     private Arme arme; | ||||
|     private int pv; | ||||
|  | ||||
|     public Heros(int x, int y) { | ||||
|         super(x, y, "hero"); | ||||
|         this.pv = 250; | ||||
|         this.arme = new Arme(0, x, y); | ||||
|     } | ||||
|  | ||||
|     public String getLabelPv() { | ||||
|         return String.valueOf(this.pv); | ||||
|     } | ||||
|  | ||||
|     public int getPv(){ | ||||
| 		return this.pv; | ||||
| 	} | ||||
|  | ||||
| 	public void setPv(int pdv){ | ||||
| 		this.pv=pdv; | ||||
| 	} | ||||
|  | ||||
| 	public Arme getArme(){ | ||||
| 		return this.arme; | ||||
| 	} | ||||
|  | ||||
| 	public void setArme(int atk){ | ||||
| 		this.arme.value=atk; | ||||
| 	} | ||||
|  | ||||
|     public boolean rencontrer(Case c) { | ||||
|         if (c.type.equals("or")) { | ||||
|             return true; | ||||
|         } | ||||
|         if (c.type.equals("arme")) { | ||||
|             return true; | ||||
|         } | ||||
|         if (c.type.equals("potion")) { | ||||
|             this.pv += c.getValue(); | ||||
|             return true; | ||||
|         } | ||||
|         if (c.type.equals("monstre")) { | ||||
|             if (this.arme.value > 0) { | ||||
|                 return false; | ||||
|             } else { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Monstre.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Monstre.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										23
									
								
								SAe2.1/commentente/SAé/Monstre.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								SAe2.1/commentente/SAé/Monstre.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
|  | ||||
| public class Monstre extends Case{	//Déclaration de la classe Monstre | ||||
|  | ||||
| 	private int pv;   //Variable pour stocker les points de vie du monstre | ||||
|  | ||||
| 	public Monstre(int pdv, int x, int y){	//Constructeur de la classe Monstre | ||||
| 		super(x, y, "monstre");		//Appel du constructeur de la classe parente Case en passant les coordonnées x et y, ainsi que le type "monstre" | ||||
| 		this.pv = pdv;		//Initialisation de l'attribut pv avec la valeur pdv (= point de vie) | ||||
| 	} | ||||
|  | ||||
| 	public String getLabelPv(){		//Méthode pour obtenir le label des points de vie du monstre | ||||
| 		return (""+this.pv);		 //Retourne les points de vie du monstre convertis en chaîne de caractères | ||||
| 	} | ||||
|  | ||||
| 	public int getPv(){		//Méthode pour obtenir les points de vie du monstre | ||||
| 		return this.pv; | ||||
| 	} | ||||
|  | ||||
| 	public void setPv(int pdv){  //Méthode pour définir les points de vie du monstre | ||||
| 		this.pv=pdv; | ||||
| 	} | ||||
|  | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Or.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SAe2.1/commentente/SAé/Or.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user