예제 #1
1
 public void victory() {
   battleWon = true;
   player.expGain(totalExperience);
   enemies.removeAll(enemies);
   spellsThrown.removeAll(spellsThrown);
   staminaTimer.stop();
 }
예제 #2
0
 @Override
 public void update(Observable o, Object arg) {
   if (arg instanceof Player) {
     Player player = (Player) arg;
     int points = player.getPoints();
     System.out.println("Spieler" + player.getNum() + "an der Reihe");
     if (player.getNum() == 1) {
       System.out.println("Spieler1 punkte++");
       points1Num.setText("" + points);
     } else if (player.getNum() == 2) {
       System.out.println("Spieler2 punkte++");
       points2Num.setText("" + points);
     }
   } else {
     GameController controller = (GameController) arg;
     if (controller.getPlayer().getNum() == 1) {
       ImageIcon image = new ImageIcon("../gfx/spieler1_play.png");
       l1.setIcon(image);
       ImageIcon imageOld = new ImageIcon("../gfx/spieler2.png");
       l2.setIcon(imageOld);
       System.out.println("spieler gewechselt");
     } else {
       ImageIcon imageI = new ImageIcon("../gfx/spieler2_play.png");
       l2.setIcon(imageI);
       ImageIcon imageOldI = new ImageIcon("../gfx/spieler1.png");
       l1.setIcon(imageOldI);
     }
   }
 }
예제 #3
0
 public void mouseClicked(MouseEvent e) {
   if (scene == BATTLE) {
     if (!battleWon) {
       int target = 0;
       if (kickDirt.contains(mX, mY) && player.getStamina() >= 33.3 && !player.getDeath()) {
         spellsThrown.add(
             new Spell(
                 0,
                 new Color(153, 76, 0),
                 player.centerX(),
                 player.centerY(),
                 enemies.get(target).centerX(),
                 enemies.get(target).centerY(),
                 target));
         player.staminaGain(-333);
       }
       if (hurlPebble.contains(mX, mY) && player.getStamina() >= 100 && !player.getDeath()) {
         spellsThrown.add(
             new Spell(
                 1,
                 Color.LIGHT_GRAY,
                 player.centerX(),
                 player.centerY(),
                 enemies.get(target).centerX(),
                 enemies.get(target).centerY(),
                 target));
         player.staminaGain(-1000);
       }
     }
   }
 }
 public String[] getPropertyName() {
   String[] save = new String[x.getProperties().size()];
   for (int i = 0; i < x.getProperties().size(); i++) {
     save[i] = (Game.SlotsList[x.getProperties().get(i)]).getName();
   }
   return save;
 }
예제 #5
0
  public void keyReleased(KeyEvent key) {

    if (key.getKeyCode() == 37) {

      leftcheck = false;
      if (rightcheck) {
        player.ta = changet;
      } else {
        player.ta = 0;
      }
    }

    if (key.getKeyCode() == 39) {

      rightcheck = false;
      if (leftcheck) {
        player.ta = -changet;
      } else {
        player.ta = 0;
      }
    }

    if (key.getKeyCode() == 32) {

      grav = false;
    }
  }
예제 #6
0
  public void drawVictory(Graphics g) {
    g.setColor(new Color(0, 0, 0, 200));
    g.fillRect(195, 220, 410, 110);
    g.setColor(new Color(255, 255, 255, 200));
    g.fillRect(200, 225, 400, 100);
    g.setColor(new Color(0, 0, 0, 200));
    g.setFont(new Font("Bell MT", Font.BOLD, 20));
    FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
    int hgt = metrics.getHeight();

    String initialMessage;
    String followupMessage;

    if (nextWindow) {
      initialMessage = "You have gotten stronger.";
      followupMessage = player.getName() + " is now level " + player.getLevel() + "!";
    } else {
      initialMessage = "You survived!";
      followupMessage = "You and your allies gain " + totalExperience + " experience!";
    }

    // Hgt = 26
    int adv = metrics.stringWidth(initialMessage);
    g.drawString(initialMessage, getWidth() / 2 - adv / 2, 234 + hgt);
    adv = metrics.stringWidth(followupMessage);
    g.drawString(followupMessage, getWidth() / 2 - adv / 2, 269 + hgt);
  }
예제 #7
0
 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));
   }
 }
예제 #8
0
 public void scrollEnemies() {
   for (Enemy i : enemyList) {
     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));
   }
 }
