@Override
  public void discard() {

    DiscardCards command = new DiscardCards(ModelFacade.getUserPlayerInfo().getIndex(), theList);

    try {
      MasterController.getSingleton().discardCards(command);
      ModelFacade.getUserPlayer().setDiscarded(true);
    } catch (ServerException e) {
      System.err.println(e.getReason());
    }

    closeModal();
  }
  @Override
  public void update() {
    if (MasterController.getSingleton().hasGameBegun()
        && ModelFacade.whatStateMightItBe() == Status.Discarding
        && !ModelFacade.getUserPlayer().hasDiscarded()) {
      Player user = ModelFacade.getUserPlayer();

      updateDiscardView();

      if (user.needsToDiscard()) {
        showModal();
      }
    }
  }
  public DiscardController(IDiscardView view, IWaitView waitView) {

    super(view);

    this.waitView = waitView;

    theList = new ResourceList(0, 0, 0, 0, 0);

    ModelFacade.addObserver(this);

    modalIsVisible = false;
    waitModalIsVisible = false;
  }
  public void updateDiscardView() {
    Player user = ModelFacade.getUserPlayer();

    int numToDiscard = user.getResources().getTotal() / 2;

    getDiscardView().setDiscardButtonEnabled(numToDiscard == theList.getTotal());
    getDiscardView().setStateMessage("Discard " + theList.getTotal() + "/" + numToDiscard);

    for (ResourceType type : ResourceType.values()) {
      int amount = user.getResourceAmount(type);
      int value = theList.getResource(type);

      getDiscardView().setResourceDiscardAmount(type, value);
      getDiscardView().setResourceMaxAmount(type, amount);

      getDiscardView()
          .setResourceAmountChangeEnabled(
              type, value < amount && numToDiscard > theList.getTotal(), value != 0);
    }
  }