update Java's tp

master
Antoine PEREDERII 1 year ago
parent e0a82abdb6
commit fa87fa45ae

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<component name="ProjectRootManager" version="2" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -5,5 +5,6 @@
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="application" />
</component>
</module>

@ -3,8 +3,9 @@
<component name="ChangeListManager">
<list default="true" id="c44c2f96-8ae0-4f37-a212-587839ee08bf" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiagrammeOieIndice.mdj" beforeDir="false" afterPath="$PROJECT_DIR$/DiagrammeOieIndice.mdj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiagrammeOieInstance.mdj" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/tpJeuDeL_oie.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/tpJeuDeL_oie.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Oie/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/Oie/.idea/misc.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -17,24 +18,36 @@
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 1
}]]></component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 1
}</component>
<component name="ProjectId" id="2ZZJwcpiDLr2R3nWM1YGBHgEZ1j" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "master",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
&quot;project.structure.proportion&quot;: &quot;0.18768328&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;advanced.settings&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager">
<configuration name="Unnamed" type="Application" factoryName="Application" nameIsGenerated="true">
<module name="tpJeuDeL_oie" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
@ -44,10 +57,16 @@
<option name="presentableId" value="Default" />
<updated>1702623908454</updated>
<workItem from="1704990430275" duration="15000" />
<workItem from="1705063011152" duration="166000" />
<workItem from="1705063185374" duration="7000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnknownFeatures">
<option featureType="dependencySupport" implementationName="executable:docker" />
<option featureType="dependencySupport" implementationName="executable:kubectl" />
</component>
</project>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -6,10 +6,9 @@ import models.Plateau;
public class Stub {
public Jeu loadPions() {
Jeu game = new Jeu(10, 6);
Jeu game = new Jeu(15, 6);
game.getMyAdminPlayer().ajouterJoueur(new Joueur("rouge"));
game.getMyAdminPlayer().ajouterJoueur(new Joueur("bleu"));
game.getPlateau().placerJoueursSurCaseInitiale(game.getMyAdminPlayer().getLesJoueurs());
return game;
}
}