예제 #9
0
 public void checkEnemyCollision() {
   for (Enemy e : enemyList) {
     if (e.getOnScreen()) { // can be removed later on
       // goes through all the enemies and checks if they collide
       if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) {
         if (player1.getInvi() == false) {
           // If the player is not invisble then you get spiked.
           if (player1.getVelocity() > 0) { // if the player hits it from the bottom
             player1.setSpikeVelo();
             loseCoins();
           } else {
             player1.setVelo(
                 50); // if the player is on top instead the player bounces off the enemy
             if (musicOn) {
               bounce.play();
             }
           }
         }
         eRemove.add(e); // once we hit, we remove the enemy
       }
     } else {
       eRemove.add(e); // if the enemy goes of the screen, we remove
     }
   }
   for (Enemy e : eRemove) {
     poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies
     enemyList.remove(e);
   }
   eRemove = new ArrayList<Enemy>();
 }
예제 #10
0
 public void checkStarCollision() {
   for (Star s : starList) {
     if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides
       if (s.checkCollision(
           s.getPics().get(s.getCounter()),
           player1)) { // if the player collides with the star we remove it then change the
         // velosity to the distance that the star provides
         sRemove.add(s); // remove star once you collide with it
         player1.setVelo(s.getDist()); // changes the velocity
         player1.setInvi(true); // sets the player invisble for a few seconds
         score += s.getPoints(); // points increase by the star type
         if (musicOn) {
           starSound.play(); // playthe star sound
         }
       }
     } else {
       sRemove.add(s); // remove the star if its not on the screen
     }
   }
   for (Star s : sRemove) {
     poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect
     starList.remove(s);
   }
   sRemove = new ArrayList<Star>();
 }
예제 #11
0
  public static void loadPlayer(Registry registry) {
    Player p = (Player) getPlayers().get(player);
    if (p != null) {
      p.setTransient(registry);
    }

    GameController gc = registry.getGameController();
    registry.getPlayerManager().clearPlayers();
    registry.getPlayerManager().registerPlayer(p);
    BlockManager bm = (BlockManager) blockManagers.get(player);
    bm.name = "Saved";
    bm = (BlockManager) bm.clone();
    bm.name = "Clone";
    bm.setTransient(registry);
    gc.setBlockManager(bm);
    PlaceableManager pm = (PlaceableManager) placeableManagers.get(player).clone();
    gc.setPlaceableManager(pm);
    MonsterManager mm = (MonsterManager) monsterManagers.get(player).clone();
    mm.setTransient(registry);
    gc.setMonsterManager(mm);

    if (p != null) {
      p.resetPlayer();
    }

    // unloadUnused();
  }
예제 #12
0
 public void keyReleased(KeyEvent evt) {
   keys[evt.getKeyCode()] = false;
   // reset the counters for for the sprite s
   player1.resetCounter();
   if (!player1.getPower().equals("Balloon")) {
     player1.resetPicCounter();
   }
 }
예제 #13
0
 // paints the player, items, and rooms
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Environment Layout = new Environment();
   Layout.drawRoom(mapX, mapY, g);
   Player PlayerSprite = new Player();
   PlayerSprite.drawPlayer(x, y, g);
   Layout.items(x, y, g, getItem);
 }
예제 #14
0
 private void assignCards() {
   player.clearCards();
   dealer.clearCards();
   for (int i = 0; i < 3; ++i) {
     player.assignCard(genNewCard());
     dealer.assignCard(genNewCard());
   }
 }
예제 #15
0
 public void actionPerformed(ActionEvent action) {
   player.Update();
   viewScreen.CenterOnObject(player.getBoundingBox());
   map.centerOnWorldCoordinates(
       new Point((int) player.getBoundingBox().x, (int) player.getBoundingBox().y));
   collisionManager.handleCollisions();
   this.repaint();
   this.requestFocus();
 }
예제 #16
0
 /**
  * Update changing components.
  *
  * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
  */
 @Override
 public void paintComponent(Graphics g) {
   money.setText(String.valueOf(player.getMoney()));
   record.setText(String.valueOf(bestScore));
   dealerPanel.removeAll();
   playerPanel.removeAll();
   for (Card dealerCard : dealer.getCards()) dealerPanel.add(dealerCard);
   for (Card playerCard : player.getCards()) playerPanel.add(playerCard);
   revalidate();
 }
예제 #17
0
 // @Override
 public synchronized void sacarIdPlayer(String ids) {
   for (Player d : getJugadores()) {
     if (d.getId() != null) {
       if (d.getId().equals(ids)) {
         d.setId(null);
         break;
       }
     }
   }
 }
