Package monopoly.model.personality

Examples of monopoly.model.personality.Player


    private Player nextPlayer() {
        if (_playersQueue.isEmpty()) {
            return null;
        }

        Player p = _playersQueue.poll();
        _playersQueue.offer(p);

        return p;
    }
View Full Code Here


            }
        }

        for (int i = 0; i < playerCount; i++) {
            _field.addPlayer(_startCell,
                    new Player("Игрок " + (i + 1),
                    _availableColors.get(i), 150000));
        }
        _playersQueue = new ArrayDeque(_field.players());
       
        GameModelEvent event = new GameModelEvent(this);
View Full Code Here

     * игрового поля, в соответсвии с количеством очков выпавших на костях.
     * После того как игрок дойдет до целевой ячейки, он совершает действие
     * согласно игровой логике этой ячейки.
     */
    public void makeNextMove() {
        Player p = nextPlayer();
        if (p == null) {
            return;
        }

        DiceScore diceScore = p.dropDice(_dice);
        GameModelEvent event = new GameModelEvent(this, p, diceScore);
        firePlayerDroppedDice(event);

        GameFieldCellBase oldPosition = p.position();
        p.shiftOnField(diceScore.score());
        GameFieldCellBase newPosition = p.position();
        event = new GameModelEvent(this, p, oldPosition, newPosition);
        firePlayerShiftedOnField(event);

        event = new GameModelEvent(this, p);
        firePlayerStartedDoAction(event);
View Full Code Here

     * окно представления, отображая возможные действие игрока согласно логике
     * конкретной ячейке игрового поля.
     * @param e аргументы события.
     */
    public void gamePlayerStartedDoAction(GameModelEvent e) {
        final Player p = e.getPlayer();
        GameFieldCellBase cell = p.position();

        if (cell instanceof GiftCell) {
            GiftCell giftCell = (GiftCell) cell;
            int gift = giftCell.currentGift();

            showSimpleDialogMessage("ПОДАРОК", "<html>"
                    + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                    + "\"" + p.name() + "\"</font>" + " остановился на ячейки "
                    + "<font color=green>\"ПОДАРОК\"</font>. "
                    + "Получите от банка <i>" + gift + "$.</i>"
                    + "</html>");

            GameViewEvent event = new GameViewEvent(this, p, gift);
            fireMadePlayerGift(event);
        } else if (cell instanceof PenaltyCell) {
            PenaltyCell penaltyCell = (PenaltyCell) cell;
            int penalty = penaltyCell.currentPenalty();

            showSimpleDialogMessage("ШТРАФ", "<html>"
                    + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                    + "\"" + p.name() + "\"</font>" + " остановился на ячейки "
                    + "<font color=red>\"ШТРАФ\"</font>. "
                    + "Вы будете оштрафованы банком на <i>"
                    + penalty + "$.</i>"
                    + "</html>");

            GameViewEvent event = new GameViewEvent(this, p, penalty);
            fireMadePlayerPenalty(event);
        } else if (cell instanceof CompanyCell) {
            final CompanyCell companyCell = (CompanyCell) cell;

            if (companyCell.owner() == _gameModel.bank()) {
                _canPlayerBuyLand = true;

                final Dialog dialog = new JDialog();
                dialog.setModal(true);
                dialog.setTitle("Фирма \"" + companyCell.name() + "\"");
                dialog.setLayout(new GridBagLayout());
                GridBagConstraints c = new GridBagConstraints();
                c.fill = GridBagConstraints.BOTH;
                c.insets = new Insets(5, 5, 5, 5);

                c.gridx = 0;
                c.gridy = 0;
                dialog.add(new JLabel("<html>"
                        + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                        + "\"" + p.name() + "\"</font>" + "остановился на ячейки"
                        + " являющейся фирмой <u>\"" + companyCell.name() + "\"</u>"
                        + " принадлежащей Банку.<br>"
                        + "Желаете приобрести указанную фирму за ее номинальную"
                        + " цену <i>" + companyCell.cost() + "$?</i>"
                        + "</html>"), c);

                JButton ybttn = new JButton("Да");
                ybttn.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        _canPlayerBuyLand = false;

                        GameViewEvent event = new GameViewEvent(this, p,
                                companyCell, companyCell.cost());
                        fireMadePlayerBuyLand(event);

                        dialog.dispose();
                    }
                });

                c.fill = GridBagConstraints.VERTICAL;
                c.gridy = 1;
                dialog.add(ybttn, c);

                JButton nbttn = new JButton("Нет");
                nbttn.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        dialog.dispose();
                    }
                });

                c.gridy = 2;
                dialog.add(nbttn, c);

                dialog.pack();
                dialog.setLocationRelativeTo(this);
                dialog.setResizable(false);
                dialog.setVisible(true);

                if (_canPlayerBuyLand == false) {
                    showSimpleDialogMessage("Недостаточно денежных средств",
                            "<html>"
                            + "Игроку <font color=" + HTMLColors.getName(p.color())
                            + ">\"" + p.name() + "\"</font> не хватило денежных "
                            + "средств для покупки фирмы <u>\"" + companyCell.name()
                            + "\"</u>.<br>Необходмо: <i>" + companyCell.cost()
                            + "$.</i><br>Имеется: <i>" + p.money() + "$.</i>"
                            + "</html>");
                }
            } else if (companyCell.owner() != p) {
                final Dialog infoDialog = new JDialog();
                infoDialog.setModal(true);
                infoDialog.setTitle("Фирма \"" + companyCell.name() + "\"");
                infoDialog.setLayout(new GridBagLayout());
                GridBagConstraints c = new GridBagConstraints();
                c.fill = GridBagConstraints.BOTH;
                c.insets = new Insets(5, 5, 5, 5);

                c.gridx = 0;
                c.gridy = 0;

                Color color = HTMLColors.black;
                final ILandOwner owner = companyCell.owner();
                if (owner instanceof Player) {
                    color = ((Player) owner).color();
                }

                infoDialog.add(new JLabel("<html>"
                        + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                        + "\"" + p.name() + "\"</font>" + "остановился на ячейки"
                        + " являющейся фирмой <u>\"" + companyCell.name() + "\"</u>"
                        + " и принадлежащей игроку <font color="
                        + HTMLColors.getName(color) + ">\"" + owner.name()
                        + "\"</font>.<br>"
                        + "Оплатите арендную плату в размере <i>"
                        + companyCell.rent() + "$.</i>"
                        + "</html>"), c);

                JButton okbttn = new JButton("OK");
                okbttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
                okbttn.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        _canPlayerPaidRent = false;

                        GameViewEvent event = new GameViewEvent(this, p,
                                companyCell);
                        fireMadePlayerPayRent(event);

                        infoDialog.dispose();
                    }
                });

                c.fill = GridBagConstraints.NONE;
                c.gridy = 1;
                infoDialog.add(okbttn, c);

                infoDialog.pack();
                infoDialog.setLocationRelativeTo(this);
                infoDialog.setResizable(false);
                infoDialog.setVisible(true);

                if (_canPlayerPaidRent == true) {
                    final Dialog dialog = new JDialog();
                    dialog.setModal(true);
                    dialog.setTitle("Игрок \"" + p.name() + "\"");
                    dialog.setLayout(new GridBagLayout());

                    c = new GridBagConstraints();
                    c.fill = GridBagConstraints.BOTH;
                    c.insets = new Insets(5, 5, 5, 5);

                    final JLabel questionLbl = new JLabel();
                    final JLabel amountLbl = new JLabel();
                    final JSpinner amountSpr = new JSpinner();
                    final JButton ybttn = new JButton("Да");
                    ybttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);
                    final JButton nbttn = new JButton("Нет");
                    nbttn.setAlignmentX(JComponent.CENTER_ALIGNMENT);

                    c.gridx = 0;
                    c.gridy = 0;
                    dialog.add(questionLbl, c);

                    c.gridx = 0;
                    c.gridy = 1;
                    dialog.add(amountLbl, c);

                    c.gridx = 0;
                    c.gridy = 2;
                    dialog.add(amountSpr, c);

                    c.gridx = 0;
                    c.gridy = 3;
                    c.fill = GridBagConstraints.NONE;
                    dialog.add(ybttn, c);

                    c.gridx = 0;
                    c.gridy = 4;
                    dialog.add(nbttn, c);

                    questionLbl.setText("<html>"
                            + "Желаете попробывать перекупить у игрока <font color="
                            + HTMLColors.getName(color) + ">\"" + owner.name()
                            + "\"</font> фирму <u>\"" + companyCell.name()
                            + "\"</u>?"
                            + "</html>");

                    amountLbl.setText("Предложить сумму ($):");

                    SpinnerModel sprModel = new SpinnerNumberModel(
                            companyCell.cost(), companyCell.cost(),
                            companyCell.cost() * 10, 1000);
                    amountSpr.setModel(sprModel);

                    ybttn.setActionCommand("P1");
                    ybttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            String actionCommand = e.getActionCommand();
                            if ("P1".equals(actionCommand)) {
                                dialog.setTitle("Игрок \"" + owner.name() + "\"");

                                questionLbl.setText("<html>"
                                        + "Игрок <font color="
                                        + HTMLColors.getName(p.color()) + ">\""
                                        + p.name() + "\"</font> предложил вам "
                                        + "продать свою фирму <u>\""
                                        + companyCell.name() + "\"</u>. Вы согласны?"
                                        + "</html>");
                                amountLbl.setText("Предложенная сумма ($):");

                                amountSpr.setEnabled(false);

                                ybttn.setActionCommand("P2");

                                dialog.pack();
                            } else if ("P2".equals(actionCommand)) {
                                _canPlayerBuyLand = false;
                                GameViewEvent event = new GameViewEvent(this, p,
                                        companyCell, (Integer) amountSpr.getValue());
                                fireMadePlayerBuyLand(event);

                                dialog.dispose();
                            }
                        }
                    });

                    nbttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            _canPlayerBuyLand = true;
                            dialog.dispose();
                        }
                    });

                    dialog.pack();
                    dialog.setLocationRelativeTo(this);
                    dialog.setResizable(false);
                    dialog.setVisible(true);

                    if (_canPlayerBuyLand == false) {
                        showSimpleDialogMessage("Недостаточно денежных средств",
                                "<html>"
                                + "Игроку <font color=" + HTMLColors.getName(p.color())
                                + ">\"" + p.name() + "\"</font> не хватило денежных "
                                + "средств для покупки фирмы <u>\"" + companyCell.name()
                                + "\"</u>.<br>Необходмо: <i>" + companyCell.cost()
                                + "$.</i><br>Имеется: <i>" + p.money() + "$.</i>"
                                + "</html>");
                    }
                }
            }
        }
