private void parsePaymentRequest(Protos.PaymentRequest request) throws PaymentProtocolException { try { if (request == null) throw new PaymentProtocolException("request cannot be null"); if (request.getPaymentDetailsVersion() != 1) throw new PaymentProtocolException.InvalidVersion( "Version 1 required. Received version " + request.getPaymentDetailsVersion()); paymentRequest = request; if (!request.hasSerializedPaymentDetails()) throw new PaymentProtocolException("No PaymentDetails"); paymentDetails = Protos.PaymentDetails.newBuilder() .mergeFrom(request.getSerializedPaymentDetails()) .build(); if (paymentDetails == null) throw new PaymentProtocolException("Invalid PaymentDetails"); if (!paymentDetails.hasNetwork()) params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork( "Invalid network " + paymentDetails.getNetwork()); if (paymentDetails.getOutputsCount() < 1) throw new PaymentProtocolException.InvalidOutputs("No outputs"); for (Protos.Output output : paymentDetails.getOutputsList()) { if (output.hasAmount()) totalValue = totalValue.add(Coin.valueOf(output.getAmount())); } // This won't ever happen in practice. It would only happen if the user provided outputs // that are obviously invalid. Still, we don't want to silently overflow. if (params.hasMaxMoney() && totalValue.compareTo(params.getMaxMoney()) > 0) throw new PaymentProtocolException.InvalidOutputs("The outputs are way too big."); } catch (InvalidProtocolBufferException e) { throw new PaymentProtocolException(e); } }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Drawing public void drawCoin(Graphics g) { // draws the coins for (Coin i : coinList) { g.drawImage( i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null); i.count(); i.setDirection(); } }
/** Returns a {@link Wallet.SendRequest} suitable for broadcasting to the network. */ public Wallet.SendRequest getSendRequest() { Transaction tx = new Transaction(params); for (Protos.Output output : paymentDetails.getOutputsList()) tx.addOutput( new TransactionOutput( params, tx, Coin.valueOf(output.getAmount()), output.getScript().toByteArray())); return Wallet.SendRequest.forTx(tx).fromPaymentDetails(paymentDetails); }
public void scrollCoins() { for (Coin i : coinList) { i.setY(i.getY() + (int) (player1.getVelocity() * 0.3)); i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3)); i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3)); } }
/** Returns the outputs of the payment request. */ public List<PaymentProtocol.Output> getOutputs() { List<PaymentProtocol.Output> outputs = new ArrayList<PaymentProtocol.Output>(paymentDetails.getOutputsCount()); for (Protos.Output output : paymentDetails.getOutputsList()) { Coin amount = output.hasAmount() ? Coin.valueOf(output.getAmount()) : null; outputs.add(new PaymentProtocol.Output(amount, output.getScript().toByteArray())); } return outputs; }
public void checkPupCollision() { // pretty much the same thing as before, however it alsoe does the powerup effects for (Powerup p : pupList) { if (p.getOnScreen()) { // can be removed later on if (p.checkCollision(player1)) { pupRemove.add(p); player1.setPower(p.getType()); player1.setVelo(50); } } else { pupRemove.add(p); } } if (player1.getPower().equals("Lucky")) { // changes everything to stars for (Coin c : coinList) { starList.add(new Star(c.getX(), c.getY(), 2)); cRemove.add(c); } for (Box b : boxList) { starList.add(new Star(b.getX(), b.getY(), 2)); bRemove.add(b); } for (Enemy e : enemyList) { starList.add(new Star(e.getX(), e.getY(), 2)); eRemove.add(e); } } else if (player1.getPower().equals("Magnet")) { // moves the coins towards the player for (Coin c : coinList) { c.moveTowards(player1); } } else { // else do nothing } for (Powerup p : pupRemove) { poofList.add(new Poof(p.getX(), p.getY(), 2)); pupList.remove(p); } pupRemove = new ArrayList<Powerup>(); }
public void checkCoinCollision() { for (Coin c : coinList) { if (c.getOnScreen()) { // check if the coin is on the screen if (c.checkCollision( c.getPics().get(c.getCounter()), player1)) { // if the player collides with the coin cRemove.add(c); // remove the coin player1.setVelo(50); // set the velocity so the player moves up player1.setDown(false); // set the down false (players moving up) coins += c.getValue(); // check the coins collected score += c.getPoints(); // get the score if (musicOn) { coinSound.play(); // play the sound } } } else { cRemove.add(c); // remove the coin } } for (Coin c : cRemove) { poofList.add(new Poof(c.getX(), c.getY(), 0)); coinList.remove(c); } cRemove = new ArrayList<Coin>(); }
public void moveCoins() { for (Coin i : coinList) { i.move(); } }