Commit fd598c06 authored by Felix RABADAN's avatar Felix RABADAN
Browse files

clean code + fix uml

parent da360d90
This diff is collapsed.
{
"java.format.settings.url": ".vscode/java-formatter.xml"
}
\ No newline at end of file
......@@ -25,8 +25,8 @@ public class Admin extends Member {
public void putOnMarket() { // the administrator can only creat new random cards with random prices
Card newCard = CardController.getInstance().createRandomCard();
Market.getInstance().getBuyableCards().add(new Triple<Card, Integer, User>(newCard,
new Random().nextInt(1000) + 1, null));
Market.getInstance().getBuyableCards()
.add(new Triple<Card, Integer, User>(newCard, new Random().nextInt(1000) + 1, null));
}
public void newFile(String teamName, int weekNb) throws FileNotFoundException {
......@@ -41,12 +41,16 @@ public class Admin extends Member {
System.out.printf("The %d week is starting...\n\n", weeknb);
ArrayList<User> rank = UserController.getInstance().rank();// update the rank of every users
// best user get their cards
rank.get(0).addCard(CardController.getInstance().createRandomCard(Rarity.RARE));
;
rank.get(1).addCard(CardController.getInstance().createRandomCard(Rarity.LESS_COMMON));
;
rank.get(2).addCard(CardController.getInstance().createRandomCard(Rarity.COMMON));
;
if (rank.size() < 2) {
rank.get(0).addCard(CardController.getInstance().createRandomCard(Rarity.RARE));
} else if (rank.size() < 3) {
rank.get(0).addCard(CardController.getInstance().createRandomCard(Rarity.RARE));
rank.get(1).addCard(CardController.getInstance().createRandomCard(Rarity.LESS_COMMON));
} else {
rank.get(0).addCard(CardController.getInstance().createRandomCard(Rarity.RARE));
rank.get(1).addCard(CardController.getInstance().createRandomCard(Rarity.LESS_COMMON));
rank.get(2).addCard(CardController.getInstance().createRandomCard(Rarity.COMMON));
}
}
}
......@@ -2,9 +2,7 @@ package game;
public class Card {
public enum Rarity {
COMMON(1f),
LESS_COMMON(1.05f),
RARE(1.1f);
COMMON(1f), LESS_COMMON(1.05f), RARE(1.1f);
public final float factor;
......@@ -44,8 +42,7 @@ public class Card {
@Override
public String toString() {
return "Card [id=" + id + ", number=" + number + ", player=" + player.getName() + ", position = "
+ player.getPosition() + ", rarity=" + rarity
+ ", score=" + player.getScore() + "]";
+ player.getPosition() + ", rarity=" + rarity + ", score=" + player.getScore() + "]";
}
}
......@@ -12,10 +12,10 @@ public class Club {
players = new ArrayList<Player>();
}
public void addPlayer(Player newPlayer){
if(!players.contains(newPlayer)){
public void addPlayer(Player newPlayer) {
if (!players.contains(newPlayer)) {
players.add(newPlayer);
}else{
} else {
}
}
}
......@@ -16,41 +16,54 @@ public class Game {
if (i == 1) {
normalGame();
} else {
testGame();
debugGame();
}
}
private static void normalGame() {
Boolean end = false;
// init les joueurs
try {
Parser.parse("CSV\\2021_42\\2021_46_France.csv");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
Parser.parse("CSV\\2021_42\\2021_42_Nantes.csv");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (!end) {
UserController userController = UserController.getInstance();
System.out.println("1 - create new user\n2 - connect to user\n3 - connect to admin\n4 - remove user\n5 - game over");
System.out.println(
"1 - create new user\n2 - connect to user\n3 - connect to admin\n4 - remove user\n5 - game over");
int i = sc.nextInt();
switch (i) {
case 1:
System.out.println("Name of the new user :");
String name = sc.next();
userController.connect(userController.addUser(name));
connected();
break;
case 2:
System.out.println("Name of the user");
String username = sc.next();
userController.connect(username);
connected();
break;
case 3:
admin();
break;
case 4:
System.out.println("Name of the user you want to remove :");
String userToRemove = sc.next();
userController.removeUser(userToRemove);
break;
case 5:
end = true;
default:
break;
case 1:
System.out.println("Name of the new user :");
String name = sc.next();
userController.connect(userController.addUser(name));
connected();
break;
case 2:
System.out.println("Name of the user");
String username = sc.next();
userController.connect(username);
connected();
break;
case 3:
admin();
break;
case 4:
System.out.println("Name of the user you want to remove :");
String userToRemove = sc.next();
userController.removeUser(userToRemove);
break;
case 5:
end = true;
default:
break;
}
}
}
......@@ -63,24 +76,24 @@ public class Game {
"1 - displayDeck\n2 - display balance\n3 - compose team\n4 - go to market\n5 - disconnect");
int i = sc.nextInt();
switch (i) {
case 1:
u.displayDeck();
break;
case 2:
u.displayBalance();
break;
case 3:
u.chooseTeam();
break;
case 4:
market();
break;
case 5:
UserController.getInstance().disconnect();
connected = false;
break;
default:
break;
case 1:
u.displayDeck();
break;
case 2:
u.displayBalance();
break;
case 3:
u.chooseTeam();
break;
case 4:
market();
break;
case 5:
UserController.getInstance().disconnect();
connected = false;
break;
default:
break;
}
}
}
......@@ -92,20 +105,20 @@ public class Game {
System.out.println("1 - buy\n2 - sell\n3 - exchange\n4 - leave market");
int i = sc.nextInt();
switch (i) {
case 1:
u.buy();
break;
case 2:
u.sell();
break;
case 3:
u.exchange();
break;
case 4:
onMarket = false;
break;
default:
break;
case 1:
u.buy();
break;
case 2:
u.sell();
break;
case 3:
u.exchange();
break;
case 4:
onMarket = false;
break;
default:
break;
}
}
}
......@@ -117,41 +130,41 @@ public class Game {
System.out.println("1 - new file\n2 - new card(s)\n3 - new week\n4 - disconnect");
int i = sc.nextInt();
switch (i) {
case 1:
while (true) {
try {
System.out.println("Week number ?");
int weekNb = sc.nextInt();
System.out.println("Team name ?");
String teamName = sc.next();
admin.newFile(teamName, weekNb);
break;
} catch (FileNotFoundException e) {
System.out.println("Invalid, try again.");
}
}
break;
case 2:
System.out.println("How many new cards do you want to put on market ?");
int nbCards = sc.nextInt();
for (int j = 0; j < nbCards; j++) {
admin.putOnMarket();
case 1:
while (true) {
try {
System.out.println("Week number ?");
int weekNb = sc.nextInt();
System.out.println("Team name ?");
String teamName = sc.next();
admin.newFile(teamName, weekNb);
break;
} catch (FileNotFoundException e) {
System.out.println("Invalid, try again.");
}
break;
case 3:
admin.newWeek();
break;
case 4:
connected = false;
sc.nextLine();
break;
default:
break;
}
break;
case 2:
System.out.println("How many new cards do you want to put on market ?");
int nbCards = sc.nextInt();
for (int j = 0; j < nbCards; j++) {
admin.putOnMarket();
}
break;
case 3:
admin.newWeek();
break;
case 4:
connected = false;
sc.nextLine();
break;
default:
break;
}
}
}
private static void testGame() {
private static void debugGame() {
// DEBUT TEST
System.out.println("NEW GAME !!!!!!!");
......
......@@ -5,8 +5,7 @@ import java.util.Map;
public class Player {
public enum Position {
GOAL_KEEPER,
COURT_FIELD_PLAYER,
GOAL_KEEPER, COURT_FIELD_PLAYER,
}
private String name;
......
......@@ -9,7 +9,7 @@ public class User extends Member {
private int balance;
private ArrayList<Card> deck;
private Card[] team;
private Float teamScore =(float) 0;
private Float teamScore = (float) 0;
public User(String name) {
super(name);
......@@ -135,8 +135,10 @@ public class User extends Member {
if (confirm.equals("yes")) {
if (balance >= price) {
balance -= chosenCard.getSnd();
chosenCard.getTrd().setBalance(price);
chosenCard.getTrd().addCard(chosenCard.getFst());
if (chosenCard.getTrd() != null) {
chosenCard.getTrd().setBalance(price);
}
addCard(chosenCard.getFst());
System.out.println("This card is yours now ! You still have " + balance + " coins");
Market.getInstance().getBuyableCards().remove(chosenCard);
} else {
......@@ -166,8 +168,8 @@ public class User extends Member {
.entrySet()) {
// si 2 utilisateurs veulent chacun ce que l'autre offre alors on réalise
// l'échange sans demander leurs avis
if (set.getKey().snd.getPlayer().getName().equalsIgnoreCase(namePlayer) && set
.getKey().snd.getRarity().equals(rarity)
if (set.getKey().snd.getPlayer().getName().equalsIgnoreCase(namePlayer)
&& set.getKey().snd.getRarity().equals(rarity)
&& set.getValue().fst.equalsIgnoreCase(chosenCard.getPlayer().getName())
&& set.getValue().snd.equals(chosenCard.getRarity())) {
deck.add(set.getKey().snd);
......@@ -190,7 +192,7 @@ public class User extends Member {
float sum = 0;
for (Card c : team) {
if (c != null) {
sum += c.getPlayer().getScore() * c.getRarity().factor;
sum += c.getPlayer().getScore() * c.getRarity().factor;
}
}
teamScore = sum / (float) team.length;
......
......@@ -17,20 +17,20 @@ public class CardController {
return instance;
}
public Card controlNbMaxCards(String newKey, int number, Player player, Rarity rarity) {
private Card controlNbMaxCards(String newKey, int number, Player player, Rarity rarity) {
int maxBound = 0;
switch (rarity) {
case COMMON:
maxBound = 1000;
break;
case LESS_COMMON:
maxBound = 100;
break;
case RARE:
maxBound = 10;
break;
default:
break;
case COMMON:
maxBound = 1000;
break;
case LESS_COMMON:
maxBound = 100;
break;
case RARE:
maxBound = 10;
break;
default:
break;
}
if (0 < number && number < maxBound) {
Card newCard = new Card(number, rarity, player);
......@@ -59,6 +59,19 @@ public class CardController {
}
}
public Card createRandomCard() {
int randomRarity = new Random().nextInt(3);
switch (randomRarity) {
case 0:
return createRandomCard(Rarity.RARE);
case 1:
return createRandomCard(Rarity.COMMON);
case 2:
return createRandomCard(Rarity.LESS_COMMON);
}
return null;
}
public Card createRandomCard(Card.Rarity rarity) {
Card card = null;
ArrayList<Player> players = new ArrayList<Player>(PlayerController.getInstance().getPlayers().values());
......@@ -68,15 +81,15 @@ public class CardController {
Player randomPlayer = players.get(randomIndex);
int randomRarity = new Random().nextInt(3);
switch (randomRarity) {// generation avec parametre suivant la rarete
case 0:
card = createCard(new Random().nextInt(10) + 1, Card.Rarity.RARE, randomPlayer);
break;
case 1:
card = createCard(new Random().nextInt(100) + 1, Card.Rarity.LESS_COMMON, randomPlayer);
break;
case 2:
card = createCard(new Random().nextInt(1000) + 1, Card.Rarity.COMMON, randomPlayer);
break;
case 0:
card = createCard(new Random().nextInt(10) + 1, Card.Rarity.RARE, randomPlayer);
break;
case 1:
card = createCard(new Random().nextInt(100) + 1, Card.Rarity.LESS_COMMON, randomPlayer);
break;
case 2:
card = createCard(new Random().nextInt(1000) + 1, Card.Rarity.COMMON, randomPlayer);
break;
}
}
return card;
......@@ -91,16 +104,4 @@ public class CardController {
}
}
public Card createRandomCard() {
int randomRarity = new Random().nextInt(3);
switch (randomRarity) {
case 0:
return createRandomCard(Rarity.RARE);
case 1:
return createRandomCard(Rarity.COMMON);
case 2:
return createRandomCard(Rarity.LESS_COMMON);
}
return null;
}
}
......@@ -21,12 +21,12 @@ public final class PlayerController {
public Player addPlayer(String name, Player.Position position, float score) {
if (!players.containsKey(name)) {
Player newPlayer = new Player(name,position,score);
Player newPlayer = new Player(name, position, score);
players.put(name, newPlayer);
return newPlayer;
} else {
Player player = players.get(name);
player.score = score;//update score
player.score = score;// update score
return player;
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<gaphor xmlns="http://gaphor.sourceforge.net/model" version="3.0" gaphor-version="2.6.5">
<gaphor xmlns="http://gaphor.sourceforge.net/model" version="3.0" gaphor-version="2.7.1">
<StyleSheet id="d07fb07f-5758-11ec-882a-f430b952417b"/>
<Package id="d07fb080-5758-11ec-9e1b-f430b952417b">
<name>
......@@ -36,6 +36,7 @@
<ref refid="a4cc802f-5f4f-11ec-93fb-f430b952417b"/>
<ref refid="47cd7a1f-5f50-11ec-aa62-f430b952417b"/>
<ref refid="3b8d5f08-5f51-11ec-ab19-f430b952417b"/>
<ref refid="6943c2a4-5f56-11ec-a36b-00e04c01000e"/>
</reflist>
</ownedType>
</Package>
......@@ -52,28 +53,29 @@
<ref refid="07d01a49-5759-11ec-a104-f430b952417b"/>
<ref refid="610c5519-5759-11ec-9d4e-f430b952417b"/>
<ref refid="80c0e1f3-575a-11ec-8bd8-f430b952417b"/>
<ref refid="75b03f39-575c-11ec-9214-f430b952417b"/>
<ref refid="8ed8d3e9-5f4b-11ec-b7eb-f430b952417b"/>
<ref refid="cebc2950-5f4b-11ec-8f28-f430b952417b"/>
<ref refid="fe2747d1-5f4b-11ec-9d13-f430b952417b"/>
<ref refid="a414f2db-5f4c-11ec-b4f1-f430b952417b"/>
<ref refid="7485bde9-5f4e-11ec-9556-f430b952417b"/>
<ref refid="aa723347-5f4e-11ec-9d24-f430b952417b"/>
<ref refid="a4cca72f-5f4f-11ec-b03c-f430b952417b"/>
<ref refid="47cdf4ba-5f50-11ec-a24d-f430b952417b"/>
<ref refid="3b8dacce-5f51-11ec-8241-f430b952417b"/>
<ref refid="00816905-575b-11ec-928b-f430b952417b"/>
<ref refid="49c34fa8-575b-11ec-a94c-f430b952417b"/>
<ref refid="b29142f0-575b-11ec-99f5-f430b952417b"/>
<ref refid="75b03f39-575c-11ec-9214-f430b952417b"/>
<ref refid="8b42f4f8-575c-11ec-af90-f430b952417b"/>
<ref refid="e6d1b764-5f48-11ec-8c78-f430b952417b"/>
<ref refid="7634fee4-5f4a-11ec-b14d-f430b952417b"/>
<ref refid="edbcdb4c-5f4a-11ec-a096-f430b952417b"/>
<ref refid="8ed8d3e9-5f4b-11ec-b7eb-f430b952417b"/>
<ref refid="cebc2950-5f4b-11ec-8f28-f430b952417b"/>
<ref refid="fe2747d1-5f4b-11ec-9d13-f430b952417b"/>
<ref refid="07ed9ec7-5f4c-11ec-bbe1-f430b952417b"/>
<ref refid="16a91910-5f4c-11ec-968b-f430b952417b"/>
<ref refid="a414f2db-5f4c-11ec-b4f1-f430b952417b"/>
<ref refid="7485bde9-5f4e-11ec-9556-f430b952417b"/>
<ref refid="866e55a9-5f4e-11ec-8dde-f430b952417b"/>
<ref refid="aa723347-5f4e-11ec-9d24-f430b952417b"/>
<ref refid="6156c1a7-5f4f-11ec-89f3-f430b952417b"/>
<ref refid="a4cca72f-5f4f-11ec-b03c-f430b952417b"/>
<ref refid="fc2bf7af-5f4f-11ec-959e-f430b952417b"/>
<ref refid="47cdf4ba-5f50-11ec-a24d-f430b952417b"/>
<ref refid="3b8dacce-5f51-11ec-8241-f430b952417b"/>
<ref refid="684faabc-5f56-11ec-8154-00e04c01000e"/>
</reflist>
</ownedPresentation>
</Diagram>
......@@ -1369,6 +1371,12 @@
<ref refid="fe2747d1-5f4b-11ec-9d13-f430b952417b"/>
</reflist>
</presentation>
<specialization>
<reflist>
<ref refid="09654421-5f4c-11ec-9537-f430b952417b"/>
<ref refid="fcf06ec7-5f4f-11ec-ad69-f430b952417b"/>
</reflist>
</specialization>
</Class>
<ClassItem id="fe2747d1-5f4b-11ec-9d13-f430b952417b">
<matrix>
......@@ -1627,7 +1635,7 @@
<val>393.0</val>
</width>
<height>
<val>176.0</val>
<val>179.55555555555543</val>
</height>
<diagram>
<ref refid="d07fb081-5758-11ec-831e-f430b952417b"/>
......@@ -2867,4 +2875,86 @@
<ref refid="445f3bc9-5f51-11ec-bb6f-f430b952417b"/>
</ownerFormalParam>
</Parameter>
<AssociationItem id="684faabc-5f56-11ec-8154-00e04c01000e">
<diagram>
<ref refid="d07fb081-5758-11ec-831e-f430b952417b"/>
</diagram>
<head_subject>
<ref refid="6943c2a5-5f56-11ec-8cee-00e04c01000e"/>
</head_subject>
<horizontal>
<val>0</val>
</horizontal>
<note>
<val>manage</val>
</note>
<show_direction>
<val>1</val>
</show_direction>
<subject>
<ref refid="6943c2a4-5f56-11ec-a36b-00e04c01000e"/>
</subject>
<tail_subject>
<ref refid="6943eb2d-5f56-11ec-b912-00e04c01000e"/>
</tail_subject>
<matrix>
<val>(1.0, 0.0, 0.0, 1.0, 1057.0, 53.0)</val>
</matrix>
<points>
<val>[(-58.20624547344285, 43.0), (-167.12345679012344, 122.41131389037989)]</val>
</points>
<head-connection>
<ref refid="a414f2db-5f4c-11ec-b4f1-f430b952417b"/>
</head-connection>
<tail-connection>
<ref refid="07d01a49-5759-11ec-a104-f430b952417b"/>
</tail-connection>
</AssociationItem>
<Association id="6943c2a4-5f56-11ec-a36b-00e04c01000e">
<memberEnd>
<reflist>
<ref refid="6943c2a5-5f56-11ec-8cee-00e04c01000e"/>
<ref refid="6943eb2d-5f56-11ec-b912-00e04c01000e"/>
</reflist>
</memberEnd>
<name>
<val>manage</val>
</name>
<ownedEnd>
<reflist>
<ref refid="6943c2a5-5f56-11ec-8cee-00e04c01000e"/>
<ref refid="6943eb2d-5f56-11ec-b912-00e04c01000e"/>
</reflist>
</ownedEnd>
<package>
<ref refid="d07fb080-5758-11ec-9e1b-f430b952417b"/>
</package>
<presentation>
<reflist>
<ref refid="684faabc-5f56-11ec-8154-00e04c01000e"/>
</reflist>
</presentation>
</Association>
<Property id="6943c2a5-5f56-11ec-8cee-00e04c01000e">
<association>
<ref refid="6943c2a4-5f56-11ec-a36b-00e04c01000e"/>
</association>
<owningAssociation>
<ref refid="6943c2a4-5f56-11ec-a36b-00e04c01000e"/>
</owningAssociation>
<type>
<ref refid="a4148e9a-5f4c-11ec-81a0-f430b952417b"/>
</type>