Exemplo n.º 1
0
  public boolean completeLogin(AuthRequest req, Player player) {
    // used custAuth or is remembered

    if (req.remember) {
      if (req.isValid()) {
        if (req.isGuest) {
          player.addTMessage(Color.GRAY, "Guestname remembered.");
          player.setGuest(true);
        } else {
          player.addTMessage(Color.GRAY, "Custom Authentication remembered.");
          player.setUsedAuthenticator(true);
          player.setGuest(false);
        }

        return player.setName(req.playerName);
      }
    } else {
      if (req.isValid()) {
        player.addTMessage(Color.GRAY, "Custom Authentication successfully completed.");
        player.setUsedAuthenticator(true);
        player.setGuest(false);
        return player.setName(req.playerName);
      } else {
        player.addTMessage(Color.RED, "Your custom Authentication expired. Please try again.");
      }
    }

    return false;
  }
Exemplo n.º 2
0
 @Test
 public void testNonNumericComparator() {
   Player p1 = beanFactory.createPlayer().as();
   p1.setName("aaa");
   Player p2 = beanFactory.createPlayer().as();
   p2.setName("zzz");
   Comparator<Player> desc = PlayerColumn.NAME.getComparator(false);
   Comparator<Player> asc = PlayerColumn.NAME.getComparator(true);
   assertComparators(p1, p2, desc, asc);
 }
Exemplo n.º 3
0
  @Override
  public void updatePlayers(List<PlayerInfo> players) {
    lock.writeLock().lock();
    try {
      if (players == null) {
        return;
      }
      Iterator<PlayerInfo> iterator = players.iterator();
      while (iterator.hasNext()) {
        Player player = iterator.next();
        if (player.getName() == null) {
          iterator.remove();
        }
      }

      if (this.players.size() != players.size()) {
        throw new IllegalArgumentException("Diff players count");
      }

      for (int index = 0; index < players.size(); index++) {
        Player playerToUpdate = this.players.get(index);
        Player newPlayer = players.get(index);

        playerToUpdate.setCallbackUrl(newPlayer.getCallbackUrl());
        playerToUpdate.setName(newPlayer.getName());
      }
    } finally {
      lock.writeLock().unlock();
    }
  }
Exemplo n.º 4
0
 /** Test of setName method, of class Player. */
 @Test
 public void testSetName() {
   System.out.println("setName");
   String name = "";
   Player instance = null;
   instance.setName(name);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
Exemplo n.º 5
0
  public void Start() {
    do {

      System.out.println("Enter name o player1");
      Scanner scan = new Scanner(System.in);
      player1.setName(scan.nextLine().toString());
      System.out.println("name:" + player1.getName());
    } while (player1.getName().trim().length() < 1);
    do {
      System.out.println("Enter name o player2");
      Scanner scan2 = new Scanner(System.in);
      player2.setName(scan2.nextLine().toString());
    } while (player2.getName().equals(player1.getName()) || player2.getName().trim().length() < 1);

    boolean good = false;
    do {
      if (good && initialchips < 3) {
        System.out.println("INFO:You have to start with at least 3 chips!");
      }
      if (good && initialchips % 2 == 0) {
        System.out.println("INFO:You have to start with an odd number of chips!");
      }
      System.out.println();
      System.out.println("How many chips does the initial pile contain?");
      Scanner scan3 = new Scanner(System.in);
      try {

        initialchips = Integer.parseInt(scan3.nextLine().trim());
        good = true;
      } catch (Exception e) {
        System.out.println("INFO:Should be an integer!");
        good = false;
      }

    } while (initialchips < 3 || initialchips % 2 == 0);

    do {
      printstate();
      getChips(turn);

    } while (initialchips > 0);
  }
Exemplo n.º 6
0
  // HOWTO
  @Override
  public String setPlayerNameAndAiType(int playerID, String clientName, Integer clientAiTypeId) {
    String playerName = getNextFreePlayerName(clientName, playerID);

    Player entity;
    switch (clientAiTypeId) {
      default:
      case 1:
        entity = new Player(playerID, clientName);
        break;
      case 2:
        entity = new AI_NoMover(playerID, clientName);
        break;
      case 3:
        entity = new AI_Random(playerID, clientName);
        break;
      case 4:
        entity = new AI_Puckie(playerID, clientName);
        break;
      case 5:
        entity = new AIstar(playerID, clientName);
        break;
      case 6:
        entity = new AI_Crasher(playerID, clientName);
        break;
      case 7:
        entity = new AI_Zigzag(playerID, clientName);
        break;
      case 8:
        entity = new AI_LimitedView_DriveSafe(playerID, clientName);
        break;
      case 9:
        entity = new AI_LimitedView_FastCorner(playerID, clientName);
        break;
      case 10:
        entity = new AI_LimitedView_FastTopmost(playerID, clientName);
        break;
      case 11:
        entity = new AI_LimitedView_SpeedUp(playerID, clientName);
        break;
      case 12:
        entity = new AI_Bipartite(playerID, clientName);
        break;
      case 13:
        entity = new AI_LimitedView_DriveCarefully(playerID, clientName);
        break;
        /* ADD YOUR NEW AI ALSO HERE */
    }
    // Player player=getPlayerMap().get(playerID);
    getPlayerMap().put(playerID, entity);
    entity.setName(playerName);

    return playerName;
  }
Exemplo n.º 7
0
  private void SetPlayerManager(JsonArray players, JsonObject turnTracker) {
    Player[] catanPlayers = new Player[players.size()];
    int longestRoad = turnTracker.getAsJsonPrimitive("longestRoad").getAsInt();
    int largestArmy = turnTracker.getAsJsonPrimitive("largestArmy").getAsInt();

    for (int i = 0; i < players.size(); i++) {
      if (!players.get(i).isJsonNull()) {
        JsonObject player = players.get(i).getAsJsonObject();
        int index = player.getAsJsonPrimitive("playerIndex").getAsInt();

        String name = player.getAsJsonPrimitive("name").getAsString();
        String color = player.getAsJsonPrimitive("color").getAsString();
        int playerId = player.getAsJsonPrimitive("playerID").getAsInt();
        int cities = player.getAsJsonPrimitive("cities").getAsInt();
        int settlements = player.getAsJsonPrimitive("settlements").getAsInt();
        int roads = player.getAsJsonPrimitive("roads").getAsInt();
        int victoryPoints = player.getAsJsonPrimitive("victoryPoints").getAsInt();

        Player newPlayer = new Player();
        newPlayer.setPoints(victoryPoints);
        try {
          newPlayer.setColor(color);
        } catch (InvalidColorException e) {
          e.printStackTrace();
        }
        if (longestRoad == index) {
          newPlayer.setLongestRoad(true);
        }
        if (largestArmy == index) {
          newPlayer.setLargestArmy(true);
        }

        newPlayer.setId(playerId);
        newPlayer.setCitiesRemaining(cities);
        newPlayer.setSettlementsRemaining(settlements);
        newPlayer.setRoadsRemaining(roads);
        newPlayer.setPlayerIndex(index);
        newPlayer.setName(name);

        // <========Construct part of player manager here============>
        catanPlayers[index] = newPlayer;
      }
    }
    // <========Construct player manager here============>
    PlayerManager newPlayerManager = new PlayerManager();
    newPlayerManager.setCatanPlayers(catanPlayers);
    newPlayerManager.setIndexOfLargestArmy(largestArmy);
    newPlayerManager.setIndexOfLongestRoad(longestRoad);

    this.playerManager = newPlayerManager;
  }
Exemplo n.º 8
0
  public void changePlayersNameByInterfaceCheck(Player p1) {

    if (this.status != LobbyStatus.WAITING && this.status != LobbyStatus.READY) {
      // name changes are only allowed as long as the game is not started
      // yet
      return;
    }

    for (Player p2 : this.players) {
      if (p1.getClientInterface() == p2.getClientInterface()) {
        Log.info("Lobby(" + this.id + "): Change name of " + p2 + " to " + p1.getName());
        p2.setName(p1.getName());
      }
    }
  }
Exemplo n.º 9
0
  /*
   * caricamento delle variabili secondo le impostazioni predefinite del file
   * di configurazione cfg presente nella cartella di installazione del gioco
   */
  public static void loadCfg(File cfg) {
    String tmp = new String();
    String cfr = new String();
    try {
      BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(cfg)));
      do {
        tmp = r.readLine();
        tmp = tmp.trim();
        if (tmp.startsWith("begin") || tmp.startsWith("//")) ;
        else {
          /* caso: giocatore singolo, viene inizializzato */
          cfr = "singlePlayer";
          if (tmp.startsWith(cfr)) {
            if (tmp.endsWith("= 1;")) {
              one.setHuman(true);
              two.setHuman(false);
            }
            if (tmp.endsWith("= 2;")) {
              one.setHuman(false);
              two.setHuman(true);
            }
          }

          /* caso: multigiocatore */
          cfr = "multiPlayer";
          if (tmp.startsWith(cfr) && tmp.endsWith("= 1;")) {
            one.setHuman(true);
            two.setHuman(true);
          }

          /*
           * abilita il gioco in rete cfr = "network";
           * if(tmp.startsWith(cfr) && tmp.endsWith("= 1;")) network =
           * true; else if(tmp.startsWith(cfr) &&
           * tmp.endsWith("= 0;")) network = false;
           */

          /* imposta il nome del giocatore 1 */
          cfr = "name1";
          if (tmp.startsWith(cfr)) {
            tmp = tmp.substring(tmp.indexOf("'") + 1, tmp.lastIndexOf("'"));
            one.setName(tmp);
          }

          /* imposta il nome del giocatore 2 */
          cfr = "name2";
          if (tmp.startsWith(cfr)) {
            tmp = tmp.substring(tmp.indexOf("'") + 1, tmp.lastIndexOf("'"));
            two.setName(tmp);
          }

          /* configura IP */
          cfr = "ip";
          if (tmp.startsWith(cfr)) {
            tmp = tmp.substring(tmp.indexOf("'") + 1, tmp.lastIndexOf("'"));
            hostName = new String(tmp);
          }

          /* configura colori */

          /* altre opzioni */
          cfr = "level";
          if (tmp.startsWith(cfr)) {
            if (tmp.endsWith("= 4;")) level = 4;
            else level = 6;
          }
        }
      } while (!tmp.equals("end"));
      r.close();
    } catch (Exception e) {
      System.err.println(e);
    }
  }
