예제 #1
0
        public String getXMLString()
        {
            String result = "<gamePacket type=\"" + type;

            switch (type)
            {
            case TYPE.GAME_RESULT:
                result += "\">" + GameResult.ToXMLString(gameResult);
                break;

            case TYPE.RESULT:
                result += "\">" + ShotResult.ToXMLString(shotResult);
                break;

            case TYPE.SHOT:
                result += "\">" + Coordinates.ToXMLString(coordinates);
                break;

            case TYPE.TEXT_MESSAGE:
                result += "\" message=\"" + message + "\"/>";
                return(result);

            case TYPE.WHO_STARTS:
                result += "\" whoStarts=\"" + (whoStarts == Global.HOST_FIRST ? "host" : "client") + "\"/>";
                return(result);

            default:
                result += "\"/>";
                return(result);
            }

            result += "</gamePacket>";

            return(result);
        }
예제 #2
0
        public static String ToXMLString(ShotResult shotResult)
        {
            String result = "<shotResult isNull=\"";

            if (shotResult == null)
            {
                result += "true\"";
            }
            else
            {
                result += "false\"";
                result += " isHit=\"" + (shotResult.isHit() ? "true" : "false") + "\"";
                result += " isSunk=\"" + (shotResult.isSunk() ? "true" : "false") + "\"";
                result += " isGameEnded=\"" + (shotResult.isGameEnded() ? "true" : "false") + "\"";
                result += " matrix=\"";
                result += ((shotResult.getMatrix() == null) ? "null" : Global.boolArrayToString(shotResult.getMatrix())) + "\"";
            }

            result += ">" + Coordinates.ToXMLString(shotResult.getCoordinates()) + "</shotResult>";
            return(result);
        }