tags:

views:

32

answers:

1

Hi, i'm trying to change a Skor4 game (feor two players) into tic tac toe. The problem is that in the source code that im trying to change sends only the x dimension of the ball to the server and then the other player takes that x dimension and finds the y dimension. In my case i want to send both x and y dimension. How can i do this??

when a player plays:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;

here is the sendMove:

public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}

here is send:

public void send(String s) {
  outStream.println(s);
}

After that the other player receives the move:

int istatus = connection.getTheirMove();

here is getTheirMove:

public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }

here is receive:

public String receive() throws IOException {
    return inStream.readLine();
}
+1  A: 

So why not send

  String coord =  x + "," + y;

and split the x and y coordinates using String.split() ? That would give you an array of two strings - the x and the y.

Going further, you may want to send (say) something to identify what your message is, followed by the data. And then use a similar method to unambiguously split up the data. e.g. messages could look like:

COORD:x,y
STATUS: message

etc.

Brian Agnew
thanksssss..i solved my problem using your help...thanks a lot
Danah