Ejemplo n.º 1
0
  void waitForOtherPlayers() throws IOException {

    Global.log("Waiting for other players to register...");

    int n = Integer.parseInt(mainServer.readLine());
    playerNames = new String[n];

    for (int i = 0; i < n; ++i) {
      String info = mainServer.readLine();
      playerNames[i] = info;
    }

    // ping back to server for an OK
    mainServer.println();
    mainServer.flush();

    Global.log("List of Players:");
    for (int i = 0; i < n; ++i) Global.log("\t" + (i + 1) + ": " + playerNames[i]);

    // get player ID
    for (int i = 0; i < n; ++i) {
      if (name.equals(playerNames[i])) {
        playerID = i;
        break;
      }
    }

    Global.log("Player ID: " + (playerID + 1));
  }
Ejemplo n.º 2
0
  @Override
  public void startTheGame() {

    gameType = "";

    try {
      // receive ping from server
      gameType = mainServer.readLine();
    } catch (IOException ex) {
      System.err.println("Could not communicate with server: " + ex);
      Global.onException();
    }

    super.startTheGame();

    for (FixedTimer timer : timers) timer.start();

    startMarquee(getGameType(), 1000);
    startMarquee("3");
    startMarquee("2");
    startMarquee("1");

    // receive ping that the game is starting

    try {
      // ping back that client is ready
      mainServer.println();
      mainServer.flush();
      // wait for if server is ready
      mainServer.readLine();
    } catch (IOException ex) {
      System.err.println("Could not communicate with server: " + ex);
      Global.onException();
    }

    turnOnEndGameReceiver();
    startMarquee("START!");
  }
Ejemplo n.º 3
0
  void registerName() throws IOException, ClientNameException {

    // send name of player to main server
    Global.log("Sending player information [" + name + "]...");
    mainServer.out.println(name);
    mainServer.out.flush();
    Global.log("Checking if name already exists...");

    // check if registered
    String s = mainServer.readLine();
    if (!s.equals("OK")) {
      Global.log("Error! Name already exists. ClientNameException thrown.");
      throw new ClientNameException("Client name [" + name + "] already exists in server");
    }

    Global.log("Successfully registered as [" + name + "]");
  }