/** Checks if the player collides with a blip, power blip, or a ghost. */
 public void checkCollision() {
   Rectangle playerRect =
       new Rectangle(player.getCenter().x - 8, player.getCenter().y - 8, 13, 13);
   for (Enemy enemy : enemies) {
     Rectangle enemyRect = new Rectangle(enemy.getCenter().x - 8, enemy.getCenter().y - 8, 13, 13);
     if (playerRect.intersects(enemyRect)) {
       if (!enemy.isAlive()) {
         continue;
       }
       if (Globals.state == ENEMY_HUNTER_STATE) {
         Globals.game.playerKilled();
         player.loseALife();
         // player is dead, so we paint the dead player screen
         paintDeadPlayer();
         try {
           // sleep to make it stay on screen
           Thread.sleep(1500);
         } catch (InterruptedException e) {
           // DO nothing
         }
         resetCanvas();
         // we return because only one enemy should be able to make a player lose a life
         return;
       } else if (Globals.state == ENEMY_HUNTED_STATE) {
         if (enemy.isAlive()) {
           enemy.setAlive(false);
           player.addPoints(POINTS_FOR_KILLING_ENEMY);
         }
       }
     } else {
       continue;
     }
   }
 }
Exemple #2
0
 @Test
 public void testAddPoints() {
   ZilchGame game = new ZilchGame();
   Player p = new Player("Paris");
   game.add(p);
   assertEquals(0, game.getCurrentPlayer().getScore());
   p.addPoints(200);
   assertEquals(200, game.getCurrentPlayer().getScore());
 }
Exemple #3
0
 @Test
 public void test_scoring_bits() {
   ZilchGame z = new ZilchGame();
   Player p;
   z.add(p = new Player("Fernando"));
   z.add(new Player("Julio"));
   assertNull(z.getWinner());
   p.addPoints(ZilchGame.MAX_SCORE + 1);
   assertEquals(p, z.getWinner());
   assertEquals(10001, z.getScore(p));
 }
 public void achieve(int playerID, int gameID, int achievementID) {
   if (players.containsKey(playerID) && achievements.containsKey(achievementID)) {
     Player p = players.get(playerID);
     Achievement a = achievements.get(achievementID);
     if (p.games.containsKey(gameID)
         && !p.games.get(gameID).achievements.contains(achievementID)) {
       Playing playerInfo = p.games.get(gameID);
       int pointsEarned = a.points;
       playerInfo.achievements.add(achievementID);
       playerInfo.addPoints(pointsEarned);
       p.addPoints(pointsEarned);
       a.players.add(playerID);
     } else {
       // System.out.println("player does not play this game or already has this achievement");
     }
   } else {
     // System.out.println("player or achievement does not exist");
   }
 }
Exemple #5
0
  @Test
  public void test_Jamaal_plays_zilch() {
    ZilchGame z = new ZilchGame();
    Player p, j;
    z.add(p = new Player("Jamaal"));
    z.add(j = new Player("Hussein"));

    p.addPoints(0);
    p.addPoints(0);
    p.addPoints(0);

    j.addPoints(0);
    j.addPoints(0);
    j.addPoints(0);

    j.addPoints(0);
    j.addPoints(0);
    j.addPoints(0);

    assertEquals((-1000), j.getScore());

    ArrayList<Die> dice = z.getDice();

    dice.get(0).setFace(1);

    Player pablo = z.getCurrentPlayer();

    int score = z.getScore(pablo);

    pablo.play(new boolean[] {true, false, false, false, false, false});

    assertEquals(5, z.getDice().size());

    dice = z.getDice();

    dice.get(0).setFace(3);
    pablo.play(new boolean[] {true, false, false, false, false});
    System.out.println(z.getScore(pablo));
    System.out.println(score);
    System.out.println(pablo.getName());

    assertTrue(z.getScore(pablo) + 1000 == score);
  }
Exemple #6
0
  /** This method represents a game */
  private void game() {
    Scanner scan = new Scanner(System.in);
    String userInput;

    do {
      // read user input
      // by default it is y
      // if user input nothing consider that he wants default and use default
      System.out.print("Do you want to roll? (Y/n/q): ");
      String input = scan.nextLine();
      System.out.println();
      if (input.equals("")) {
        userInput = "y";
      } else {
        userInput = input;
      }

      // while user input value is y
      // it is user's turn
      // if user input value is n it means that it's machine's turn
      while (userInput.equalsIgnoreCase("y")) {
        // roll dices
        dices.roll();

        // add both values from dices to point of a current turn
        user.addCurrentTurnPoints(dices.getValue1() + dices.getValue2());

        // if we get '1' or two '1' then drop points for player
        // and change a hand to machine
        if (dices.getValue1() == 1 || dices.getValue2() == 1) {
          if (dices.getValue1() == dices.getValue2()) {
            System.out.println("You rolled two 1s. You lose all of your points and your hand");
            user.dropPoints(true);
            userInput = "n";
          } else {
            System.out.println("You rolled 1. You lose current points and your hand");
            user.dropPoints(false);
            userInput = "n";
          }
        }

        // if hand is still user's then show result and ask for a next roll of dices
        if (userInput.equalsIgnoreCase("y")) {
          System.out.println(
              "So far you have all points: "
                  + user.getAllPoints()
                  + " and points at current turn: "
                  + user.getPointsCurrentTurn());
          System.out.println("So far your enemy has all points: " + machine.getAllPoints());
          System.out.print("Do you want to roll? (Y/n/q): ");
          input = scan.nextLine();
          System.out.println();
          if (input.equals("")) {
            userInput = "y";
          } else {
            userInput = input;
          }
        }
      }
      // if user asks to stop rolling then adding points from current turn to all points
      // but if we dropped point of user we will add "0"
      user.addPoints(user.getPointsCurrentTurn());

      // while turn is 'n' (machine's) and points of machine for current turn less than 20
      while (userInput.equalsIgnoreCase("n") && machine.getPointsCurrentTurn() < 20) {
        // roll dices
        dices.roll();

        // add dices' values to current points of machine
        machine.addCurrentTurnPoints(dices.getValue1() + dices.getValue2());

        // check if there is not '1' value on any dice
        // if there is then drop points and change turn
        if (dices.getValue1() == 1 || dices.getValue2() == 1) {
          if (dices.getValue1() == dices.getValue2()) {
            System.out.println("Machine rolled two 1s. It loses all its points and its hand");
            machine.dropPoints(true);
            userInput = "y";
          } else {
            System.out.println("Machine rolled 1. It loses current points and its hand");
            machine.dropPoints(false);
            userInput = "y";
          }
        }
      }
      // if machine got points for current turn more than 20
      // then it stores these points
      machine.addPoints(machine.getPointsCurrentTurn());

      // if no one won we print results again
      if (user.getAllPoints() < 100 && machine.getAllPoints() < 100) {
        System.out.println(
            "So far you have all points: "
                + user.getAllPoints()
                + " and points at current turn: "
                + user.getPointsCurrentTurn());
        System.out.println("So far your enemy has all points: " + machine.getAllPoints());
      }
    } while (!userInput.equals("q") && user.getAllPoints() < 100 && machine.getAllPoints() < 100);

    System.out.println();

    // if someone won then print results and points
    if (user.getAllPoints() >= 100) {
      System.out.println("You win with " + user.getAllPoints() + " points");
      System.out.println("Your enemy has " + machine.getAllPoints() + " points");
    } else if (machine.getAllPoints() >= 100) {
      System.out.println("You lose");
      System.out.println("You have " + user.getAllPoints() + " points");
      System.out.println("Your enemy has " + machine.getAllPoints() + " points");
    }
  }