示例#1
0
  public Carte getCarte(String type) {
    for (String t : monopoly.getCartes().keySet()) {
      listeCartes.get(t).removeAllItems();
      for (Carte c : monopoly.getCartes().get(t)) {
        listeCartes.get(t).addItem(c);
      }
    }

    listeCartes.get(type).setEnabled(true);
    validCard.setEnabled(true);
    cardOver = false;
    while (!cardOver) {
      try {
        this.wait();
      } catch (Exception e) {
      }
    }
    listeCartes.get(type).setEnabled(false);
    Carte res = (Carte) listeCartes.get(type).getSelectedItem();
    monopoly.getCartes().get(type).remove(res);
    return res;
  }
示例#2
0
  public InterfaceDemo(Monopoly m) {
    super("Demo Monopoly");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.monopoly = m;
    listeDes = new JComboBox[2];
    listeCartes = new HashMap<>();
    GUI = initUIcomponent();
    this.getContentPane().add(GUI);
    initListeners();
    this.setSize(new Dimension(1000, 700));
    this.setLocationRelativeTo(null);
    this.setVisible(true);

    for (ProprieteAConstruire p : m.getProprietes()) {
      propList.addItem(p);
    }
  }
示例#3
0
  public int deplacement(Joueur j, int[] lancer) {
    lancer[0] = 1;
    info.setText("> " + j.getNom() + " <");
    joueur = j;
    int dist;

    propList.removeAllItems();
    batList.removeAllItems();
    for (ProprieteAConstruire x : monopoly.getProprietes()) {
      if (x.getProprietaire() == null) {
        propList.addItem(x);
      } else {
        batList.addItem(x);
      }
    }
    addMaison.setEnabled(batList.getItemCount() > 0);
    addHotel.setEnabled(batList.getItemCount() > 0);
    validProp.setEnabled(propList.getItemCount() != 0);
    cashValue.setText(Integer.toString(j.getCash()));
    validCash.setEnabled(true);

    if (moveMode == 0) {
      listeCarreaux.setSelectedItem(j.getCarreau());
      validTele.setEnabled(true);
      teleOver = false;
      while (!teleOver) {
        try {
          this.wait();
        } catch (Exception e) {
        }
      }
      dist = ((Carreau) listeCarreaux.getSelectedItem()).getId() - j.getPosition().getId();
    } else {
      lancer = getDes();
      dist = lancer[0] + lancer[1];
    }
    return dist;
  }
示例#4
0
  private JPanel initUIcomponent() {
    JPanel content = new JPanel();
    content.setLayout(new BorderLayout());
    content.add(new JLabel("Demo Monopoly", SwingConstants.CENTER), BorderLayout.NORTH);

    JPanel controles = new JPanel();
    controles.setLayout(new GridLayout(7, 1));

    JPanel optPanel = new JPanel();
    optPanel.setLayout(new GridLayout(2, 2));
    optPanel.add(new JLabel("Mode Déplacement", SwingConstants.CENTER));
    moveLabel = new JLabel("Selection");
    optPanel.add(moveLabel);
    optPanel.add(new JLabel(""));
    switchMove = new JButton("Changer");
    switchMove.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            moveMode = (moveMode == 0 ? 1 : 0);
            moveLabel.setText(moveMode == 0 ? "Selection" : "Lancer de dés");
          }
        });
    optPanel.add(switchMove);
    controles.add(optPanel);

    JPanel cashPanel = new JPanel();
    cashPanel.setLayout(new GridLayout(2, 2));
    cashPanel.add(new JLabel("Cash", SwingConstants.CENTER));
    cashValue = new JTextField(10);
    cashPanel.add(cashValue);
    cashPanel.add(new JLabel(""));
    validCash = new JButton("Valider");
    validCash.setEnabled(false);
    cashPanel.add(validCash);
    controles.add(cashPanel);

    JPanel propPanel = new JPanel();
    propPanel.setLayout(new GridLayout(2, 2));
    propPanel.add(new JLabel("Proprietés", SwingConstants.CENTER));
    propList = new JComboBox();
    propPanel.add(propList);
    propPanel.add(new JLabel(""));
    validProp = new JButton("Valider");
    validProp.setEnabled(false);
    propPanel.add(validProp);
    controles.add(propPanel);

    JPanel batPanel = new JPanel();
    batPanel.setLayout(new GridLayout(2, 2));
    batPanel.add(new JLabel("Constructions", SwingConstants.CENTER));
    batList = new JComboBox();
    batPanel.add(batList);
    batPanel.add(new JLabel(""));
    JPanel batPanel2 = new JPanel();
    batPanel2.setLayout(new GridLayout(1, 2));
    addMaison = new JButton("Maison");
    addMaison.setEnabled(false);
    batPanel2.add(addMaison);
    addHotel = new JButton("Hotel");
    addHotel.setEnabled(false);
    batPanel2.add(addHotel);
    batPanel.add(batPanel2);
    controles.add(batPanel);

    // Gestion du deplacement
    JPanel telePanel = new JPanel();
    telePanel.setLayout(new GridLayout(2, 2));
    telePanel.add(new JLabel("Téléportation", SwingConstants.CENTER));
    listeCarreaux = new JComboBox();
    for (Integer i : monopoly.getCarreaux().keySet()) {
      listeCarreaux.addItem(monopoly.getCarreaux().get(i));
    }
    telePanel.add(listeCarreaux);
    telePanel.add(new JLabel(""));
    validTele = new JButton("Valider");
    validTele.setEnabled(false);
    telePanel.add(validTele);
    controles.add(telePanel);

    // Gestion des dés.
    JPanel dicePanel = new JPanel();
    dicePanel.setLayout(new GridLayout(2, 2));
    dicePanel.add(new JLabel("Dés", SwingConstants.CENTER));
    JPanel dicePanel2 = new JPanel();
    dicePanel2.setLayout(new GridLayout(2, 1));
    listeDes[0] = new JComboBox();
    for (int i = 1; i <= 6; i++) {
      listeDes[0].addItem(i);
    }
    dicePanel2.add(listeDes[0]);
    listeDes[1] = new JComboBox();
    for (int i = 1; i <= 6; i++) {
      listeDes[1].addItem(i);
    }
    dicePanel2.add(listeDes[1]);
    dicePanel.add(dicePanel2);
    dicePanel.add(new JLabel(""));
    validDice = new JButton("Valider");
    validDice.setEnabled(false);
    dicePanel.add(validDice);
    controles.add(dicePanel);

    // Gestion des cartes
    JPanel cardPanel = new JPanel();
    cardPanel.setLayout(new GridLayout(2, 2));
    cardPanel.add(new JLabel("Cartes", SwingConstants.CENTER));
    JPanel cardPanel2 = new JPanel();
    cardPanel2.setLayout(new GridLayout(2, 1));
    JComboBox cb;
    for (String s : monopoly.getCartes().keySet()) {
      listeCartes.put(s, (cb = new JComboBox()));
      cb.setEnabled(false);
      cardPanel2.add(cb);
    }
    cardPanel.add(cardPanel2);
    cardPanel.add(new JLabel(""));
    validCard = new JButton("Valider");
    validCard.setEnabled(false);
    cardPanel.add(validCard);
    controles.add(cardPanel);

    content.add(controles, BorderLayout.CENTER);

    info = new JLabel("", SwingConstants.CENTER);
    this.add(info, BorderLayout.SOUTH);

    return content;
  }