Commit 310f100b authored by Felix RABADAN's avatar Felix RABADAN
Browse files

debut new week + random card + changement rank

parent 00e0d808
*.class
.vscode/launch.json
game/Game.java
......@@ -11,5 +11,4 @@ FC Nantes Alban Lafont 0 0 0 13/27 (48%) 0 (0) 0 (0) 0 (0) 90' G 6.3
FC Nantes Dennis Appiah 0 0 0 3/6 (50%) 3 (0) 3 (0) 0 (0) 21' D 6.3
FC Nantes Sébastien Corchia 0 1 0 6/6 (100%) 4 (1) 4 (1) 0 (0) 39' D 5.7
FC Nantes Kalifa Coulibaly 0 0 0 0/0 0 (0) 0 (0) 0 (0) 1' F -
FC Nantes Samuel Moutoussamy 0 0 0 1/1 (100%) 0 (0) 0 (0) 0 (0) 1' M -
FC Nantes Samuel Moutoussamy 0 0 0 1/1 (100%) 0 (0) 0 (0) 0 (0) 1' M -
\ No newline at end of file
......@@ -13,4 +13,4 @@ FC Nantes Alban Lafont 0 0 0 13/27 (48%) 0 (0) 0 (0) 0 (0) 90' G 6.3
FC Nantes Dennis Appiah 0 0 0 3/6 (50%) 3 (0) 3 (0) 0 (0) 21' D 6.3
FC Nantes Sébastien Corchia 0 1 0 6/6 (100%) 4 (1) 4 (1) 0 (0) 39' D 5.7
FC Nantes Kalifa Coulibaly 0 0 0 0/0 0 (0) 0 (0) 0 (0) 1' F -
FC Nantes Samuel Moutoussamy 0 0 0 1/1 (100%) 0 (0) 0 (0) 0 (0) 1' M -
FC Nantes Samuel Moutoussamy 0 0 0 1/1 (100%) 0 (0) 0 (0) 0 (0) 1' M -
\ No newline at end of file
......@@ -13,5 +13,4 @@ FC Nantes Wylan Cyprien 0 0 2 10/11 (91%) 3 (2) 3 (2) 0 (0) 13' M 6.4
FC Nantes Jean-Charles Castelletto 0 0 2 14/15 (93%) 5 (2) 5 (2) 0 (0) 90' D 6.3
FC Nantes Osman Bukari 0 0 1 13/13 (100%) 7 (2) 7 (2) 0 (0) 32' M 6.1
FC Nantes Randal Kolo Muani 1 0 3 21/26 (81%) 17 (7) 15 (5) 2 (2) 90' M 6.1
FC Nantes Dennis Appiah 0 0 0 20/21 (95%) 3 (0) 3 (0) 0 (0) 48' D 5.8
FC Nantes Dennis Appiah 0 0 0 20/21 (95%) 3 (0) 3 (0) 0 (0) 48' D 5.8
\ No newline at end of file
package game;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import game.controllers.UserController;
......@@ -21,25 +20,17 @@ public class Admin extends Member {
return instance;
}
public void rank() {
ArrayList<Float> teamScores = new ArrayList<Float>();
for (User user : UserController.getInstance().getUsers().values()) {
teamScores.add(user.getTeamScore());
}
Collections.sort(teamScores);
LinkedHashMap<User, Float> classification = new LinkedHashMap<User, Float>();
for (Float score : teamScores) {
for (User user : UserController.getInstance().getUsers().values()) {
if (user.getTeamScore() == score) {
classification.put(user, score);
}
}
}
System.out.println("### Classement ###");
int i = 1;
for (Map.Entry<User, Float> set : classification.entrySet()) {
System.out.println(i + " - " + set.getKey().getName() + " : " + set.getValue());
i++;
}
public void newWeek(String pathname){
/**
* Launch a next week, and make every actions necessary
*/
try {
Parser.parse(pathname);
} catch (FileNotFoundException e) {
e.printStackTrace();
}//update the score and players
ArrayList<User> rank = UserController.getInstance().rank();//update the rank of every users
rank.get(0);
}
}
......@@ -44,4 +44,5 @@ public class Card {
public Player getPlayer() {
return this.player;
}
}
......@@ -17,21 +17,27 @@ public class Parser {
String line = fileScanner.nextLine();
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter("\t");
Club club = clubController.addClub(lineScanner.next());// premier terme nom du club, on le rajoute si existe pas
Club club = clubController.addClub(lineScanner.next());// premier terme nom du club, on le rajoute si existe
// pas
String name = lineScanner.next();
String position = lineScanner.findInLine("[A-Z]");//on cherche la prochaine lettre, correspond a la position
float score = Float.parseFloat(lineScanner.next());
//TODO cas ou pas de score
String position = lineScanner.findInLine("[A-Z]");// on cherche la prochaine lettre, correspond a la
// position
float score;
try {
score = Float.parseFloat(lineScanner.next());
} catch (Exception e) {
score = 0;// joueur na pas jouer donc score 0
}
Player.Position playposition;
if(position.equals("G")){//G is goalkeeper
playposition= Player.Position.GOAL_KEEPER;
}else{
playposition= Player.Position.COURT_FIELD_PLAYER;
if (position.equals("G")) {// G is goalkeeper
playposition = Player.Position.GOAL_KEEPER;
} else {
playposition = Player.Position.COURT_FIELD_PLAYER;
}
Player player = playerController.addPlayer(name,playposition,score);//if player exist => update score
club.addPlayer(player);//add only if the player is not in the club
Player player = playerController.addPlayer(name, playposition, score);// if player exist => update score
club.addPlayer(player);// add only if the player is not in the club
lineScanner.close();
}
fileScanner.close();
......
......@@ -10,6 +10,7 @@ public class User extends Member {
private int balance;
private ArrayList<Card> deck;
private Card[] team;
private Float teamScore;
private Scanner scanner = new Scanner(System.in);
......@@ -167,11 +168,15 @@ public class User extends Member {
}
}
public float getTeamScore() {
public void updateTeamScore() {
float sum = 0;
for (Card c : team) {
sum += c.getPlayer().getScore();
}
return sum / (float) team.length;
teamScore = sum / (float) team.length;
}
public float getTeamScore() {
return teamScore;
}
}
\ No newline at end of file
package game.controllers;
import java.util.ArrayList;
import java.util.Random;
import game.Card;
import game.Player;
......@@ -19,6 +22,7 @@ public class CardController {
Card new_card = new Card(number, rarity, player);
switch (rarity) {
case COMMON:
// TODO moyen de faire des sous fonctions pour eviter la repition du code
if (player.getNbCommonCards() < 1000) {
player.getCards().put(new_key, new_card);
System.out.println("The card has been added");
......@@ -55,6 +59,29 @@ public class CardController {
}
}
public Card createRandomCard(Card.Rarity rarity) {
Card card = null;
ArrayList<Player> players = new ArrayList<Player>(PlayerController.getInstance().getPlayers().values());
int randomIndex = 0;
while (card == null) {
randomIndex = new Random().nextInt(players.size());
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), Card.Rarity.RARE, randomPlayer);
break;
case 1:
card = createCard(new Random().nextInt(100), Card.Rarity.LESS_COMMON, randomPlayer);
break;
case 2:
card = createCard(new Random().nextInt(1000), Card.Rarity.COMMON, randomPlayer);
break;
}
}
return card;
}
public void removeCard(Card card) {
if (card.getPlayer().getCards().containsKey(card.getId())) {
card.getPlayer().getCards().remove(card.getId()); // bug
......
......@@ -6,7 +6,7 @@ import game.Player;
public final class PlayerController {
private static PlayerController instance = null;
public HashMap<String, Player> players;
private HashMap<String, Player> players;
private PlayerController() {
players = new HashMap<String, Player>();
......@@ -31,4 +31,8 @@ public final class PlayerController {
return player;
}
}
public HashMap<String, Player> getPlayers() {
return players;
}
}
package game.controllers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import game.Member;
......@@ -56,4 +58,20 @@ public final class UserController {
System.out.println(connectedMember.getName() + " is disconnected");
connectedMember = null;
}
public ArrayList<User> rank() {
ArrayList<User> userRank = new ArrayList<User>(users.values());
for (User user : userRank){
user.updateTeamScore();
}
Collections.sort(userRank,(a,b) -> Math.round( a.getTeamScore() - (b.getTeamScore())));
System.out.println("### Classement ###");
int i = 1;
for (User user: userRank) {
System.out.println(i + " - " +user.getName() + " : " + user.getTeamScore());
i++;
}
return userRank;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment