public static void encode( Game game, Writer out )
public static void encode( IGame game, Writer out )
    public static void encode( Game game, Writer out )        throws IOException    {        Enumeration iter; // used when marching through a list of sub-elements        Coords coords;        int loop;        // First, validate our input.        if ( null == game ) {            throw new IllegalArgumentException( "The game is null." );        }        if ( null == out ) {            throw new IllegalArgumentException( "The writer is null." );        }        // Start the XML stream for this game.        out.write( "<game version=\"1.0\">" );        // Encode the game options.        if ( null != game.getOptions() ) {            GameOptionsEncoder.encode( game.getOptions(), out );        }        // Encode the board.        if ( null != game.getBoard() ) {            BoardEncoder.encode( game.getBoard(), out );        }        // Encode the minefields.        iter = game.getMinedCoords();        if ( iter.hasMoreElements() ) {            out.write( "<minefields>" );            while ( iter.hasMoreElements() ) {                coords = (Coords) iter.nextElement();                Enumeration fields = game.getMinefields( coords ).elements();                while ( fields.hasMoreElements() ) {                    MinefieldEncoder.encode( (Minefield) fields.nextElement(),                                             out );                }            }            out.write( "</minefields>" );        }        // Encode the players.        iter = game.getPlayers();        if ( iter.hasMoreElements() ) {            out.write( "<players>" );            while ( iter.hasMoreElements() ) {                PlayerEncoder.encode( (Player) iter.nextElement(), out );            }            out.write( "</players>" );        }        // Encode the teams.        iter = game.getTeams();        if ( iter.hasMoreElements() ) {            out.write( "<teams>" );            while ( iter.hasMoreElements() ) {                TeamEncoder.encode( (Team) iter.nextElement(), out );            }            out.write( "</teams>" );        }        // Encode the in-game entities.        iter = game.getEntities();        if ( iter.hasMoreElements() ) {            out.write( "<entities set=\"IN-GAME\">" );            while ( iter.hasMoreElements() ) {                EntityEncoder.encode( (Entity) iter.nextElement(), out );            }            out.write( "</entities>" );        }        // Encode the out-of-game entities.        iter = game.getOutOfGameEntitiesVector().elements();        if ( iter.hasMoreElements() ) {            out.write( "<entities set=\"OUT-GAME\">" );            while ( iter.hasMoreElements() ) {                EntityEncoder.encode( (Entity) iter.nextElement(), out );            }            out.write( "</entities>" );        }        // Encode the game turns.        iter = game.getTurns();        if ( iter.hasMoreElements() ) {            out.write( "<turns>" );            while ( iter.hasMoreElements() ) {                GameTurnEncoder.encode( (GameTurn) iter.nextElement(), out );            }            out.write( "</turns>" );        }        // Encode the actions.        iter = game.getActions();        if ( iter.hasMoreElements() ) {            out.write( "<actions>" );            while ( iter.hasMoreElements() ) {                EntityActionEncoder.encode( (EntityAction) iter.nextElement(),                                            out );            }            out.write( "</actions>" );        }        // Encode the PSRs.        iter = game.getPSRs();        if ( iter.hasMoreElements() ) {            out.write( "<PSRs>" );            while ( iter.hasMoreElements() ) {                PilotingRollDataEncoder.encode( (PilotingRollData) iter.nextElement(),                                            out );            }            out.write( "</PSRs>" );        }        // Encode the game's data.        out.write( "<gameData " );        out.write( "windDirection=\"" );        out.write( game.getWindDirection() );        out.write( "\" roundCount=\"" );        out.write( game.getRoundCount() );        out.write( "\" phase=\"" );        out.write( game.getPhase() );        out.write( "\" lastPhase=\"" );        out.write( game.getLastPhase() );        out.write( "\" forceVictory=\"" );        out.write( game.isForceVictory() ? "true" : "false" );        out.write( "\" victoryPlayerId=\"" );        out.write( game.getVictoryPlayerId() );        out.write( "\" victoryTeam=\"" );        out.write( game.getVictoryTeam() );        out.write( "\" mechInFirst=\"" );        out.write( game.getMechInFirst() ? "true" : "false" );        out.write( "\" mechInSecond=\"" );        out.write( game.getMechInSecond() ? "true" : "false" );        out.write( "\" />" );        // Finish the XML stream for this game.        out.write( "</game>" );    }