Commit d517f0a0 authored by Malo KERVESTIN's avatar Malo KERVESTIN
Browse files

mise en place du marché

parent fee124d6
......@@ -2,9 +2,6 @@ package game;
import game.controllers.*;
import java.io.FileNotFoundException;
import game.Parser;
import game.Player.Position;
public class Game {
......@@ -37,15 +34,11 @@ public class Game {
cardController.createCard(10, Card.Rarity.RARE, p);
cardController.createCard(11, Card.Rarity.RARE, p);
System.out.println("####");
p.displayCards();
//test parser
Parser fnnantesPlayers = new Parser();
try {
fnnantesPlayers.parseTeam("CSV\\2021_46_Nantes.csv");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// p.displayCards();
Market market = Market.getInstance();
cardController.putOnMarket(new Pair<Card, Integer>(card1, 1000));
market.displayBuyableCards();
}
}
package game;
import java.util.ArrayList;
public class Market {
private static Market instance = null;
private ArrayList<Pair<Card, Integer>> buyableCards;
private Market() {
this.buyableCards = new ArrayList<Pair<Card, Integer>>();
}
public static Market getInstance() {
if (instance == null) {
instance = new Market();
}
return instance;
}
public void displayBuyableCards() {
for (Pair<Card, Integer> pair : buyableCards) {
System.out.println(pair.toString());
}
}
public ArrayList<Pair<Card, Integer>> getBuyableCards() {
return this.buyableCards;
}
}
package game;
public class Pair<T1, T2> {
T1 fst;
T2 snd;
public Pair(T1 fst, T2 snd) {
this.fst = fst;
this.snd = snd;
}
T1 getFst() {
return fst;
}
T2 getSnd() {
return snd;
}
public String toString() {
return "(" + getFst() + ", " + getSnd() + ")";
}
}
......@@ -4,17 +4,24 @@ import java.util.ArrayList;
public class User {
private String name;
private float balance;
private int balance;
private ArrayList<Card> deck;
private Card[] team;
public User(String name) {
this.name = name;
this.balance = 10000f;
this.balance = 10000;
this.deck = new ArrayList<Card>();
this.team = new Card[4];
}
public void displayDeck() {
System.out.println("My deck :");
for (Card card : deck) {
System.out.println("- " + card.toString());
}
}
public String getName() {
return this.name;
}
......@@ -23,10 +30,7 @@ public class User {
System.out.println("Your balance is " + balance + " coins");
}
public void displayDeck() {
System.out.println("My deck :");
for (Card card : deck) {
System.out.println("- " + card.toString());
}
public ArrayList<Card> getDeck() {
return this.deck;
}
}
\ No newline at end of file
package game.controllers;
import game.Card;
import game.Market;
import game.Player;
import game.Pair;
public class CardController {
private static CardController instance = null;
......@@ -62,6 +64,9 @@ public class CardController {
} else {
System.err.println("This card doesn't exist");
}
}
public void putOnMarket(Pair<Card, Integer> pair) {
Market.getInstance().getBuyableCards().add(pair);
}
}
package game.controllers;
import java.util.HashMap;
import java.util.Scanner;
import game.Card;
import game.Pair;
import game.User;
public final class UserController {
......@@ -46,4 +49,17 @@ public final class UserController {
System.out.println("Connexion error : another user is already connected");
}
}
private Scanner scanner = new Scanner(System.in);
public void sell() {
System.out.println("Which card would you like to sell ?");
connectedUser.displayDeck();
int choice = scanner.nextInt();
Card chosenCard = connectedUser.getDeck().get(choice);
System.out.println("At which price ?");
int price = scanner.nextInt();
CardController.getInstance().putOnMarket(new Pair<Card, Integer>(chosenCard, price));
connectedUser.getDeck().remove(chosenCard);
}
}
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