예제 #18
0
 private Player getPlayerId(String wd) {
   for (Player y : getJugadores()) {
     if (y.getId() != null) {
       if (y.getId().equals(wd)) {
         return y;
       }
     }
   }
   return null;
 }
예제 #19
0
  private void final_scores(Match m) {
    int numPlayers = 0;
    int playerTotal = 0;
    int gameNum = 0, maxGameNum = 0;
    Player p;

    // Create window
    final JFrame f = new JFrame();
    JPanel titles = new JPanel();
    titles.setLayout(new BorderLayout());
    JLabel maintitle = new JLabel("Yahtzee World!");
    maintitle.setFont(new Font("SansSerif", Font.ITALIC, 24));
    JLabel instr = new JLabel("Final Scores (total of game scores).");
    instr.setFont(new Font("SansSerif", Font.PLAIN, 16));
    titles.add(maintitle, "North");
    titles.add(instr, "South");

    JPanel names = new JPanel();
    JLabel l[] = new JLabel[Match.MAXPLAYERS];
    final JTextField t[] = new JTextField[Match.MAXPLAYERS];

    numPlayers = m.getNumPlayers();
    names.setLayout(new GridLayout(numPlayers, 2));
    for (int playerNum = 0; playerNum < numPlayers; playerNum++) {
      p = m.getPlayer(playerNum);
      playerTotal = 0;
      l[playerNum] = new JLabel(p.getName());
      t[playerNum] = new JTextField(20);
      names.add(l[playerNum]);
      names.add(t[playerNum]);
      maxGameNum = (m.getGameNum() >= Match.MAXGAMES) ? (Match.MAXGAMES - 1) : m.getGameNum();
      for (gameNum = 0; gameNum <= maxGameNum; gameNum++) {
        playerTotal += p.getScoreCell(gameNum, CellCodes.GRANDTOTAL);
      }
      t[playerNum].setText(String.valueOf(playerTotal));
    }

    JButton quit = new JButton("Quit");
    quit.addActionListener(
        new ActionListener() {
          // This method is called when the user clicks the JButton
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    f.add(titles, "North");
    f.add(names, "Center");
    f.add(quit, "South");
    f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    f.setResizable(false);
  }
예제 #20
0
  //    public static void unloadUnused() {
  //        if (player > -1) {
  //            for (int i = 0; i < NUMBER_OF_PLAYER_SLOTS; i++) {
  //                if (i != player) {
  //                    players.set(i, null);
  //                    blockManagers.set(i, null);
  //                    placeableManagers.set(i, null);
  //                    monsterManagers.set(i, null);
  //                }
  //            }
  //        }
  //    }
  public static ArrayList getPlayerList() {
    ArrayList names = new ArrayList();

    for (int i = 0; i < players.size(); i++) {
      Player p = players.get(i);
      if (p != null) {
        names.add(p.getName());
      } else {
        names.add("");
      }
    }
    return names;
  }
예제 #21
0
 // @Override
 public synchronized void asignarIdPlayer(String ids) throws Exception {
   boolean found = false;
   for (Player d : getJugadores()) {
     if (d.getId() == null) {
       d.setId(ids);
       found = true;
       break;
     }
   }
   if (!found) {
     throw new Exception("Partida completa.");
   }
 }
예제 #22
0
  public void actionPerformed(ActionEvent ae) {

    if (ae.getSource() == stopButton) {
      if (player != null) {
        player.stop(); // NOTE: stop() is a synchronous method !
      }
    } else {
      player.stop(); // NOTE: stop() is a synchronous method !
      player.close();
      // waitForState(player.Closed);
      System.out.print("Player Closed - Exiting");
      System.exit(0);
    }
  }
예제 #23
0
 private void movePlayers() {
   onePlayerAlive = false;
   Iterator i = players.iterator();
   while (i.hasNext()) {
     Player p = (Player) i.next();
     if (p.getLives() == 0) {
       p.setActive(false);
     }
     if (p.isActive()) {
       onePlayerAlive = true;
       p.move();
     }
   }
 }
예제 #24
0
 public void loseCoins() {
   int x = player1.getX();
   int y = player1.getY();
   double losePercentage = 0.1;
   for (int i = 0;
       i < (int) coins * losePercentage;
       i++) { // makes the user lose 10 percent of the coin and draws them in a circle
     // System.out.println(i);
     int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i)));
     int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i)));
     coinList.add(new Coin(xPos, yPos, 3));
   }
   coins -= (int) (coins * losePercentage);
 }
