Exemplo n.º 1
0
  private void manageDiscardTreasures(boolean visible, Player aPlayer) {
    int howMany;
    int option;

    do { // Se descartan tesoros hasta que se vuelve al menú anterior
      if (visible) {
        howMany =
            showTreasures(
                "Elige tesoros visibles para descartar", aPlayer.getVisibleTreasures(), true);
      } else {
        howMany =
            showTreasures(
                "Elige tesoros ocultos para descartar", aPlayer.getHiddenTreasures(), true);
      }
      option = getTreasure(howMany);
      if (option > Command.GoBack.menu) {
        if (visible) {
          game.discardVisibleTreasures(
              new ArrayList(Arrays.asList(aPlayer.getVisibleTreasures().get(option))));
        } else {
          game.discardHiddenTreasures(
              new ArrayList(Arrays.asList(aPlayer.getHiddenTreasures().get(option))));
        }
      }
    } while (option != Command.GoBack.menu);
  }
Exemplo n.º 2
0
  public void play(Napakalaki aGame, int numberOfPlayers) {
    Command command;
    CombatResult combatResult;
    Player currentPlayer;
    ArrayList<String> names;

    game = aGame;

    names = getPlayerNames(numberOfPlayers);

    System.out.print("delante initgame\n");
    game.initGame(names);
    System.out.print("pasa initgame\n");
    do { // Mientras dure la partida
      currentPlayer = game.getCurrentPlayer();
      do { // Mientras el jugador se decide a conocer al monstruo
        System.out.println("******* ******* ******* ******* ******* ******* *******");
        System.out.println("\n\n Turno de: " + currentPlayer.toString());
        command = getCommandBeforeKnowingMonster();
        command = processCommand(command, currentPlayer);
      } while (command != Command.Exit && command != Command.ShowMonster);
      if (command == Command.ShowMonster) {
        do { // Mientras el jugador se decida a combatir
          System.out.println("******* ******* ******* ******* ******* ******* *******");
          System.out.println("\n\n Turno de: " + currentPlayer.toString());
          command = getCommandBeforeFighting();
          command = processCommand(command, currentPlayer);
        } while (command != Command.Exit && command != Command.Combat);
        if (command == Command.Combat) {
          combatResult = game.developCombat();
          switch (combatResult) {
            case WINGAME:
              System.out.println("\n\n       " + currentPlayer.getName());
              System.out.println("\n\n ¡¡¡ H A S   G A N A D O   L A   P A R T I D A !!!");
              break;
            case WIN:
              System.out.println("\n\n Ganaste el combate");
              break;
            case LOSE:
              System.out.println("\n\n Has perdido el combate, te toca cumplir el mal rollo");
              break;
          }
          if (combatResult != CombatResult.WINGAME) {
            do { // Hasta que se avance de turno
              System.out.println("******* ******* ******* ******* ******* ******* *******");
              System.out.println("\n\n Turno de: " + currentPlayer.toString());
              if (currentPlayer.canISteal()) command = getCommandAfterFighting();
              else command = getCommandAfterFightingNoSteal();
              command = processCommand(command, currentPlayer);
            } while (command != Command.Exit && command != Command.NextTurnAllowed);
          } else {
            command = Command.Exit;
          }
        } // if (command == Command.Combat)
      } // if (command == Command.ShowMonster)
    } while (command != Command.Exit); // Mientras dure la partida
  }
Exemplo n.º 3
0
  private Command processCommand(Command command, Player aPlayer) {
    Treasure aTreasure;

    switch (command) {
      case Exit:
        break;
      case Combat:
        break;
      case ShowMonster:
        System.out.println("\n------- ------- ------- ------- ------- ------- ------- ");
        System.out.println("El monstruo actual es:\n\n" + game.getCurrentMonster().toString());
        break;
      case ShowVisibleTreasure:
        showTreasures("Esta es tu lista de tesoros visibles", aPlayer.getVisibleTreasures(), false);
        break;
      case ShowHiddenTreasure:
        showTreasures("Esta es tu lista de tesoros ocultos", aPlayer.getHiddenTreasures(), false);
        break;
      case MakeTreasureVisible:
        manageMakeTreasureVisible(aPlayer);
        break;
      case DiscardVisibleTreasure:
        manageDiscardTreasures(true, aPlayer);
        break;
      case DiscardHiddenTreasure:
        manageDiscardTreasures(false, aPlayer);
        break;
      case DiscardAll:
        aPlayer.discardAllTreasures();
        break;
      case StealTreasure:
        aTreasure = aPlayer.stealTreasure();
        if (aTreasure == null) System.out.println("\n\n No has podido robar nada \n\n");
        else System.out.println("\n\n Has robado este tesoro: \n\n" + aTreasure.toString());
        break;
      case NextTurn:
        if (!game.nextTurn()) {
          System.out.println("\n\n ERROR \n");
          System.out.println("No cumples las condiciones para pasar de turno.");
          System.out.println("O bien tienes más de 4 tesoros ocultos");
          System.out.println("O bien te queda mal rollo por cumplir");
        } else {
          command = Command.NextTurnAllowed;
        }
        break;
    }
    return command;
  }