Beispiel #1
0
 public static void main(String[] args) {
   Knight k = new Knight();
   k.setSize(8, 8);
   k.setForm(FORM);
   k.solve();
   System.out.println("solutionCount=" + k.solutionCount);
 }
  public PromotionDialog(Square location) {
    // Creating promotion dialog
    if (Board.getBoard().isWhiteMove()) {
      setTitle(
          "Promotion for " + Board.getBoard().getWhitePlayer().getName() + " - Choose a figure");
    } else {
      setTitle(
          "Promotion for " + Board.getBoard().getBlackPlayer().getName() + " - Choose a figure");
    }

    this.location = location;
    JPanel pane = (JPanel) getContentPane();
    pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    pane.setLayout(new GridLayout(1, 4, 10, 10));

    JButton rookButton = new JButton();
    rookButton.setIcon(rook.getFigureIcon());
    rookButton.addActionListener(this);
    rookButton.setFocusPainted(false);
    pane.add(rookButton);

    JButton knightButton = new JButton();
    knightButton.setIcon(knight.getFigureIcon());
    knightButton.addActionListener(this);
    knightButton.setFocusPainted(false);
    pane.add(knightButton);

    JButton bishopButton = new JButton();
    bishopButton.setIcon(bishop.getFigureIcon());
    bishopButton.addActionListener(this);
    bishopButton.setFocusPainted(false);
    pane.add(bishopButton);

    JButton queenButton = new JButton();
    queenButton.setIcon(queen.getFigureIcon());
    queenButton.addActionListener(this);
    queenButton.setFocusPainted(false);
    pane.add(queenButton);

    // Has to choose
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    // Set to be always on top
    setAlwaysOnTop(true); // http://goo.gl/h3vnma
    // Makes dialog customizable
    setModal(true);
    // Disable resize
    setResizable(false);
    // Makes the dialog like an application (with swing components, etc.)
    setModalityType(ModalityType.APPLICATION_MODAL);
    // Size of dialog
    setMinimumSize(new Dimension(300, 100));
    // Centering by default
    setLocationRelativeTo(null);
    pack();
    setVisible(true);
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   // If figure icon matches the the button selected's icon - insert figure into board
   Icon icon = ((JButton) e.getSource()).getIcon();
   if (icon.equals(rook.getFigureIcon())) {
     location.setFigure(rook);
   } else if (icon.equals(knight.getFigureIcon())) {
     location.setFigure(knight);
   } else if (icon.equals(bishop.getFigureIcon())) {
     location.setFigure(bishop);
   } else if (icon.equals(queen.getFigureIcon())) {
     location.setFigure(queen);
   }
   // Delete frame when clicked
   dispose();
 }
Beispiel #4
0
 public static void main(String[] args) {
   Board b = new Board();
   Knight k = new Knight(b);
   // Rules r = new Rules(b, k);
   k.start();
 }
 // calls the act of the knight.
 public void act() {
   super.act();
 }
  /** @param args */
  public static void main(String[] args) {

    ApplicationContext ctx = new ClassPathXmlApplicationContext("knight_aop.xml");
    Knight knight = (Knight) ctx.getBean("knight");
    System.out.println(knight.embarkOnQuest());
  }
Beispiel #7
0
 public static void beAttacked(Knight k) {
   k.defence();
 }
Beispiel #8
0
 public static void strikeTheEnemy(Knight k) {
   k.hit();
 }