Commit 53222fe1 authored by Malo KERVESTIN's avatar Malo KERVESTIN
Browse files

Merge branch 'main' of gitlab.univ-nantes.fr:E188013M/2021-kervestin-rabadan-java into main

parents f6c456c4 e12a51e1
......@@ -26,7 +26,7 @@ public class Card {
}
public String toString() {
return this.player.getName() + " / " + this.rarity + " / " + this.number;
return this.player.getName() + " / " + this.rarity + " / " + this.number + " / " + this.player.getPosition();
}
public Object getId() {
......
......@@ -8,7 +8,7 @@ import game.controllers.ClubController;
import game.controllers.PlayerController;
public class Parser {
public static void parseTeam(String pathname) throws FileNotFoundException {
public static void parse(String pathname) throws FileNotFoundException {
Scanner fileScanner = new Scanner(new File(pathname));
ClubController clubController = ClubController.getInstance();
PlayerController playerController = PlayerController.getInstance();
......@@ -22,22 +22,18 @@ public class Parser {
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
Player.Position playposition;
if(position.equals("G")){
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);
club.addPlayer(player);
// while (lineScanner.hasNext()) {
// System.out.print(lineScanner.next() + "|");
// }
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();
}
}
......@@ -11,11 +11,11 @@ public class Player {
private String name;
private Position position;
private float score;
private HashMap<String, Card> cards;
private int nbCommonCards;
private int nbLessCommonCards;
private int nbRareCards;
public float score;
public Player(String name, Position position, float score) {
this.name = name;
......
package game;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import game.Card.Rarity;
import game.Player.Position;
......@@ -52,7 +51,7 @@ public class User extends Member {
}
}
public Card chooseCard() {
private Card chooseCard() {
int choice;
do {
choice = scanner.nextInt();
......@@ -60,25 +59,40 @@ public class User extends Member {
return deck.get(choice);
}
public Card chooseCard(Player.Position position) {
private Card chooseCardToDeck(Player.Position position) {// verifie aussi quil ny ai pas 2x le meme joueur pour la
// creation de deck
int choice;
Player.Position chosePosition;
boolean samePlayer;
do {
choice = scanner.nextInt();
chosePosition = deck.get(choice).getPlayer().getPosition();
} while (choice >= deck.size() || chosePosition != position);
samePlayer = false;
for (Card card : team) {// check si le joueur nest pas deja dans la team
if (card != null && card.getPlayer() == deck.get(choice).getPlayer()) {
samePlayer = true;
break;
}
}
// System.out.println(choice >= deck.size() );
// System.out.println(chosePosition != position );
// System.out.println(samePlayer);
} while (choice >= deck.size() || chosePosition != position || samePlayer);
return deck.get(choice);
}
public void chooseDeck() {
deck.clear();
System.out.println("Which goalkeeper do you want to add to your deck");
displayDeck();
team[0] = chooseCard(Position.GOAL_KEEPER);
for (int i = 1; i < team.length; i++) {
System.out.printf("Choose your nb%d court field player\n", i);
if (deck.size() < 4) {
System.out.println("You don't have enough cards to create a team");
} else {
System.out.println("Which goalkeeper do you want to add to your deck");
displayDeck();
team[i] = chooseCard(Position.COURT_FIELD_PLAYER);
team[0] = chooseCardToDeck(Position.GOAL_KEEPER);
for (int i = 1; i < team.length; i++) {
System.out.printf("Choose your nb%d court field player\n", i);
displayDeck();
team[i] = chooseCardToDeck(Position.COURT_FIELD_PLAYER);
}
}
}
......
......@@ -26,7 +26,9 @@ public final class PlayerController {
return newPlayer;
} else {
System.err.println("Le player existe deja");
return players.get(name);
Player player = players.get(name);
player.score = score;//update score
return player;
}
}
}
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