コード例 #1
0
ファイル: BoardView.java プロジェクト: widerules/omeca-2
 /**
  * Actions launched after giveTo animation
  *
  * @param placePlayer Player position
  * @param vToMove CardView to move
  */
 public void endAnim(int placePlayer, CardView vToMove) {
   if (placePlayer != 0) {
     playerViews.get(placePlayer).getPlayer().addCard(vToMove.getCard());
     playerViews.get(placePlayer).setPlayer(playerViews.get(placePlayer).getPlayer(), false);
   } else {
     GA.user.addCard(vToMove.getCard());
     Gallery gallery =
         (Gallery)
             GameActivity.getActivity().findViewById(R.id.playerview_slider_board_cardgallery);
     SliderbarCardGallery adapter = (SliderbarCardGallery) gallery.getAdapter();
     adapter.notifyDataSetChanged();
     gallery.setSelection(GA.user.getNumberOfCards() - 1);
     HandView handView = (HandView) GameActivity.getActivity().findViewById(R.id.handview);
     handView.updateView(true);
   }
   this.removeView(vToMove);
 }
コード例 #2
0
ファイル: BoardView.java プロジェクト: widerules/omeca-2
    /** Background task */
    @Override
    protected Boolean doInBackground(Void... params) {
      for (int i = numberCard; i > 0; i--) {
        Player p;
        for (int j = distributor + 1; j < Board.NB_PLAYER_MAX; j++) {
          OmecaHandler handl = GameActivity.getActivity().getOmecaHandler();
          Message msgObj = handl.obtainMessage();

          Bundle b = new Bundle();
          p = GA.board.getPlayers().get(j);
          if (p != null) {
            Log.i(WifiDirectProperty.TAG, "pouette" + p.getName() + j);
            b.putInt("playerPlace", j);
            msgObj.what = OmecaHandler.GIVETO;
            msgObj.setData(b);
            GameActivity.getActivity().getOmecaHandler().sendMessage(msgObj);
          }
        }
        Message msgObj1 = GameActivity.getActivity().getOmecaHandler().obtainMessage();
        Bundle b1 = new Bundle();
        b1.putInt("playerPlace", distributor);
        msgObj1.what = OmecaHandler.GIVETO;
        msgObj1.setData(b1);
        GameActivity.getActivity().getOmecaHandler().sendMessage(msgObj1);

        for (int j = 0; j < distributor; j++) {
          Message msgObj = GameActivity.getActivity().getOmecaHandler().obtainMessage();
          Bundle b = new Bundle();
          p = GA.board.getPlayers().get(j);
          if (p != null) {
            b.putInt("playerPlace", j);
            msgObj.what = OmecaHandler.GIVETO;
            msgObj.setData(b);
            GameActivity.getActivity().getOmecaHandler().sendMessage(msgObj);
          }
        }
        try {
          Thread.sleep(200);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      return null;
    }
コード例 #3
0
ファイル: BoardView.java プロジェクト: widerules/omeca-2
    /** OnDrag event actions */
    @Override
    public boolean onDrag(View v, DragEvent event) {
      switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          break;
        case DragEvent.ACTION_DRAG_ENTERED:
          break;
        case DragEvent.ACTION_DRAG_EXITED:
          break;
        case DragEvent.ACTION_DROP:
          View vTmp = (View) event.getLocalState();
          if (vTmp instanceof CardView) {
            CardView view = (CardView) vTmp;
            ViewGroup parent = (ViewGroup) (view.getParent());
            parent.removeViewInLayout(view);
            addView(view);
            if (parent instanceof HandView) {
              CardView card = (CardView) view;
              card.setOnDragListener(null);
              Gallery g2 =
                  (Gallery)
                      GameActivity.getActivity()
                          .findViewById(R.id.playerview_slider_board_cardgallery);
              if (g2 != null) {
                SliderbarCardGallery a2 = (SliderbarCardGallery) g2.getAdapter();
                a2.notifyDataSetChanged();
              }
            } else if (parent instanceof BoardView) {
              // Cards grouped moving
              if (cardsGroup.getTouching().size() > 1)
                cardsGroup.move(event.getX(), event.getY(), getWidth(), getHeight());
            }
            MarginLayoutParams marginParams = new MarginLayoutParams(view.getLayoutParams());
            int left = (int) (event.getX() - (view.getWidth() / 2));
            int top = (int) (event.getY() - (view.getHeight() / 2));
            int right = (int) (((View) view.getParent()).getWidth() - left + view.getWidth());
            int bottom = (int) (((View) view.getParent()).getHeight() - top + view.getHeight());
            marginParams.setMargins(left, top, right, bottom);
            view.setLayoutParams(new RelativeLayout.LayoutParams(marginParams));

            if (parent instanceof HandView) {
              Log.i(WifiDirectProperty.TAG, "1");
              MoveCardAction movecard =
                  new MoveCardAction("Player", GA.user.getId(), view.getCard(), "BoardView");
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));

            } else if (parent instanceof DrawPileView) {
              MoveCardAction movecard =
                  new MoveCardAction("DrawPileView", "BoardView", view.getCard());
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));
            } else if (parent instanceof DiscardPileView) {
              MoveCardAction movecard =
                  new MoveCardAction("DiscardPileView", "BoardView", view.getCard());
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));
            }
            View tmp;
            for (int i = 0; i < getChildCount(); i++) {
              tmp = getChildAt(i);
              if (tmp instanceof CardView) tmp.setVisibility(View.VISIBLE);
            }
            vTmp.setVisibility(View.VISIBLE);
          } else {
            vTmp.setVisibility(View.VISIBLE);
          }
          cardsGroup.getTouching().clear();
          break;
        case DragEvent.ACTION_DRAG_ENDED:
          break;
        default:
          break;
      }
      return true;
    }