示例#1
0
 /* mouse events */
 public void mousePressed(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   /* left click */
   if (e.getButton() == MouseEvent.BUTTON1) {
     if (x >= posX && x < posX + Constant.BATTLEFIELD_WIDTH) {
       if (y >= posY) {
         if (y < posY + Constant.BATTLEFIELD_HEIGHT) {
           battle_field.doPress((x - posX), (y - posY));
           return;
         } else if (y < posY + Constant.BATTLEFIELD_HEIGHT + Constant.CARDPANEL_HEIGHT) {
           card_panel.doDrag(x - posX, y - (posY + Constant.BATTLEFIELD_HEIGHT));
           return;
         }
       }
     }
     /* right click */
   } else if (e.getButton() == MouseEvent.BUTTON3) {
     if (x >= posX && x < posX + Constant.BATTLEFIELD_WIDTH) {
       if (y >= posY) {
         if (y < posY + Constant.BATTLEFIELD_HEIGHT) {
           Skill skill = arena.player.useSkill(skill_id, x - posX, y - posY);
           if (skill != null) {
             arena.addSkill(skill);
           }
           return;
         } else if (y < posY + Constant.BATTLEFIELD_HEIGHT + Constant.CARDPANEL_HEIGHT) {
           card_panel.changeDetail(x - posX, y - (posY + Constant.BATTLEFIELD_HEIGHT));
           return;
         }
       }
     }
   }
 }
示例#2
0
  public ArenaFrame(String title, Arena arena, String background, String battleBG, String cardBG) {
    setTitle(title);
    this.arena = arena;
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    width = (int) screenSize.getWidth();
    height = (int) screenSize.getHeight();
    posX = (width - Constant.BATTLEFIELD_WIDTH) / 2;
    posY = (height - Constant.BATTLEFIELD_HEIGHT - Constant.CARDPANEL_HEIGHT) / 2;
    skill_id = 0;
    addKeyListener(this);
    addMouseListener(this);
    addMouseMotionListener(this);

    setUndecorated(true);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    c = getContentPane();
    c.setPreferredSize(new Dimension(width, height));
    c.setLayout(null);

    battle_field =
        new BattleFieldPanel(Constant.BATTLEFIELD_WIDTH, Constant.BATTLEFIELD_HEIGHT, arena);
    battle_field.setBounds(posX, posY, Constant.BATTLEFIELD_WIDTH, Constant.BATTLEFIELD_HEIGHT);
    battle_field.setOpaque(false);
    c.add(battle_field);

    card_panel = new CardPanel(Constant.CARDPANEL_WIDTH, Constant.CARDPANEL_HEIGHT, arena);
    card_panel.setBounds(
        posX,
        posY + Constant.BATTLEFIELD_HEIGHT,
        Constant.CARDPANEL_WIDTH,
        Constant.CARDPANEL_HEIGHT);
    card_panel.setOpaque(false);
    c.add(card_panel);

    setSize(width, height);

    setBackground(background);
    setBattleFieldBackground(battleBG);
    setCardPanelBackground(cardBG);

    setResizable(false);
    setLocationRelativeTo(null);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
    setFocusable(true);
  }
示例#3
0
 public void mouseDragged(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   if (x >= posX && x < posX + Constant.BATTLEFIELD_WIDTH) {
     if (y >= posY) {
       if (y < posY + Constant.BATTLEFIELD_HEIGHT) {
         return;
       } else if (y < posY + Constant.BATTLEFIELD_HEIGHT + Constant.CARDPANEL_HEIGHT) {
         card_panel.dragging(x - posX, y - (posY + Constant.BATTLEFIELD_HEIGHT));
         return;
       }
     }
   }
 }
示例#4
0
  public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() >= 2) {
      int x = e.getX();
      int y = e.getY();
      if (x >= posX && x < posX + Constant.BATTLEFIELD_WIDTH) {
        if (y >= posY) {
          if (y < posY + Constant.BATTLEFIELD_HEIGHT) {

          } else if (y < posY + Constant.BATTLEFIELD_HEIGHT + Constant.CARDPANEL_HEIGHT) {
            card_panel.doDoubleClick(x - posX, y - (posY + Constant.BATTLEFIELD_HEIGHT));
            return;
          }
        }
      }
    }
  }
  public InputRequest takeInputRequest(InputRequest i) {
    makeAllUnSelectable();
    confirmPanel.setText(i.getOwner().getName() + "! " + i.getMessage());
    confirmPanel.activate();

    if (i instanceof CreatureSelectionRequest) {
      CreatureSelectionRequest request = (CreatureSelectionRequest) i;
      List<CardPanel> creaturePanels = getCreaturePanelsOnFields(request.getPossibleCreatures());
      for (CardPanel panel : creaturePanels) {
        panel.setSelectable(true);
      }
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          List<CreatureCard> creatures = new LinkedList<CreatureCard>();
          for (CardPanel panel : creaturePanels) {
            if (panel.isSelected()) {
              creatures.add((CreatureCard) panel.getCard());
            }
          }
          try {
            request.setCreatures(creatures);
          } catch (InvalidSelectionException e) {
            confirmPanel.setText("Invalid Selection: " + request.getMessage());
            confirmPanel.activate();
          }
        }
      }
    } else if (i instanceof PlayerSelectionRequest) {
      PlayerSelectionRequest request = (PlayerSelectionRequest) i;
      List<PlayerSelectionPanel> playerPanels =
          getPlayerSelectionPanels(request.getPossiblePlayers());
      for (PlayerSelectionPanel panel : playerPanels) {
        panel.setSelectable(true);
      }
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          List<Player> players = new LinkedList<Player>();
          for (PlayerSelectionPanel panel : playerPanels) {
            if (panel.isSelected()) {
              players.add((Player) panel.getReference());
            }
          }
          try {
            request.setSelectedPlayers(players);
          } catch (InvalidSelectionException e) {
            confirmPanel.setText("Invalid Selection: " + request.getMessage());
            confirmPanel.activate();
          }
        }
      }

    } else if (i instanceof CardSelectionRequest) {
      CardSelectionRequest request = (CardSelectionRequest) i;
      /*for(Card card : request.getPossibleCards())
      {
      	//System.out.println(card.getName());
      }*/
      List<CardPanel> cardPanels = getCardPanelsInHands(request.getPossibleCards());
      for (CardPanel panel : cardPanels) {
        // System.out.println("Selectable!");
        panel.setSelectable(true);
      }
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          // System.out.println(confirmPanel.isConfirmed());
          List<Card> cards = new LinkedList<Card>();
          for (CardPanel panel : cardPanels) {
            if (panel.isSelected()) {
              // System.out.println("Hellooooo");
              // System.out.println(panel.getCard().getName());
              cards.add((Card) panel.getCard());
            }
          }
          try {
            // System.out.println("Selected Cards");
            // System.out.println(cards);
            // System.out.println("Possible Cards");
            // System.out.println(request.getPossibleCards());
            request.setSelectedCards(cards);
          } catch (InvalidSelectionException e) {
            confirmPanel.setText("Invalid Selection: " + request.getMessage());
            confirmPanel.activate();
          }
        }
      }
    } else if (i instanceof BooleanInputRequest) {
      confirmPanel.getBoolPanel().activate();
      BooleanInputRequest request = (BooleanInputRequest) i;
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          request.setAnswer(confirmPanel.getBoolPanel().getAnswer());
        }
      }
      confirmPanel.getBoolPanel().deactivate();
    } else if (i instanceof EndGameInputRequest) {
      refreshPlayers();
      System.out.println("The game has ended");
    }

    makeAllUnSelectable();

    return i;
  }
示例#6
0
 public void redraw() {
   card_panel.redraw();
   repaint();
 }
示例#7
0
 public void removePortalCard(int id) {
   card_panel.removePortalCard(id);
 }
示例#8
0
 public boolean addToHand(ConcreteCard card) {
   return card_panel.addToHand(card);
 }