View Full Code Here

    /**
     * Обработчик события - у игрока была конфискована земельная собственность.
     * @param e аргументы события.
     */
    public void gamePlayerLandsConfiscated(GameModelEvent e) {
        Player p = e.getPlayer();
        List<ILand> confiscated = e.getConfiscated();

        final Dialog infoDialog = new JDialog();
        infoDialog.setModal(true);
        infoDialog.setTitle("Конфискация фирм");
        infoDialog.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(5, 5, 5, 5);

        c.gridx = 0;
        c.gridy = 0;
        infoDialog.add(new JLabel("<html>"
                + "У игрока <font color=" + HTMLColors.getName(p.color()) + ">"
                + "\"" + p.name() + "\"</font>" + ", в связи с отсутсвием "
                + "денежных средств для уплаты, были конфискованы следующие "
                + "фирмы: "
                + "</html>"), c);
        List<String> companyNames = new ArrayList<String>();
        for (ILand company : confiscated) {
View Full Code Here

    /**
     * Обработчик события - игрок закончил игру(банкрот).
     * @param e аргументы события.
     */
    public void gamePlayerFinishedGame(GameModelEvent e) {
        Player p = e.getPlayer();

        showSimpleDialogMessage("Банкрот", "<html>"
                + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                + "\"" + p.name() + "\"</font> не имеет денежных средств "
                + "для уплаты и закончил игру."
                + "</html>");

        PlayerChip chip = getPlayerChip(p);
        _playerChips.remove(chip);
View Full Code Here

    /**
     * Обработчик события - игра закончина и выявлен победитель.
     * @param e аргументы события.
     */
    public void gameFinished(GameModelEvent e) {
        Player p = e.getPlayer();

        showSimpleDialogMessage("Игра окончена", "<html>"
                + "Игрок <font color=" + HTMLColors.getName(p.color()) + ">"
                + "\"" + p.name() + "\"</font> стал монополистом и победил в игре."
                + "</html>");

        final JFrame mainWindow = this;
        final Dialog infoDialog = new JDialog();
        infoDialog.setModal(true);
View Full Code Here

        g.drawRect(x, y, CELL_WIDTH, CELL_HEIGHT - y);

        ILandOwner owner = company.owner();
        if (owner instanceof Player) {
            Player p = (Player) owner;

            Graphics2D g2d = (Graphics2D) g;
            GradientPaint gp = new GradientPaint(x, y, Color.WHITE,
                    x, CELL_HEIGHT, p.color().darker());
            g2d.setPaint(gp);
            g2d.fillRect(1, y + 1, CELL_WIDTH - 2, (CELL_HEIGHT - y) - 2);
        }

        super.paintChildren(g);
View Full Code Here

TOP

Related Classes of monopoly.model.personality.Player

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.