Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 35f8e547 rédigé par Marc BARBIER's avatar Marc BARBIER
Parcourir les fichiers

je sais plus

parent 44a6b92a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 240 ajouts et 40 suppressions
......@@ -17,6 +17,7 @@ public class Main extends Application {
sc.addScreen("main", getClass().getResource("/main.fxml"));
sc.addScreen("shop", getClass().getResource("/shop.fxml"));
sc.addScreen("team", getClass().getResource("/team.fxml"));
sc.addScreen("results", getClass().getResource("/results.fxml"));
sc.activate("start");
stage.setTitle("User client");
......
......@@ -6,6 +6,8 @@ import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import umljavaproj.common.IAccount;
import umljavaproj.common.IMarket;
import umljavaproj.common.IMatch;
......@@ -23,7 +25,11 @@ public final class RMIController {
try {
registry = LocateRegistry.getRegistry();
} catch (RemoteException e) {
//TODO: Gérer l'erreur
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Connection perdu");
alert.setContentText("Vous devez redémarer l'application");
alert.showAndWait();
System.exit(1);
}
}
......
......@@ -47,8 +47,6 @@ public class LoginController extends Controller {
ScreenController sc = ScreenController.getInstance();
sc.activate("main");
//TODO: continuer la fonction
} catch (RemoteException | NotBoundException exception) {
exception.printStackTrace();
Alert alert = new Alert(AlertType.ERROR);
......
package umljavaproj.playerclient.javafx;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Optional;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
......@@ -70,11 +74,19 @@ public class MainController extends Controller {
int price = Integer.parseInt(pricestr);
try {
rmiController.getMarket().sellCardRMI(rmiController.getUserRMICode(), cardID, price);
} catch (Exception e1) {
//TODO: exception à gérer (?)
} catch (RemoteException | NotBoundException e1) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Connection perdu");
alert.setContentText("Vous devez redémarer l'application");
alert.showAndWait();
System.exit(1);
}
} else {
//TODO: alerte mauvaise syntaxe (prix incorrect)
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Prix invalide");
alert.setHeaderText("Le prix que vous avez entrer est invalide");
alert.setContentText("vous ne pouvez entrer que des nombre entier");
alert.showAndWait();
}
});
});
......@@ -89,15 +101,22 @@ public class MainController extends Controller {
sellBtn
);
}
} catch (Exception e) {
//TODO: exception à gérer (?)
} catch (RemoteException | AlreadyBoundException | NotBoundException e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Connection perdu");
alert.setContentText("Vous devez redémarer l'application");
alert.showAndWait();
System.exit(1);
}
try {
money.setText("" + rmiController.getUser().getBalance());
} catch (RemoteException e) {
// TODO: ce catch a été géré automatiquement, vérifier qu'il est correct / exception à gérer (?)
e.printStackTrace();
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Connection perdu");
alert.setContentText("Vous devez redémarer l'application");
alert.showAndWait();
System.exit(1);
}
}
......
package umljavaproj.playerclient.javafx;
import java.net.URL;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import umljavaproj.common.IMatch;
import umljavaproj.common.PlayerResult;
import umljavaproj.commonjfx.Controller;
import umljavaproj.playerclient.RMIController;
public class ResultController extends Controller{
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private TreeView<String> view;
@FXML
void initialize() {
assert view != null : "fx:id=\"view\" was not injected: check your FXML file 'results.fxml'.";
}
@Override
public void onActivation() {
RMIController controller = RMIController.getInstance();
try {
IMatch match = controller.getMatch();
PlayerResult[] results = match.getResults();
Arrays.sort(results);
TreeItem<String> rootItem = new TreeItem<> ("Resultats");
TreeItem<String> subitem = null;
String team = "";
rootItem.setExpanded(true);
for(PlayerResult playerResult : results) {
if(subitem == null || !team.equals(playerResult.getTeam())) {
team = playerResult.getTeam();
subitem = new TreeItem<>(team, new ImageView(new Image(getClass().getResourceAsStream("team.png"))));
rootItem.getChildren().add(subitem);
}
TreeItem<String> item = new TreeItem<> (playerResult.getPlayerName()+": "+playerResult.getScore());
subitem.getChildren().add(item);
}
view.setRoot(rootItem);
} catch (RemoteException | NotBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package umljavaproj.playerclient.javafx;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import umljavaproj.common.IMarket;
import umljavaproj.common.MarketResume;
import umljavaproj.common.exception.CardNotFoundException;
import umljavaproj.common.exception.NotEnoughBalanceException;
import umljavaproj.commonjfx.Controller;
import umljavaproj.commonjfx.ScreenController;
import umljavaproj.playerclient.RMIController;
......@@ -60,8 +65,17 @@ public class ShopController extends Controller {
try {
localMarket = rmiController.getMarket();
localMarket.buyCardRMI(rmiController.getUserRMICode(), resume.getName(), resume.getRarity());
} catch (Exception e1) {
// TODO: Gérer l'exception
} catch (RemoteException | NotBoundException e1) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Connection perdu");
alert.setContentText("Vous devez redémarer l'application");
alert.showAndWait();
System.exit(1);
} catch (CardNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NotEnoughBalanceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
......@@ -79,8 +93,12 @@ public class ShopController extends Controller {
buyButton
);
}
} catch (Exception e) {
//TODO: Gérer les exceptions
} catch (RemoteException | NotBoundException e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Connection perdu");
alert.setContentText("Vous devez redémarer l'application");
alert.showAndWait();
System.exit(1);
}
try {
......
......@@ -61,6 +61,9 @@ public class TeamController extends Controller {
@FXML
private Button applyBtn;
@FXML
private Button results;
protected Pair<RadioButton, Integer> goalSelect;
protected Pair<RadioButton, Integer> fieldASelect;
protected Pair<RadioButton, Integer> fieldBSelect;
......@@ -79,13 +82,17 @@ public class TeamController extends Controller {
assert playerCTab != null : "fx:id=\"playerCTab\" was not injected: check your FXML file 'team.fxml'.";
assert shopBtn != null : "fx:id=\"shopBtn\" was not injected: check your FXML file 'team.fxml'.";
mainbtn.setOnAction((ActionEvent e) -> {
mainbtn.setOnAction(e -> {
ScreenController.getInstance().activate("main");
});
shopBtn.setOnAction((ActionEvent e) -> {
shopBtn.setOnAction(e -> {
ScreenController.getInstance().activate("shop");
});
results.setOnAction(e -> {
ScreenController.getInstance().popup("results");
});
}
@Override
......@@ -126,17 +133,12 @@ public class TeamController extends Controller {
if(fieldCSelect == null)playerCTab.setStyle(cssStyle);
}
});
}
private void setMatch(List<SimplePair<String, String>> matches) {
if(!matches.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("Next week matches :");
sb.append("Matches suivant: ");
Iterator<SimplePair<String, String>> iterator = matches.iterator();
while(iterator.hasNext()) {
SimplePair<String, String> match = iterator.next();
......@@ -144,10 +146,12 @@ public class TeamController extends Controller {
sb.append(" VS ");
sb.append(match.getValue());
if(iterator.hasNext()) {
sb.append(',');
sb.append(", ") ;
}
}
matchField.setText(sb.toString());
} else {
matchField.setText("Pas de match avenir");
}
}
......
client/src/main/resources/img/team.png

3,94 ko

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.Pane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="umljavaproj.playerclient.javafx.ResultController">
<children>
<TreeView fx:id="view" prefHeight="400.0" prefWidth="200.0" />
</children>
</Pane>
......@@ -50,8 +50,19 @@
<children>
<HBox prefHeight="28.0" prefWidth="640.0">
<children>
<Button fx:id="mainbtn" mnemonicParsing="false" text="Main" />
<Button fx:id="shopBtn" mnemonicParsing="false" prefWidth="54.0" text="Shop" />
<Button fx:id="mainbtn" mnemonicParsing="false" text="Main">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin></Button>
<Button fx:id="shopBtn" mnemonicParsing="false" prefWidth="54.0" text="Shop">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin></Button>
<Button fx:id="results" mnemonicParsing="false" text="Resultat des semaines passé">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<Separator prefWidth="200.0" />
......
......@@ -22,4 +22,5 @@ public interface IAdmin extends Remote {
public String[] getAvaliableCommonPlayerName() throws RemoteException;
public String[] getAvaliableUncommonPlayerName() throws RemoteException;
public void setNextWeekMatches(List<SimplePair<String, String>> matches) throws RemoteException;
public String[] getPlayerList() throws RemoteException;
}
\ No newline at end of file
package umljavaproj.common;
import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
......@@ -8,7 +7,7 @@ import umljavaproj.common.exception.CardNotFoundException;
import umljavaproj.common.exception.NotEnoughBalanceException;
public interface IMarket extends Remote {
public int buyCardRMI(int buyer, String name, Rarity rarity) throws CardNotFoundException, NotEnoughBalanceException, RemoteException, AlreadyBoundException;
public int buyCardRMI(int buyer, String name, Rarity rarity) throws CardNotFoundException, NotEnoughBalanceException, RemoteException;
public void sellCardRMI(int seller, int card, int price) throws RemoteException;
public MarketResume[] getMarketResume() throws RemoteException;
}
......@@ -5,6 +5,6 @@ import java.rmi.RemoteException;
import java.util.List;
public interface IMatch extends Remote {
public PlayerResults[] getResults() throws RemoteException;
public PlayerResult[] getResults() throws RemoteException;
public List<SimplePair<String, String>> getNextWeekMatches() throws RemoteException;
}
......@@ -3,5 +3,5 @@ package umljavaproj.common;
import java.rmi.RemoteException;
public interface ITeam extends Cloneable {
public int computeScore(PlayerResults[] overallResults) throws RemoteException;
public int computeScore(PlayerResult[] overallResults) throws RemoteException;
}
......@@ -2,12 +2,12 @@ package umljavaproj.common;
import java.io.Serializable;
public class PlayerResults implements Serializable {
public class PlayerResult implements Serializable, Comparable<PlayerResult> {
protected String team;
protected String player;
protected float score;
public PlayerResults(String player, String team, float score) {
public PlayerResult(String player, String team, float score) {
this.player = player;
this.team = team;
this.score = score;
......@@ -24,4 +24,24 @@ public class PlayerResults implements Serializable {
public String getPlayerName() {
return player;
}
@Override
public int compareTo(PlayerResult o) {
int comp = o.getTeam().compareTo(this.getTeam());
if(comp == 0) {
comp = o.getPlayerName().compareTo(this.getPlayerName());
}
return comp;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof PlayerResult) {
PlayerResult playerResult = ((PlayerResult)obj);
return playerResult.player.equals(player) &&
playerResult.score == score &&
playerResult.team.equals(team);
}
return false;
}
}
Aucun aperçu pour ce type de fichier
......@@ -67,4 +67,16 @@ public final class ScreenController {
return controller;
}
public Stage popup(String name) {
Stage stage = new Stage();
Pair<Pane, Controller> pair = this.sceneMap.get(name);
if(pair == null) {
throw new RuntimeException("the scene " + name + " doesn't exist");
}
stage.setScene(new Scene(pair.getKey()));
stage.show();
pair.getValue().onActivation();
return stage;
}
}
......@@ -12,7 +12,7 @@ import umljavaproj.common.Classification;
import umljavaproj.common.IAdmin;
import umljavaproj.common.IMatch;
import umljavaproj.common.IPlayer;
import umljavaproj.common.PlayerResults;
import umljavaproj.common.PlayerResult;
import umljavaproj.common.Rarity;
import umljavaproj.common.SimplePair;
import umljavaproj.common.exception.CardNotFoundException;
......@@ -52,14 +52,14 @@ public class Admin implements IAdmin {
}
public void importResults(String csv) throws UnknownPlayerException {
List<PlayerResults> playerResults = new ArrayList<>();
List<PlayerResult> playerResults = new ArrayList<>();
String[] resultLine = csv.split("\n");
for (String playerResult: resultLine) {
String[] data = playerResult.split(",");
playerResults.add(new PlayerResults(data[0], data[1], Float.parseFloat(data[2])));
playerResults.add(new PlayerResult(data[0], data[1], Float.parseFloat(data[2])));
}
this.match.setResults(playerResults.toArray(new PlayerResults[0]));
this.match.setResults(playerResults.toArray(new PlayerResult[0]));
}
private User[] putUsersInOrder(User[] users, User newUser) throws RemoteException {
......@@ -213,4 +213,10 @@ public class Admin implements IAdmin {
match.setNextWeekMatches(matches);
}
@Override
public String[] getPlayerList() throws RemoteException {
CardFactory cardFactory = CardFactory.getInstance();
return cardFactory.getPlayers().toArray(new String[0]);
}
}
\ No newline at end of file
package umljavaproj.server;
import umljavaproj.common.ITeam;
import umljavaproj.common.PlayerResults;
import umljavaproj.common.PlayerResult;
public class EmptyTeam implements ITeam {
public int computeScore(PlayerResults[] overallResults) {
public int computeScore(PlayerResult[] overallResults) {
return 0;
}
}
\ No newline at end of file
......@@ -5,21 +5,21 @@ import java.util.Collections;
import java.util.List;
import umljavaproj.common.IMatch;
import umljavaproj.common.PlayerResults;
import umljavaproj.common.PlayerResult;
import umljavaproj.common.SimplePair;
public class Match implements IMatch {
protected PlayerResults[] results;
protected PlayerResult[] results;
protected List<SimplePair<String, String>> nextWeekMatches;
public Match() {
this.results = new PlayerResults[0];
this.results = new PlayerResult[0];
this.nextWeekMatches = new ArrayList<>();
}
@Override
public PlayerResults[] getResults() {
public PlayerResult[] getResults() {
return results;
}
......@@ -32,7 +32,7 @@ public class Match implements IMatch {
return Collections.unmodifiableList(nextWeekMatches);
}
public void setResults(PlayerResults[] results) {
public void setResults(PlayerResult[] results) {
this.results = results;
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter