public DGGameView(List<DGPlayer> players) {
   LinkedList<PlayerPanel> playerPanels = new LinkedList<PlayerPanel>();
   for (DGPlayer player : players) {
     playerPanels.add(new PlayerPanel(player, false));
   }
   this.players = playerPanels;
   setTitle("Its time to duel!");
   setLayout(new BorderLayout());
   confirmPanel = new ConfirmPanel("", this);
   playersView = new JPanel();
   switch (players.size()) {
     case 2:
       playersView.setLayout(new GridLayout(2, 1));
       break;
     case 3:
     case 4:
       playersView.setLayout(new GridLayout(2, 2));
   }
   for (PlayerPanel p : playerPanels) {
     playersView.add(p);
   }
   playersView.setVisible(true);
   playersView.setBackground(Color.BLACK);
   confirmPanel.setVisible(false);
   confirmPanel.setBackground(new Color(0.4f, 0.4f, 0.6f));
   add(playersView, BorderLayout.CENTER);
   add(confirmPanel, BorderLayout.SOUTH);
   pack();
   setVisible(true);
   /*JButton confirmButtonRef = confirmPanel.getConfirmButton();
   getRootPane().setDefaultButton(confirmButtonRef);
         confirmButtonRef.requestFocus();*/
 }
Example #2
0
 /**
  * Static Init
  *
  * @throws Exception
  */
 void jbInit() throws Exception {
   mainPanel.setLayout(mainLayout);
   mainLayout.setHgap(2);
   mainLayout.setVgap(2);
   infoPane.setBorder(BorderFactory.createLoweredBevelBorder());
   infoPane.setPreferredSize(new Dimension(500, 400));
   getContentPane().add(mainPanel);
   mainPanel.add(infoPane, BorderLayout.CENTER);
   mainPanel.add(confirmPanel, BorderLayout.SOUTH);
   infoPane.getViewport().add(info, null);
   confirmPanel.addActionListener(this);
 } //	jbInit
  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;
  }