Exemplo n.º 10
0
 public Player withName(String value) {
   setName(value);
   return this;
 }
  public static void main(String[] args) {
    int num1 = 0, num2 = 0;

    Scanner input = new Scanner(System.in);
    System.out.print("\nPlease enter your first name: ");
    String playerName = input.nextLine();
    player_1.setName(playerName);

    System.out.print(
        "\n\n************************************************"
            + "*************************************\n");
    System.out.printf("Welcome %s! The rules for the game are:\n", player_1.getName());
    System.out.printf(
        "The game consists of four rounds of addition problems"
            + " randomly generated. Each time the \nproblem is answered correctly"
            + " you will receive 5 points and the difficulty level\nwill increase. "
            + "If the problem is answered incorrectly you will lose 5 points and "
            + "the\ndifficulty level will be reduced.");

    for (int round = 1; round <= 4; round++) {
      // Make sure level does not go below 1.
      player_1.setLevel((player_1.getLevel() < 1) ? 1 : player_1.getLevel());

      switch (player_1.getLevel()) {
        case 1:
          num1 = randomNumber(0, 9);
          num2 = randomNumber(0, 9);
          roundResult(num1, num2, round);
          break;

        case 2:
          num1 = randomNumber(10, 99);
          num2 = randomNumber(10, 99);
          roundResult(num1, num2, round);
          break;

        case 3:
          num1 = randomNumber(100, 999);
          num2 = randomNumber(100, 999);
          roundResult(num1, num2, round);
          break;

        case 4:
          num1 = randomNumber(1000, 9999);
          num2 = randomNumber(1000, 9999);
          roundResult(num1, num2, round);
          break;
        default:
      } // End of switch.
    } // End of for loop.

    System.out.printf(
        "\n\n***************************************************"
            + "****************\n************************** Final Results ********"
            + "******************\n");
    System.out.printf(
        "%s your final score is %d points and you answered %4.1f"
            + "%% of\nthe questions correctly.",
        player_1.getName(), score, (double) numCorrect / (numCorrect + numIncorrect) * 100.0);

    input.close();
    inputAnswer.close();
  } // ************** End of MAIN method ****************************
Exemplo n.º 12
0
 public void renamePlayer(Player player, String newName) {
   player.setName(newName);
 }