@ -10,13 +10,13 @@ public class ConsoleGame {
final Jeu game = new Stub().loadPions();
System.out.println(game.getPlateau().toString());
Joueur currentPlayer = game.getMyAdminPlayer().getCurrentJoueur();
System.out.println(currentPlayer.toString());
System.out.println("Changement de Joueur");
// System.out.println(currentPlayer.toString());
// System.out.println("Changement de Joueur");
// currentPlayer = game.getMyAdminPlayer().nextPlayer();
// System.out.println(currentPlayer.toString());
// System.out.println("Changement de Joueur");
currentPlayer = game.getMyAdminPlayer().nextPlayer();
System.out.println(currentPlayer.toString());
System.out.println("Changement de Joueur");
currentPlayer = game.getMyAdminPlayer().nextPlayer();
System.out.println(currentPlayer.toString());
// System.out.println(currentPlayer.toString());
game.lancerDes();
System.out.println(game.getPlateau().toString());
game.lancerDes();

@ -5,40 +5,63 @@ import models.Joueur;
import models.Plateau;
public class DeplaceurJoueur {
private boolean verifPresenceJoueur(Joueur currentJoueur, int valeurDe, Plateau plateau) {
int nextIndex = (currentJoueur.getMyCase().getIdCase() + valeurDe) % plateau.getCaseList().size();
Case caseSuivante = plateau.getCaseList().get(nextIndex);
return caseSuivante.getCurrentJoueur() != null;
}
private void alternerJoueurs(Joueur joueur1, Joueur joueur2) {
// Échanger les positions des joueurs
Case caseJoueur1 = joueur1.getMyCase();
Case caseJoueur2 = joueur2.getMyCase();
// private boolean verifPresenceJoueur(Joueur currentJoueur, int valeurDe, Plateau plateau) {
// int nextIndex = (currentJoueur.getMyCase().getIdCase() + valeurDe) % plateau.getCaseList().size();
// Case caseSuivante = plateau.getCaseList().get(nextIndex);
// return caseSuivante.getCurrentJoueur() != null;
// }
caseJoueur1.setCurrentJoueur(joueur2);
caseJoueur2.setCurrentJoueur(joueur1);
// private void alternerJoueurs(Joueur joueur1, Joueur joueur2) {
// // Échanger les positions des joueurs
// Case caseJoueur1 = joueur1.getMyCase();
// Case caseJoueur2 = joueur2.getMyCase();
//
// caseJoueur1.setCurrentJoueur(joueur2);
// caseJoueur2.setCurrentJoueur(joueur1);
//
// joueur1.setMyCase(caseJoueur2);
// joueur2.setMyCase(caseJoueur1);
//
// System.out.println("Échange de positions entre le joueur " + joueur1.getIdJoueur() + " et le joueur " + joueur2.getIdJoueur());
// }
public void alternerPosition(Joueur joueurActuel, Joueur joueurSuivant) {
Case caseActuelle = joueurActuel.getMyCase();
Case caseSuivante = joueurSuivant.getMyCase();
joueur1.setMyCase(caseJoueur2);
joueur2.setMyCase(caseJoueur1);
joueurActuel.setMyCase(caseSuivante);
joueurSuivant.setMyCase(caseActuelle);
System.out.println("Échange de positions entre le joueur " + joueur1.getIdJoueur() + " et le joueur " + joueur2.getIdJoueur());
caseActuelle.setCurrentJoueur(joueurSuivant);
caseSuivante.setCurrentJoueur(joueurActuel);
}
public void deplacerJoueur(Joueur currentJoueur, int nbCases, Plateau plateau) {
if (verifPresenceJoueur(currentJoueur, nbCases, plateau)) {
// La case suivante est occupée ou en dehors du plateau, alterner les joueurs ou prendre une action appropriée
alternerJoueurs(currentJoueur, currentJoueur);
} else {
int positionActuelle = currentJoueur.getMyCase().getIdCase();
int nouvellePosition = (positionActuelle + nbCases) % plateau.getCaseList().size();
Case caseSuivante = plateau.getCaseList().get(nouvellePosition);
// public void deplacerJoueur(Joueur currentJoueur, int nbCases, Plateau plateau) {
// if (verifPresenceJoueur(currentJoueur, nbCases, plateau)) {
// // La case suivante est occupée ou en dehors du plateau, alterner les joueurs ou prendre une action appropriée
// alternerJoueurs(currentJoueur, currentJoueur);
// } else {
// int positionActuelle = currentJoueur.getMyCase().getIdCase();
// int nouvellePosition = (positionActuelle + nbCases) % plateau.getCaseList().size();
//
// Case caseSuivante = plateau.getCaseList().get(nouvellePosition);
// currentJoueur.getMyCase().setCurrentJoueur(null);
//
// caseSuivante.setCurrentJoueur(currentJoueur);
// currentJoueur.setMyCase(caseSuivante);
//
// System.out.println("Le joueur " + currentJoueur.getIdJoueur() + " se déplace sur la case " + caseSuivante.getIdCase());
// }
// }
public void deplacerJoueur(Case newCase, Joueur currentJoueur){
if(newCase == null)
return;
if (currentJoueur.getMyCase() != null){
currentJoueur.getMyCase().setCurrentJoueur(null);
caseSuivante.setCurrentJoueur(currentJoueur);
currentJoueur.setMyCase(caseSuivante);
System.out.println("Le joueur " + currentJoueur.getIdJoueur() + " se déplace sur la case " + caseSuivante.getIdCase());
}
if (newCase.getCurrentJoueur() != null){
alternerPosition(currentJoueur, newCase.getCurrentJoueur());
}
currentJoueur.setMyCase(newCase);
currentJoueur.getMyCase().setCurrentJoueur(currentJoueur);
}
}

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.List;
public class GestionnaireJoueur {
private static int index = 0;
private ObservableList<Joueur> myList = FXCollections.observableArrayList();
private ListProperty<Joueur> lesJoueurs = new SimpleListProperty(myList);
public ObservableList<Joueur> getLesJoueurs() {
@ -18,16 +19,16 @@ public class GestionnaireJoueur {
public ListProperty<Joueur> lesJoueursProperty() {
return lesJoueurs;
}
private ObjectProperty<Joueur> currentJoueur = new SimpleObjectProperty();
private Joueur currentJoueur;
public Joueur getCurrentJoueur() {
return currentJoueur.get();
}
public ObjectProperty<Joueur> currentJoueurProperty() {
return currentJoueur;
}
public void setCurrentJoueur(Joueur joueur) {
currentJoueur.set(joueur);
}
// public ObjectProperty<Joueur> currentJoueurProperty() {
// return currentJoueur;
// }
// public void setCurrentJoueur(Joueur joueur) {
// currentJoueur.set(joueur);
// }
// private List<Joueur> lesJoueurs = new ArrayList<>();
// private StringProperty name = new SimpleStringProperty();
// public String getName() { return name.get(); }
@ -41,15 +42,18 @@ public class GestionnaireJoueur {
// return currentJoueur;
// }
public Joueur getJoueurSuivant() {
return this.myList.get((currentJoueur.get().getIdJoueur() + 1) % lesJoueurs.size());
return this.myList.get((currentJoueur.getIdJoueur() + 1) % lesJoueurs.size());
}
public void ajouterJoueur(Joueur joueur) {
myList.add(joueur);
if(myList.size() == 1) {
currentJoueur.set(myList.get(0));
currentJoueur = myList.get(0);
}
}
public Joueur nextPlayer() {
return myList.get((currentJoueur.get().getIdJoueur() + 1) % lesJoueurs.size());
index = (index +1) % this.myList.size();
currentJoueur = myList.get(index);
return currentJoueur;
// return myList.get((currentJoueur.getIdJoueur()) % lesJoueurs.size());
}
}

@ -5,34 +5,20 @@ import java.util.List;
public class Case {
private int idCase;
private List<Joueur> myJoueur = new ArrayList<>();
private Joueur myJoueur = null;
public Case(int idCase) {
this.myJoueur = null;
this.idCase = idCase;
}
public Joueur getCurrentJoueur() {
if (this.myJoueur.size() != 0) {
return this.myJoueur.get(0);
}
return null;
return this.myJoueur;
}
public void setCurrentJoueur(Joueur joueur) {
if(joueur != null) {
this.myJoueur.add(0, joueur);
} else {
this.myJoueur.remove(this.myJoueur.get(0));
}
this.myJoueur = joueur;
}
public int getIdCase() {
return this.idCase;
}
public void addFirstJoueur(Joueur joueur) {
if(this.getIdCase() == 0) {
this.myJoueur.add(joueur);
} else {
throw new RuntimeException();
}
}
@Override
public String toString() {
if (this.myJoueur != null) {

@ -25,7 +25,10 @@ public class Jeu {
public void lancerDes() {
Joueur joueurCourant = this.myAdminPlayer.getCurrentJoueur();
int resDe = this.myDe.lancer();
this.myMovePlayer.deplacerJoueur(joueurCourant, resDe, this.myPlateau);
if (resDe == 0){
return;
}
this.myMovePlayer.deplacerJoueur(myPlateau.rechercheCase(joueurCourant.getMyCase(), resDe), joueurCourant);
this.myAdminPlayer.nextPlayer();
}
}

@ -30,7 +30,7 @@ public class Joueur {
@Override
public String toString() {
return "Je suis le Joueur " + idJoueur + " de couleur " + this.color + " et je suis sur la case " + this.myCase.getIdCase();
return "Joueur " + idJoueur + ", couleur " + this.color;
}
}

@ -6,21 +6,25 @@ import java.util.List;
public class Plateau {
private List<Case> CaseList = new ArrayList<>();
public Plateau(int nbCase) {
for(int i = 0; i <= nbCase; ++i) {
for(int i = 1; i <= nbCase; ++i) {
CaseList.add(new Case(i));
}
}
public List<Case> getCaseList() {
return this.CaseList;
}
public void placerJoueursSurCaseInitiale(List<Joueur> joueurs) {
for (Joueur joueur : joueurs) {
Case caseInitiale = getCaseList().get(0);
joueur.setMyCase(caseInitiale);
if (caseInitiale != null) {
caseInitiale.addFirstJoueur(joueur);
public Case rechercheCase(Case caseDepart, int nombreDeplacement){
if (caseDepart == null){
return CaseList.get(nombreDeplacement-1);
}
int val = caseDepart.getIdCase() + nombreDeplacement;
for (int i = 0; i < getCaseList().size();i++){
if(getCaseList().get(i).getIdCase() == val){
return getCaseList().get(i);
}
}
return null;
}
@Override

@ -50,4 +50,96 @@ public class Fenetre {
joueursContainer.itemsProperty().bind(game.getMyAdminPlayer().lesJoueursProperty());
// joueursContainer.selectionModelProperty().bind(game.getMyAdminPlayer().currentJoueurProperty());
}
public void initialize() {
de.setDisable(true);
jeu = new Jeu();
gestionnaireJoueur = new GestionnaireJoueur();
creationPlateau();
gestionnaireJoueur.getJoueurList().addListener(new ListChangeListener<Joueur>() {
@Override
public void onChanged(Change<? extends Joueur> c) {
while (c.next()) {
if (c.wasAdded()) {
for (Joueur joueur : c.getAddedSubList()) {
addGridPlayer();
}
}
if (c.wasUpdated()) {
for (Joueur joueur : c.getAddedSubList()) {
changeGridPlayer(joueur);
}
}
}
}
});
}
public void creationPlateau() {
int nombreColonnes = 16;
for (int i = 0; i < jeu.getPlateau().getSizeplateau(); i++) {
Text text = new Text(String.valueOf(i + 1));
text.setStyle("-fx-font-size: 35;");
int row = i / nombreColonnes;
int col = i % nombreColonnes;
gridPanel.add(text, col, row);
gridPanel.setMargin(text, new Insets(30, 25, 50, 0));
gridPanel.setAlignment(Pos.CENTER);
}
}
public void addPlayer(){
gestionnaireJoueur.ajouterJoueur();
}
public void addGridPlayer(){
int rowIndex = gestionnaireJoueur.getJoueurList().size();
Joueur joueur = gestionnaireJoueur.getJoueurList().get(rowIndex - 1);
Label idJoueurLabel = new Label("Joueur numéro " + joueur.getId());
gridPlayer.add(idJoueurLabel, 0, rowIndex);
Label caseJoueurLabel = new Label();
caseJoueurLabel.setText("Case numéro: N/A");
gridPlayer.add(caseJoueurLabel, 1, rowIndex);
}
public void changeGridPlayer(Joueur joueur){
Label caseJoueurLabel = (Label) gridPlayer.getChildren().get(joueur.getId());
if (joueur.getCurrentCase() != null) {
caseJoueurLabel.textProperty().bind(Bindings.concat("Case numéro " + joueur.getCurrentCase().getNum()));
} else {
caseJoueurLabel.textProperty().bind(Bindings.concat("Case numéro: N/A"));
}
}
public void start() {
addPlay.setDisable(true);
de.setDisable(false);
btStart.setDisable(true);
gestionnaireJoueur.InitaliseJoueur();
currentJoueur = gestionnaireJoueur.getCurrentJoueur();
}
public void lanceDe() {
idPlayer.textProperty().bind(currentJoueur.idProperty().asString());
deSimple.lancer();
idValeur.textProperty().bind(deSimple.valProperty().asString());
if (deSimple.getVal() == 0){
return;
}
System.out.println("Current Joueur = " + currentJoueur);
jeu.CaseDeplacer(currentJoueur,deSimple.getVal() );
currentJoueur = gestionnaireJoueur.switchCurrentPlayer();
System.out.println();
}
}
Loading…
Cancel
Save