Commit 1013e288 authored by Felix RABADAN's avatar Felix RABADAN
Browse files

fin new week

parent 310f100b
*.class
.vscode/launch.json
game/Game.java
......@@ -2,8 +2,8 @@ package game;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Map;
import game.Card.Rarity;
import game.controllers.CardController;
import game.controllers.UserController;
public class Admin extends Member {
......@@ -30,7 +30,10 @@ public class Admin extends Member {
e.printStackTrace();
}//update the score and players
ArrayList<User> rank = UserController.getInstance().rank();//update the rank of every users
rank.get(0);
//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));;
}
}
......@@ -25,9 +25,6 @@ public class Card {
this.player = player;
}
public String toString() {
return this.player.getName() + " / " + this.rarity + " / " + this.number + " / " + this.player.getPosition();
}
public Object getId() {
return this.id;
......@@ -45,4 +42,10 @@ public class Card {
return this.player;
}
@Override
public String toString() {
return "Card [id=" + id + ", number=" + number + ", player=" + player.getName() + ", rarity=" + rarity + ", score=" + player.getScore() + "]";
}
}
......@@ -16,7 +16,6 @@ public class Club {
if(!players.contains(newPlayer)){
players.add(newPlayer);
}else{
System.err.println("Player deja dans la team");;
}
}
}
......@@ -2,76 +2,53 @@ package game;
import game.controllers.*;
import java.io.FileNotFoundException;
import game.Card.Rarity;
import game.Player.Position;
public class Game {
public static void main(String[] args) {
// DEBUT TEST
System.out.println("NEW GAME !!!!!!!");
UserController userController = UserController.getInstance();
CardController cardController = CardController.getInstance();
User felix = userController.addUser("felix");
User malo = userController.addUser("malo");
userController.addUser("felix");
userController.connect(felix);
userController.connect(malo);
CardController cardController = CardController.getInstance();
Player p = new Player("Paul Pogba", Position.COURT_FIELD_PLAYER, (float) 5.0); // pq mettre le score dans le
// constructeur ?
Card card1 = cardController.createCard(1, Card.Rarity.COMMON, p);
cardController.createCard(1, Card.Rarity.COMMON, p);
cardController.removeCard(card1);
cardController.createCard(1, Card.Rarity.RARE, p);
cardController.createCard(2, Card.Rarity.RARE, p);
cardController.createCard(3, Card.Rarity.RARE, p);
cardController.createCard(4, Card.Rarity.RARE, p);
cardController.createCard(5, Card.Rarity.RARE, p);
cardController.createCard(6, Card.Rarity.RARE, p);
cardController.createCard(7, Card.Rarity.RARE, p);
cardController.createCard(8, Card.Rarity.RARE, p);
cardController.createCard(9, Card.Rarity.RARE, p);
cardController.createCard(10, Card.Rarity.RARE, p);
cardController.createCard(11, Card.Rarity.RARE, p);
System.out.println("####");
// p.displayCards();
Market market = Market.getInstance();
// Admin admin = Admin.getInstance();
// admin.putOnMarket(new Pair<Card, Integer>(card1, 1000));
market.displayBuyableCards();
Card card2 = cardController.createCard(1, Card.Rarity.RARE,
new Player("Kylian Mbappe", Position.COURT_FIELD_PLAYER, (float) 5.0));
felix.addCard(card2);
// market.displayBuyableCards();
market.displayExchangeableCards();
// felix.sell();
// felix.buy();
felix.exchange();
felix.displayDeck();
// market.displayBuyableCards();
market.displayExchangeableCards();
userController.disconnect();
userController.connect(malo);
malo.addCard(card1);
malo.exchange();
malo.displayDeck();
userController.disconnect();
userController.connect(felix);
felix.displayDeck();
market.displayExchangeableCards();
// test parser
// try {
// Parser.parseTeam("CSV\\2021_46_Nantes.csv");
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
User prof = userController.addUser("prof");
Admin admin = Admin.getInstance();
// add all the players
try {
Parser.parse("CSV\\2021_42\\2021_42_Nantes.csv");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
Parser.parse("CSV\\2021_46\\2021_46_Nantes.csv");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// on rajoute des cartes au pif pour tester et avoir des decks de base
for (int i = 0; i < 6; i++) {
felix.addCard(cardController.createRandomCard());
malo.addCard(cardController.createRandomCard());
prof.addCard(cardController.createRandomCard());
}
// create goal for test
Player axel = new Player("Axel Rocheteau", Position.GOAL_KEEPER, 2);
felix.addCard(cardController.createCard(1, Card.Rarity.RARE, axel));
malo.addCard(cardController.createCard(2, Card.Rarity.RARE, axel));
prof.addCard(cardController.createCard(3, Card.Rarity.RARE, axel));
// connect test
felix.chooseDeck();
malo.chooseDeck();
prof.chooseDeck();
admin.newWeek("CSV\\2021_42\\2021_42_Nantes.csv");// first week
felix.displayDeck();//on voit bien la nouvelle carte rare en plus
}
}
......@@ -49,7 +49,6 @@ public class User extends Member {
public void addCard(Card card) {
if (card != null) {
deck.add(card);
System.out.println("Your card has been added in your deck");
}
}
......@@ -76,9 +75,6 @@ public class User extends Member {
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);
}
......@@ -172,6 +168,7 @@ public class User extends Member {
float sum = 0;
for (Card c : team) {
sum += c.getPlayer().getScore();
//TODO prendre en compte la rarete genre 1.05?
}
teamScore = sum / (float) team.length;
}
......
......@@ -5,6 +5,7 @@ import java.util.Random;
import game.Card;
import game.Player;
import game.Card.Rarity;
public class CardController {
private static CardController instance = null;
......@@ -23,30 +24,30 @@ public class CardController {
switch (rarity) {
case COMMON:
// TODO moyen de faire des sous fonctions pour eviter la repition du code
if (player.getNbCommonCards() < 1000) {
if (player.getNbCommonCards() < 1000 && 0 < number && number < 1000) {
player.getCards().put(new_key, new_card);
System.out.println("The card has been added");
player.setNbCommonCards();
} else {
System.err.println("The player " + player.getName() + " has too many common cards");
return null;
}
break;
case LESS_COMMON:
if (player.getNbLessCommonCards() < 100) {
if (player.getNbLessCommonCards() < 100 && 0 < number && number < 100) {
player.getCards().put(new_key, new_card);
System.out.println("The card has been added");
player.setNbLessCommonCards();
} else {
System.err.println("The player " + player.getName() + " has too many less common cards");
return null;
}
break;
case RARE:
if (player.getNbRareCards() < 10) {
if (player.getNbRareCards() < 10 && 0 < number && number < 10) {
player.getCards().put(new_key, new_card);
System.out.println("The card has been added");
player.setNbRareCards();
} else {
System.err.println("The player " + player.getName() + " has too many rare cards");
return null;
}
break;
default:
......@@ -67,15 +68,15 @@ public class CardController {
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
switch (randomRarity) {// generation avec parametre suivant la rarete
case 0:
card = createCard(new Random().nextInt(10), Card.Rarity.RARE, randomPlayer);
card = createCard(new Random().nextInt(10) + 1, Card.Rarity.RARE, randomPlayer);
break;
case 1:
card = createCard(new Random().nextInt(100), Card.Rarity.LESS_COMMON, randomPlayer);
card = createCard(new Random().nextInt(100) + 1, Card.Rarity.LESS_COMMON, randomPlayer);
break;
case 2:
card = createCard(new Random().nextInt(1000), Card.Rarity.COMMON, randomPlayer);
card = createCard(new Random().nextInt(1000) + 1, Card.Rarity.COMMON, randomPlayer);
break;
}
}
......@@ -90,4 +91,17 @@ public class CardController {
System.err.println("This card doesn't exist");
}
}
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;
}
}
......@@ -25,7 +25,6 @@ public final class ClubController {
clubs.put(name, newClub);
return newClub;
} else {
System.err.println("Le club existe deja");
return clubs.get(name);
}
}
......
......@@ -25,7 +25,6 @@ public final class PlayerController {
players.put(name, newPlayer);
return newPlayer;
} else {
System.err.println("Le player existe deja");
Player player = players.get(name);
player.score = score;//update score
return player;
......
......@@ -64,7 +64,7 @@ public final class UserController {
for (User user : userRank){
user.updateTeamScore();
}
Collections.sort(userRank,(a,b) -> Math.round( a.getTeamScore() - (b.getTeamScore())));
Collections.sort(userRank,(a,b) -> Math.round( b.getTeamScore() - (a.getTeamScore())));
System.out.println("### Classement ###");
int i = 1;
......
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