예제 #1
0
 public void move(boolean p, int dir) {
   if (p) {
     player1.setPosition((player1.getPostion() + dir) % gamesize);
   } else {
     player2.setPosition((player2.getPostion() + dir) % gamesize);
   }
 }
예제 #2
0
파일: GameMatch.java 프로젝트: VuDinh/SA
  public void startPlayingGame() {
    // set initial position for each player and create Hero
    HeroFactory hF = new HeroFactory();
    for (Iterator it = team2.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      System.out.println("slot Index:" + player.getSlotIndex());
      System.out.println("dao:" + dao);
      Cell c = dao.getHeroBeginPosition(player.getSlotIndex());
      player.setPosition(c);
      System.out.println("hero Index:" + player.getHeroIndex());
      player.setHero(hF.createHero(player.getHeroIndex()));
    }
    for (Iterator it = team1.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      Cell c = dao.getHeroBeginPosition(player.getSlotIndex());
      player.setPosition(c);
      System.out.println("hero Index:" + player.getHeroIndex());
      player.setHero(hF.createHero(player.getHeroIndex()));
    }
    PlayingGameRequest request = new PlayingGameRequest();
    request.setGame(this);

    // send Game request
    for (Iterator it = team2.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      player.getCom().write(new GameMatch(this));
    }
    for (Iterator it = team1.iterator(); it.hasNext(); ) {
      Player player = (Player) it.next();
      player.getCom().write(new GameMatch(this));
    }
  }
예제 #3
0
파일: Map.java 프로젝트: twhscs/game
 public void setPlayer(Player player) {
   this.player = player;
   player.setMap(this);
   System.out.println(DIMENSIONS);
   player.setPosition(Position.round(new Vector2f(DIMENSIONS.x / 2, DIMENSIONS.y / 2)));
   System.out.println(player.getPosition());
 }
  public void performDice(Player currentPlayer) {
    if (!isFinished()) {
      checkFinish(currentPlayer);
      currentPlayer.setDiceResult((int) (Math.random() * 3 + 1));
      currentPlayer.setPosition(currentPlayer.getPositon() + currentPlayer.getDiceResult());

      if (currentPlayer.getPositon() > 6) currentPlayer.setPosition(6);

      if (currentPlayer.getPositon() == 2 || currentPlayer.getPositon() == 5)
        resetPlayer(currentPlayer);

      checkFinish(currentPlayer);
    }
    // else: already finished the game
    else {
      currentPlayer.setDiceResult(0);
    }
  }
예제 #5
0
  public static void handleBanishment(Player player) {
    System.out.println("You're banished on the Moon.");

    // make sure the player is on a banish space
    while (!(board.getSpaces()[player.getBoardPosition()] instanceof MoonSpace)) {
      player.setPosition((player.getBoardPosition() + 1) % Board.BOARDSPACES, board);
    }

    if (player.getBanishmentAvoidChances() > 0) {
      System.out.println(
          "You can leave the Moon by using a "
              + "banishment avoid chance. Would you like to do "
              + "this? Y/N");
      if (Util.getResponse()) {
        player.changeBanishmentAvoidChances(-1);
        player.setBanished(0);
        System.out.println(
            "You're no longer banished. "
                + "You have "
                + player.getBanishmentAvoidChances()
                + " banishment avoid chances left");
        return;
      }
    }

    if (player.getCash() >= 50) {
      System.out.println(
          "You can leave the Moon now by " + "paying 50 bits. Would you like to pay? Y/N");
      if (Util.getResponse()) {
        player.changeCash(-50);
        player.setBanished(0);
        System.out.println("You're no longer banished");
        return;
      }
    }

    System.out.println(
        "You can escape from the Moon if you roll "
            + "a double. Press Enter when you want to roll");

    // wait for Enter key to be pressed
    input.nextLine();

    rollDice(player);

    int[] lastRolls = player.getLastRolls();
    if (lastRolls[0] == lastRolls[1]) {
      System.out.println("You escaped!");
      player.setBanished(0);
      player.move();
    } else {
      System.out.println("You remain on the Moon until at least " + "your next turn");
      player.setBanished(player.getBanished() - 1);
    }
  }
 private void resetPlayer(Player player) {
   player.setPosition(0);
 }