* окно представления, отображая возможные действие игрока согласно логике
* конкретной ячейке игрового поля.
* @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>");
}
}
}
}