// joi/5/shapes/HLine.java
//
//
// Copyright 2003 Bill Campbell and Ethan Bolker


/**
 * An HLine is a horizontal Line.
 */

public class HLine extends Line
{
    /**
     * Construct an HLine having a paintChar and a length.
     *
     * @param length length in (character) pixels.
     * @param paintChar character used for painting this Line.
     */

    public HLine( int length, char paintChar )
    {
        super( length, paintChar );
    }

    /**
     * Paint this Line on Screen s at position (x,y).
     *
     * @param screen the Screen on which this Line is to be painted.
     * @param x      the x position for the line.
     * @param y      the y position for the line.
     */

    public void paintOn( Screen screen, int x, int y )
    {
        for ( int i = 0; i < length; i++ )
            screen.paintAt( paintChar, x+i, y );
    }

    /**
     * Unit test for class HLine. 
     */

    public static void main( String[] args )
    {
        Terminal terminal = new Terminal();

        terminal.println( "Self documenting unit test of HLine.");
        terminal.println( "The two Screens that follow should match.");
        terminal.println();
        terminal.println( "Hard coded picture:");
        terminal.println( "++++++++++++++++++++++");
        terminal.println( "+xxxxxxxxxx          +");
        terminal.println( "+xxxxx               +");
        terminal.println( "+                    +");
        terminal.println( "+   *****            +");
        terminal.println( "+    1               +");
        terminal.println( "+                    +");
        terminal.println( "++++++++++++++++++++++");
        terminal.println();

        terminal.println( "Picture drawn using HLine methods:");
        Screen screen = new Screen( 20, 6 );

        Line hline = new HLine( 10, 'x' );
        hline.paintOn( screen );

        hline.setLength(5); 
        hline.paintOn( screen, 0, 1 );  

        hline.setPaintChar('*');
        hline.paintOn( screen, 3, 3 );
        
        hline.setLength(1); 
        hline.setPaintChar('1');
        hline.paintOn( screen, 4, 4 );

        screen.draw( terminal );
    }

}
