Commit 4b68be73 authored by Felix RABADAN's avatar Felix RABADAN
Browse files

verif user on team valid+cpt semaine

parent 5855ab02
......@@ -8,6 +8,7 @@ import game.controllers.UserController;
public class Admin extends Member {
private static Admin instance = null;
private int weeknb = 0;
private Admin() {
super("admin");
......@@ -31,6 +32,8 @@ public class Admin extends Member {
} catch (FileNotFoundException e) {
e.printStackTrace();
}//update the score and players
weeknb++;
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));;
......
......@@ -18,6 +18,7 @@ public class Game {
User felix = userController.addUser("felix");
User malo = userController.addUser("malo");
User prof = userController.addUser("prof");
User sensei = userController.addUser("sensei");
Admin admin = Admin.getInstance();
// add all the players
......@@ -50,7 +51,5 @@ public class Game {
admin.newWeek("CSV\\2021_42\\2021_42_Nantes.csv");// first week
felix.displayDeck();//on voit bien la nouvelle carte rare en plus
//TODO compteur de semaine
//TODO verif joueur on tous fait leurs equipe
}
}
......@@ -10,7 +10,7 @@ public class User extends Member {
private int balance;
private ArrayList<Card> deck;
private Card[] team;
private Float teamScore;
private Float teamScore =(float) 0;
private Scanner scanner = new Scanner(System.in);
......@@ -106,7 +106,7 @@ public class User extends Member {
}
public void buy() {
//TODO donner largent au vendeur et faire un stockage avec un tuple
// TODO donner largent au vendeur et faire un stockage avec un tuple
System.out.println("Which card would you like to buy ?");
Market.getInstance().displayBuyableCards();
int choice = scanner.nextInt();
......@@ -168,8 +168,10 @@ public class User extends Member {
public void updateTeamScore() {
float sum = 0;
for (Card c : team) {
sum += c.getPlayer().getScore();
//TODO prendre en compte la rarete genre 1.05?
if (c != null) {
sum += c.getPlayer().getScore();
}
// TODO prendre en compte la rarete genre 1.05?
}
teamScore = sum / (float) team.length;
}
......@@ -177,4 +179,8 @@ public class User extends Member {
public float getTeamScore() {
return teamScore;
}
public Card[] getTeam() {
return team;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import game.Card;
import game.Member;
import game.User;
......@@ -61,15 +62,25 @@ public final class UserController {
public ArrayList<User> rank() {
ArrayList<User> userRank = new ArrayList<User>(users.values());
for (User user : userRank){
ArrayList<User> userRankValid = new ArrayList<User>();
for (User user : userRank) {
user.updateTeamScore();
Boolean valid = true;
for (Card card : user.getTeam()) {//on parcours la team du user
if (card == null) {
valid = false;
break;
}
}
if (valid) {userRankValid.add(user);}//si user n'a pas de card null dans team on le rajoute au user valide
}
Collections.sort(userRank,(a,b) -> Math.round( b.getTeamScore() - (a.getTeamScore())));
//tri du rank en fonction du teamscore
Collections.sort(userRank, (a, b) -> Math.round(b.getTeamScore() - (a.getTeamScore())));
System.out.println("### Classement ###");
int i = 1;
for (User user: userRank) {
System.out.println(i + " - " +user.getName() + " : " + user.getTeamScore());
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