New branch
This commit is contained in:
10
.classpath
Normal file
10
.classpath
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>eXplorer</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
14
.settings/org.eclipse.jdt.core.prefs
Normal file
14
.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=17
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=17
|
||||||
BIN
bin/eXplorer/LevelGenerator.class
Normal file
BIN
bin/eXplorer/LevelGenerator.class
Normal file
Binary file not shown.
BIN
bin/eXplorer/Main.class
Normal file
BIN
bin/eXplorer/Main.class
Normal file
Binary file not shown.
BIN
bin/eXplorer/Player.class
Normal file
BIN
bin/eXplorer/Player.class
Normal file
Binary file not shown.
119
src/eXplorer/LevelGenerator.java
Normal file
119
src/eXplorer/LevelGenerator.java
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
package eXplorer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.lang.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class LevelGenerator {
|
||||||
|
|
||||||
|
private int hauteur;
|
||||||
|
private int longueur;
|
||||||
|
private String[][] carte;
|
||||||
|
|
||||||
|
//constructeur
|
||||||
|
public LevelGenerator(int pHauteur, int pLongueur) {
|
||||||
|
this.hauteur = pHauteur;
|
||||||
|
this.longueur = pLongueur;
|
||||||
|
this.carte = generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String[][] generate() {
|
||||||
|
String[][] carte = new String[this.hauteur][this.longueur];
|
||||||
|
int[] wall = new int[3];
|
||||||
|
int[] wallPorte = new int[3];
|
||||||
|
int sortie = 5;
|
||||||
|
int minGap = 3; // Minimum gap between walls
|
||||||
|
int margin = 3; // Margin from the edges
|
||||||
|
|
||||||
|
//génération des positions des portes
|
||||||
|
for (int i = 0; i < wallPorte.length; i++) {
|
||||||
|
int max = this.hauteur - 2; // Ajusté pour éviter les bords
|
||||||
|
int min = 1; // Évite les bords
|
||||||
|
int range = max - min + 1;
|
||||||
|
int dernierMur = (int) (Math.random() * range) + min;
|
||||||
|
if(dernierMur != this.longueur-2) {
|
||||||
|
wallPorte[i] = dernierMur;
|
||||||
|
}
|
||||||
|
|
||||||
|
//il sera généré 3 fois mais pas grave
|
||||||
|
sortie = (int) (Math.random() * range) + min;
|
||||||
|
System.out.println("WallPorte " + i + ": " + wallPorte[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generation des murs interieur
|
||||||
|
*/
|
||||||
|
// Ensure there is enough space to place the walls with the given margin and gap
|
||||||
|
if (this.longueur - 2 * margin < (wall.length - 1) * minGap) {
|
||||||
|
throw new IllegalArgumentException("Map too small to place walls with the given margin and gap");
|
||||||
|
}
|
||||||
|
|
||||||
|
int availableSpace = this.longueur - 2 * margin - (minGap * (wall.length - 1));
|
||||||
|
int basePosition = margin;
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < wall.length; i++) {
|
||||||
|
wall[i] = basePosition + (int)(Math.random() * availableSpace / wall.length) + (i * (minGap + 1));
|
||||||
|
basePosition = wall[i] + minGap;
|
||||||
|
System.out.println("Wall " + i + ": " + wall[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < this.hauteur; i++) {
|
||||||
|
|
||||||
|
for (int j = 0; j < this.longueur; j++) {
|
||||||
|
//Affichage des murs de la carte
|
||||||
|
if(i==0 || i== this.hauteur -1 || j == 0 || j == this.longueur-1) {
|
||||||
|
carte[i][j] = "#";
|
||||||
|
//generation de la sortie
|
||||||
|
if(i==sortie && j == this.longueur -1) {
|
||||||
|
carte[i][j] = "s";
|
||||||
|
}
|
||||||
|
} else if(contains(wall, j) ) {
|
||||||
|
carte[i][j] = "#";
|
||||||
|
|
||||||
|
//trouver l'index du mur afin de pouvoir positionner la porte
|
||||||
|
for(int ii=0; ii<wall.length; ii++) {
|
||||||
|
if(wall[ii] == j) {
|
||||||
|
System.out.println("ii : "+ii + " i : " + i + " WallPorte : " + wallPorte[ii]);
|
||||||
|
if(wallPorte[ii] == i) {
|
||||||
|
carte[i][j] = "p";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
carte[i][j] = " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return carte;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afficherCarte() {
|
||||||
|
|
||||||
|
for (int i = 0; i < this.hauteur; i++) {
|
||||||
|
for (int j = 0; j < this.longueur; j++) {
|
||||||
|
System.out.print(this.carte[i][j]);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(final int[] array, final int key) {
|
||||||
|
for (final int i : array) {
|
||||||
|
if (i == key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/eXplorer/Main.java
Normal file
19
src/eXplorer/Main.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package eXplorer;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import eXplorer.LevelGenerator;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
LevelGenerator carte1 = new LevelGenerator(10, 35) ;
|
||||||
|
|
||||||
|
carte1.afficherCarte();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
20
src/eXplorer/Player.java
Normal file
20
src/eXplorer/Player.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package eXplorer;
|
||||||
|
|
||||||
|
public class Player {
|
||||||
|
|
||||||
|
private int endurance = 0;
|
||||||
|
private int posX = 1;
|
||||||
|
private int posY = 1;
|
||||||
|
|
||||||
|
|
||||||
|
public Player(int x, int y) {
|
||||||
|
this.posX = x;
|
||||||
|
this.posY = y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouvement() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user