public boolean connectToServer(String myTeam, String myName, String myOtherName) { cc = new CommClient("gs5038.sp.cs.cmu.edu"); connectedToServer = false; m_myName = "GC4" + myName; m_serverName = "GameServerForTeam" + myTeam; String myFriends[] = {m_serverName, "GC4" + myOtherName}; // System.out.printf("GameClient: myname = \"%s\", friend1 = \"%s\", friend2 = \"%s\"\n", // m_myName, myFriends[0], myFriends[1]); // try to connect to server try { cc.connectToFriends(m_myName, myFriends); } catch (CommException e) { /* if (e.getMessage().startsWith("missing-friends")) { System.err.println("GameClient Unable to find friend: " + e.getMessage()); return false; } */ // Wait until all friends connect. boolean friendsReady = false; while (!friendsReady) { try { Thread.sleep(1000); } catch (Exception e2) { } try { cc.getIncomingMessage(); } catch (CommException e1) { if (e1.getMessage().startsWith("friends-ready")) friendsReady = true; // else // System.err.println("GameClient Giving up"); // return false; } } } connectedToServer = true; return true; }
/** indicate a filled drop to the gameServer */ public void fillDrop(int mazeX, int mazeY, MazeWorld.Direction dir) { if (!connectedToServer) return; String dropString = "FILLDROP " + m_myName + " " + mazeX + " " + mazeY + " " + dir; cc.send(m_serverName, dropString); }
/** indicate a removed gold to the gameServer */ public void removeGold(int mazeX, int mazeY, MazeWorld.Direction dir) { if (!connectedToServer) return; String goldString = "RMGOLD " + m_myName + " " + mazeX + " " + mazeY + " " + dir; cc.send(m_serverName, goldString); }
/** indicate a removed wall to the gameServer */ public void removeWall(int mazeX, int mazeY, MazeWorld.Direction dir) { if (!connectedToServer) return; String wallString = "RMWALL " + m_myName + " " + mazeX + " " + mazeY + " " + dir; cc.send(m_serverName, wallString); }
/** * send a goal to the gameServer * * @param pose 2-D continuous pose in same convention as used by MazeGraphics */ public void setGoal(RealPose2D pose) { if (!connectedToServer) return; String goalString = "GOAL " + m_myName + " " + pose.getX() + " " + pose.getY() + " " + pose.getTh(); cc.send(m_serverName, goalString); }
/** * Send the pose to the gameServer * * @param pose 2-D continuous pose in same convention as used by MazeGraphics */ public void setPose(RealPose2D pose) { if (!connectedToServer) return; String poseString = "POSE " + m_myName + " " + pose.getX() + " " + pose.getY() + " " + pose.getTh(); cc.send(m_serverName, poseString); }