Skip to content
Snippets Groups Projects
Commit 2eeb8e24 authored by Jules Delespierre's avatar Jules Delespierre
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 502 additions and 0 deletions
### Java ###
# Compiled class file
*.class
# Javadoc
doc/*
# Ignore les fichiers .csv et .json
*.csv
*.json
# Log file
*.log
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
### VisualStudioCode ###
.vscode/*
*.code-workspace
/bin/
.project
.settings/*
res/LabyrintheTmp.csv
res/settings
\ No newline at end of file
File added
# Chasse au monstre
## Groupe J5
### Membres :
* DELESPIERRE Jules
* LEBON Baptiste
* SAINT-MAXIN Axel
* MOREAU Noa
File added
res/textures/murs/blue_wall.jpeg

217 KiB

res/textures/murs/mossy_blue_wall.jpeg

489 KiB

res/textures/murs/mossy_white_wall.jpeg

226 KiB

res/textures/sols/cloud.png

7.39 KiB

res/textures/sols/herbe.png

684 B

res/textures/sols/monster.png

1.53 KiB

res/textures/sols/porte.png

1.81 KiB

package fr.univlille.iutinfo.J5.ai;
public enum DirectionEnum {
NORD, OUEST, SUD, EST;
}
package fr.univlille.iutinfo.J5.ai;
import fr.univlille.iutinfo.cam.player.hunter.IHunterStrategy;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
/**
* Classe représentant une stratégie pour le chasseur (IA).
*
*/
public class HunterStrategy implements IHunterStrategy{
@Override
public ICoordinate play() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'play'");
}
@Override
public void update(ICellEvent arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
@Override
public void initialize(int arg0, int arg1) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'initialize'");
}
}
package fr.univlille.iutinfo.J5.ai;
import java.util.Random;
import fr.univlille.iutinfo.J5.model.Coordinate;
import fr.univlille.iutinfo.cam.player.hunter.IHunterStrategy;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
/**
* Classe représentant une stratégie pour le chasseur (IA). Basé sur l'aléatoire
*/
public class HunterStrategyRandom implements IHunterStrategy {
private int nbCol;
private int nbRow;
private static final Random RAND = new Random();
@Override
public ICoordinate play() {
return new Coordinate(RAND.nextInt(nbCol), RAND.nextInt(nbRow));
}
@Override
public void update(ICellEvent arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
@Override
public void initialize(int arg0, int arg1) {
this.nbCol = arg0;
this.nbRow = arg1;
}
}
package fr.univlille.iutinfo.J5.ai;
import fr.univlille.iutinfo.J5.model.Coordinate;
import fr.univlille.iutinfo.J5.model.Maze;
import fr.univlille.iutinfo.cam.player.monster.IMonsterStrategy;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
public class MonsterStragyMainDroite implements IMonsterStrategy {
private static DirectionEnum direction = DirectionEnum.EST;
private boolean[][] maze;
private ICoordinate coordinate;
@Override
public ICoordinate play() {
if (direction==DirectionEnum.EST) {
if (this.maze[0].length > coordinate.getCol()+1 && !this.maze[coordinate.getRow()][coordinate.getCol()+1]) {
this.coordinate = new Coordinate(this.coordinate.getRow(),this.coordinate.getCol()+1);
return this.coordinate;
}
tournerADroite();
}
if (direction==DirectionEnum.SUD) {
if (this.maze.length > coordinate.getRow()+1 && !this.maze[coordinate.getRow()+1][coordinate.getCol()]) {
this.coordinate = new Coordinate(this.coordinate.getRow()+1,this.coordinate.getCol());
return this.coordinate;
}
tournerADroite();
}
if (direction==DirectionEnum.OUEST) {
if (0 < coordinate.getCol()-1 && !this.maze[coordinate.getRow()][coordinate.getCol()-1]) {
this.coordinate = new Coordinate(this.coordinate.getRow(),this.coordinate.getCol()-1);
return this.coordinate;
}
tournerADroite();
}
if (direction==DirectionEnum.SUD) {
if (0 < coordinate.getRow()+1 && !this.maze[coordinate.getRow()-1][coordinate.getCol()]) {
this.coordinate = new Coordinate(this.coordinate.getRow()-1,this.coordinate.getCol());
return this.coordinate;
}
}
return null; //n'arrive jamais
}
@Override
public void update(ICellEvent arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
@Override
public void initialize(boolean[][] arg0) {
this.maze = arg0;
}
private static void tournerADroite() {
switch (MonsterStragyMainDroite.direction.name()) {
case "EST":
MonsterStragyMainDroite.direction = DirectionEnum.SUD;
break;
case "SUD":
MonsterStragyMainDroite.direction = DirectionEnum.OUEST;
break;
case "OUEST":
MonsterStragyMainDroite.direction = DirectionEnum.NORD;
break;
case "NORD":
MonsterStragyMainDroite.direction = DirectionEnum.EST;
break;
}
}
public void getEntryMonster(Maze model) {
this.coordinate = model.monsterPath.get(0);
}
}
package fr.univlille.iutinfo.J5.ai;
import fr.univlille.iutinfo.cam.player.monster.IMonsterStrategy;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
/**
* Classe représentant une stratégie pour le monstre (IA).
*
*/
public class MonsterStrategy implements IMonsterStrategy {
@Override
public ICoordinate play() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'play'");
}
@Override
public void update(ICellEvent arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
@Override
public void initialize(boolean[][] arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'initialize'");
}
}
package fr.univlille.iutinfo.J5.ai;
import java.util.LinkedList;
import java.util.Queue;
import fr.univlille.iutinfo.J5.model.Coordinate;
import fr.univlille.iutinfo.J5.model.Maze;
import fr.univlille.iutinfo.cam.player.monster.IMonsterStrategy;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
public class MonsterStrategyParcourLargeur implements IMonsterStrategy {
private boolean[][] maze;
private ICoordinate coordinate;
private Queue<ICoordinate> queueParcours;
private ICoordinate exit;
/*
private Coordinate getVoisin(Coordinate coord){
} */
private void parcours() {
boolean trouver = false;
this.queueParcours.offer(coordinate);
while (!this.queueParcours.isEmpty() && !trouver) {
Coordinate c = (Coordinate) this.queueParcours.peek();
if (c.equals(this.exit)) {
trouver = true;
} else {
Coordinate voisin;
}
}
}
@Override
public ICoordinate play() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'play'");
}
@Override
public void update(ICellEvent arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
@Override
public void initialize(boolean[][] arg0) {
this.maze = arg0;
}
public void getEntryMonster(Maze model) {
this.coordinate = model.monsterPath.get(0);
}
public void getExit(Maze model) {
this.exit = model.exit;
}
}
package fr.univlille.iutinfo.J5.ai;
import java.util.Random;
import fr.univlille.iutinfo.J5.model.Coordinate;
import fr.univlille.iutinfo.J5.model.Maze;
import fr.univlille.iutinfo.cam.player.monster.IMonsterStrategy;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
/**
* Classe représentant une stratégie pour le monstre (IA). Basé sur l'aléatoire
*
*/
public class MonsterStrategyRandom implements IMonsterStrategy {
private boolean[][] maze;
private ICoordinate coordinate;
private static final Random RAND = new Random();
@Override
public ICoordinate play() {
Coordinate nextCord = new Coordinate(coordinate.getCol(), coordinate.getRow());
do {
nextCord.col = this.coordinate.getCol() + MonsterStrategyRandom.RAND.nextInt(-1, 2);
nextCord.row = this.coordinate.getRow() + MonsterStrategyRandom.RAND.nextInt(-1, 2);
} while ((nextCord.col < 0 || nextCord.row < 0) || maze[nextCord.getCol()][nextCord.getRow()]
|| coordinate.equals(nextCord));
this.coordinate = nextCord;
return nextCord;
}
@Override
public void update(ICellEvent arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
@Override
public void initialize(boolean[][] arg0) {
this.maze = arg0;
}
public void getEntryMonster(Maze model) {
this.coordinate = model.monsterPath.get(0);
}
}
package fr.univlille.iutinfo.J5.controller;
import fr.univlille.iutinfo.J5.model.CellEvent;
import fr.univlille.iutinfo.J5.model.Coordinate;
import fr.univlille.iutinfo.J5.model.Maze;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
import fr.univlille.iutinfo.cam.player.perception.ICellEvent.CellInfo;
import java.util.Map;
/**
* ControllerHunter est la classe qui permet de controller ViewHunterMaze
*/
public class ControllerHunter implements IController{
/**
* Permet de savoir quel model update
*/
private Maze model;
public ControllerHunter(Maze model) {
this.model = model;
}
/**
* Permet d'avoir les informations sur la case tiré
*
* @param coord la coordonnée du tir
* @return l'etat de la cellule visé (Monster si le monstre est touché, EMPTY et un tour si le monstre est déja passer par la case 0 sinon, WALL si c'est aucun de ces cas la)
*/
public ICellEvent getState(Coordinate coord) {
if (this.model.monsterPath.get(model.tourCourant).equals(coord)) {
return new CellEvent(CellInfo.MONSTER, coord);
}
if (!this.model.wall[coord.col][coord.row]) {
for (Map.Entry<Integer,ICoordinate> set : this.model.monsterPath.entrySet()) {
if (set.getValue().equals(coord)) {
return new CellEvent(CellInfo.EMPTY, set.getKey(), coord);
}
}
return new CellEvent(CellInfo.EMPTY, 0, coord);
}
return new CellEvent(CellInfo.WALL, coord);
}
/**
* Permet de convertir des coordonnées en Coordinate
*
* @param x la coordonnées x du point voulu
* @param y la coordonnées y du point voulu
* @return L'object Coordinate coorespondant aux coordonnées données en paramètres
*/
@Override
public Coordinate xyToCoordinate(int x, int y) {
return new Coordinate((int)((Math.ceil(x/20.0)*20)-20)/20,(int)((Math.ceil(y/20.0)*20)-20)/20-1);
}
/**
* Permet de passer de coordordonnées à l'état de la case
*
* @param x la coordonnées x du point voulu
* @param y la coordonnées y du point voulu
* @return l'état de la case en fonction de coordonnées
*/
public ICellEvent shoot(int x, int y){
return this.getState(this.xyToCoordinate(x, y));
}
}
package fr.univlille.iutinfo.J5.controller;
import java.util.ArrayList;
import java.util.List;
import fr.univlille.iutinfo.J5.model.Coordinate;
import fr.univlille.iutinfo.J5.model.Maze;
import fr.univlille.iutinfo.cam.player.perception.ICoordinate;
/**
* ControllerMonster est la classe qui permet de controller ViewMonsterMaze
*/
public class ControllerMonster implements IController {
/**
* Permet de savoir quel model update
*/
private Maze model;
public ControllerMonster(Maze model) {
this.model = model;
}
/**
* Permet de connaître les cases voisines du monstre
*
* @return une liste de Coordinate où le monstre peut aller
*/
public List<Coordinate> voisinMonster() {
ArrayList<Coordinate> result = new ArrayList<Coordinate>();
ICoordinate current = model.monsterPath.get(model.monsterPath.size() - 1);
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
Coordinate tmp = new Coordinate(current.getCol() + i, current.getRow() + j);
if (!this.estEnDehors(tmp) && !model.isWall(tmp) && !tmp.equals(current))
result.add(tmp);
}
}
return result;
}
/**
* Vérifie à partir de ICoordinate en paramètre si la coordonnée est en dehors
* du labyrinthe
*
* @param ICoordinate
*
* @return true si la coord est en dehors false sinon
*/
public boolean estEnDehors(ICoordinate ic) {
int longueur = model.wall.length;
int largeur = model.wall[0].length;
boolean result = true;
if ((0 <= ic.getRow() && ic.getRow() < longueur) && (0 <= ic.getCol() && ic.getCol() < largeur)) {
result = false;
}
return result;
}
/**
* Permet de mettre a jour le model
*
* @param coord
* nouvelle coordonnée du monster
*/
public void move(Coordinate coord) {
this.model.monsterPath.put(this.model.monsterPath.size(), coord);
this.model.tourCourant++;
}
/**
* Permet de setTurn sur la coordonnées passé en paramètre
*
* @param coord
*/
public void setTurn(Coordinate coord) {
throw new UnsupportedOperationException("Unimplemented method 'setTurn'");
}
/**
* Permet de convertir des coordonnées en Coordinate
*
* @param x la coordonnées x du point voulu
* @param y la coordonnées y du point voulu
* @return L'object Coordinate coorespondant aux coordonnées données en
* paramètres
*/
@Override
public Coordinate xyToCoordinate(int x, int y) {
System.out.println(new Coordinate((int) ((Math.ceil(x / 20.0) * 20) - 20) / 20,
(int) ((Math.ceil(y / 20.0) * 20) - 20) / 20 - 1));
System.out.println((int) ((Math.ceil(x / 20.0) * 20) - 20) / 20 + "-"
+ (int) ((Math.ceil((y - 16) / 20.0) * 20) - 20) / 20);
return new Coordinate((int) ((Math.ceil(x / 20.0) * 20) - 20) / 20,
(int) ((Math.ceil((y - 16) / 20.0) * 20) - 20) / 20 - 1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment