Esempio n. 1
0
 /**
  * Update changing components.
  *
  * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
  */
 @Override
 public void paintComponent(Graphics g) {
   money.setText(String.valueOf(player.getMoney()));
   record.setText(String.valueOf(bestScore));
   dealerPanel.removeAll();
   playerPanel.removeAll();
   for (Card dealerCard : dealer.getCards()) dealerPanel.add(dealerCard);
   for (Card playerCard : player.getCards()) playerPanel.add(playerCard);
   revalidate();
 }
Esempio n. 2
0
  public TestPanel(Player p) {
    super();
    player = p;
    layeredPane.setPreferredSize(new Dimension(300, 300));

    money = new JLabel("Money: $" + player.getMoney());
    product = new JLabel("Product: " + player.getProduct());
    risk = new JLabel("Risk: " + getRisk() + "%");

    JButton buy = new JButton("Buy RV");
    buy.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            buy();
          }
        });

    JButton sell = new JButton("Sell RV");
    sell.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sell();
          }
        });

    JButton collect = new JButton("Collect");
    collect.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            collect();
          }
        });

    JButton cook = new JButton("cook");
    cook.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cook();
          }
        });

    layeredPane.add(money, new Integer(0));
    money.setBounds(0, 0, 100, 20);

    layeredPane.add(product, new Integer(0));
    product.setBounds(0, 20, 100, 20);

    layeredPane.add(risk, new Integer(0));
    risk.setBounds(0, 40, 100, 20);

    layeredPane.add(buy, new Integer(0));
    buy.setBounds(100, 0, 101, 30);

    layeredPane.add(sell, new Integer(0));
    sell.setBounds(100, 30, 101, 30);

    layeredPane.add(collect, new Integer(0));
    collect.setBounds(100, 60, 101, 30);

    layeredPane.add(cook, new Integer(0));
    cook.setBounds(100, 90, 101, 30);

    add(layeredPane);
    (new Thread(new StartGame())).start();
  }
Esempio n. 3
0
 public void sell() {
   player.sellManuObject(null);
   money.setText("Money: $" + player.getMoney());
   risk.setText("Risk: " + getRisk() + "%");
 }
Esempio n. 4
0
 public void buy() {
   player.buyManuObject(new RV(player));
   money.setText("Money: $" + player.getMoney());
   risk.setText("Risk: " + getRisk() + "%");
 }
  public Displayer(Player x, int num) {
    super("Player " + num + " Information");
    playernum = num;
    this.x = x;

    setSize(400, 400);
    setResizable(false);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    moneyLabel = new JLabel("Money Owned:" + x.getMoney() + "");
    jcards = new JLabel("Get out of Jail Cards Owned: " + x.getJailCards());

    propertydisplay = new JComboBox(getPropertyName());
    icon = new ImageIcon(Game.wdr + "images/tokens/monopoly_token_" + x.getToken() + ".png");
    mortgage = new JButton("Manage Mortgage");
    mortgage.addActionListener(this);
    mortgage.setActionCommand("mortgage");

    buyHouse = new JButton("Buy a House");
    buyHouse.addActionListener(this);
    buyHouse.setActionCommand("buyHouse");

    sellHouse = new JButton("Sell a House");
    sellHouse.addActionListener(this);
    sellHouse.setActionCommand("sellHouse");

    sellProperty = new JButton("Sell this Property");
    sellProperty.addActionListener(this);
    sellProperty.setActionCommand("sellProperty");

    Image img = icon.getImage();
    Image newimg = img.getScaledInstance(80, 80, java.awt.Image.SCALE_SMOOTH);
    ImageIcon newicon = new ImageIcon(newimg);
    timg = new JLabel(newicon);

    propertydisplay.addItemListener(this);

    p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
    p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
    p2.setAlignmentX(Component.RIGHT_ALIGNMENT);
    p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
    p3.setAlignmentX(Component.LEFT_ALIGNMENT);

    p2.add(timg);
    p3.add(moneyLabel);
    p3.add(jcards);

    p1.add(p2);
    p1.add(p3);

    p4.setLayout(new BoxLayout(p4, BoxLayout.Y_AXIS));
    p4.setAlignmentY(Component.CENTER_ALIGNMENT);

    p4.add(propertydisplay);
    p4.add(pr1);
    p4.add(pr2);
    p4.add(pr3);
    p4.add(pr4);
    p4.add(pr5);

    p5.setLayout(new BoxLayout(p5, BoxLayout.X_AXIS));

    p5.add(mortgage);
    p5.add(buyHouse);
    p5.add(sellHouse);

    p.add(p1);
    p.add(p4);
    p.add(p5);

    add(p);
    setVisible(true);

    timer.setActionCommand("timing");
    timer.setInitialDelay(500);
    timer.start();
  }
  public void actionPerformed(ActionEvent e) {
    String event = e.getActionCommand();
    moneyLabel.setText("Money Owned:" + x.getMoney() + "");
    jcards.setText("Get out of Jail Cards Owned: " + x.getJailCards());
    if (event.equals("mortgage")
        && (Game.SlotsList[x.getProperties().get(propertydisplay.getSelectedIndex())]
            instanceof Property)) {
      Slot pobject = Game.SlotsList[x.getProperties().get(propertydisplay.getSelectedIndex())];
      if (pobject.getMortgage()) {
        if (JOptionPane.showConfirmDialog(
                null,
                "Would you like to unmortgage your property for $" + pobject.getMortgageV() * 1.10,
                "Mortgage Choice",
                JOptionPane.YES_NO_OPTION)
            == JOptionPane.YES_OPTION) {
          pobject.endMortgage();
        } else {

        }
      } else {
        if (JOptionPane.showConfirmDialog(
                null,
                "Would you like to mortgage your property for $" + pobject.getMortgageV(),
                "Mortgage Choice",
                JOptionPane.YES_NO_OPTION)
            == JOptionPane.YES_OPTION) {
          pobject.mortgageProperty();
        } else {

        }
      }
      // WIP Code!
    } else if (event.equals("buyHouse")) {
      HouseMenu one =
          new HouseMenu(
              x,
              "buy"); // pass along the player and what sort of thing the player wants to be doing
      one.setVisible(true);
      do {
        try {
          TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException a) {
          // nothing
        }
      } while (one.done == false);
      one.dispose();
    } else if (event.equals("sellHouse")) {
      HouseMenu one = new HouseMenu(x, "sell");
      one.setVisible(true);
      do {
        try {
          TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException a) {
          // nothing
        }
      } while (one.done == false);
      one.dispose();
    } else {
      Property choice =
          (Property) (Game.SlotsList[x.getProperties().get(propertydisplay.getSelectedIndex())]);
      int res =
          JOptionPane.showConfirmDialog(
              null,
              "Are you sure you want to sell this property, along with any houses and hotels?",
              "Confirm your choice",
              JOptionPane.YES_NO_OPTION);
      if (res == JOptionPane.YES_OPTION) {
        choice.sellProperty();
      } else {
        // nothing
      }
    }
  }