예제 #25
0
  private void setup() {
    playerSetup();

    deathLocation = new int[4];
    Arrays.fill(deathLocation, -1);

    menu.setVisible(false);
    this.revalidate();

    audioSetup();

    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();
      p.resetLives(3);
      p.setActive(true);
    }

    BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Cursor blank =
        Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "BLANK");
    this.setCursor(blank);

    reset();

    ballN = 1;
    level = 1;
    timeLast = 0;
    score = 0;
    counterN = 10;
    timeCircle = 0;
    timeCircleSwitch = 0;
    programLoopCounter = 1;
    programSpeedAdjust = 1;

    onePlayerAlive = true;
    countdownF = true;
    circular = true;
    spawnIncrease = true;
    spawnCircleB = false;
    spawnMonsterB = false;
    spawnRandomersB = false;

    levelSetup();
    countdown();
    animate();
  }
예제 #26
0
 // @Override
 public synchronized void tick() {
   ArrayList<Element> d = new ArrayList<>();
   for (Player l : jugadores) {
     l.tick();
   }
   for (Player z : jugadores) {
     for (Element x : restriccion) {
       // To avoid player go outside the arena.
       tickUp(z, x, d);
       tickDown(z, x, d);
       tickRight(z, x, d);
       tickLeft(z, x, d);
     }
   }
   restriccion.removeAll(d);
 }
예제 #27
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (scene == OVERWORLD) g.drawImage(background, 0, 0, this);
   if (scene == BATTLE) {
     if (battleBG == 1) g.drawImage(background, 0, -130, this);
     else g.drawImage(background, 0, 0, this);
   }
   int loop;
   for (loop = 0; loop < enemies.size(); loop++) {
     if (scene == OVERWORLD) {
       enemies.get(loop).drawEnemy(g);
     }
     if (scene == BATTLE) {
       if (enemies.get(loop).getActivity()) {
         enemies.get(loop).drawEnemy(g);
       }
     }
   }
   for (loop = 0; loop < spellsThrown.size(); loop++) {
     spellsThrown.get(loop).drawSpell(g);
   }
   player.drawPlayer(g);
   for (loop = 0; loop < enemies.size(); loop++) {
     enemies.get(loop).drawSpells(g);
   }
   if (scene == BATTLE) {
     drawMenu(g);
     if (battleWon) drawVictory(g);
     else if (battleLost) drawDefeat(g);
   }
 }
예제 #28
0
 static int isEnd(Player player) {
   int i;
   for (i = 1; i <= 5; i++) {
     if (player.haveHide("End" + i)) return i;
   }
   return 0;
 }
예제 #29
0
  public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
      p5.add(mortgage);
      Slot pobject;
      pobject = Game.SlotsList[x.getProperties().get(propertydisplay.getSelectedIndex())];
      if (pobject instanceof Property) {
        ((Property) (pobject)).monopolizeProperty();
        pr1.setText("Buy Price:" + pobject.getBuyPrice());
        pr2.setText("Rent Price:" + pobject.getRentPrice());
        pr3.setText("House Price:" + pobject.getHousePrice());
        pr4.setText("Hotel Price:" + pobject.getHotelPrice());
        pr5.setText("Mortgaged:" + pobject.getMortgage());
      } else if (pobject instanceof Railroad) {
        pobject.adjustRentPrice();
        pr1.setText("Buy Price:" + pobject.getBuyPrice());
        pr2.setText("Rent Price:" + pobject.getRentPrice());
        pr3.setText("");
        pr4.setText("");
        pr5.setText("");

      } else {
        pobject.adjustDiceFactor();
        pr1.setText("Buy Price:" + pobject.getBuyPrice());
        pr2.setText("Dice Factor:" + pobject.getDiceFactor());
        pr3.setText("");
        pr4.setText("");
        pr5.setText("");
      }
    }
  }
  public void captureImage() {
    String savepath =
        this.saveDirectory + "\\cam" + this.getDateFormatNow("yyyyMMdd_HHmmss-S") + ".jpg";
    System.out.println("Capturing current image to " + savepath);

    // Grab a frame
    FrameGrabbingControl fgc =
        (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
    buf = fgc.grabFrame();

    // Convert it to an image
    btoi = new BufferToImage((VideoFormat) buf.getFormat());
    img = btoi.createImage(buf);

    // save image
    saveJPG(img, savepath);

    // show the image
    // imgpanel.setImage(img);

    // images.add(img);
    images.add(savepath);

    if (images_lastadded.size() >= lastadded_max) {
      // Remove last
      images_lastadded.remove(images_lastadded.size() - 1);
    }

    images_lastadded.add(0, images.size() - 1);
    images_nevershown.add(0, images.size() - 1);

    forceNewImage();
  }