import chess.Chess;
import chess.Screen;
import chess.Sprite;
import chess.Turtle;
import java.awt.Color;

public class TurtleRobot {
    
    public static void main(String[] args) {
        /* here you go */
        
        Screen g= Chess.newScreen(800,800);
        
        Turtle tim= g.newTurtle();
        tim.hide();
        tim.ultraFast();
        
        int jointOneAngle= 45;
        int jointTwoAngle= -90;
        int jointThreeAngle= 0;
        
        boolean haveObject=false;
        
        Sprite object= g.newSprite("/sprites/miniCooper.png");
        object.setPosition(60,90);        
        
        while ( true ) {
            g.clear( Color.white );            
            g.drawString( "k/l base; a/s elbow; j/n wrist; space pickup and release", 0, 20 );
        
            tim.home();  // reset orientation
            tim.setPosition(400,400);
            
            tim.right(jointOneAngle);
            tim.setLineWidth(10);
            tim.forward(300);
            tim.left(jointTwoAngle);
            tim.setLineWidth(7);
            tim.forward(250);
            tim.left(jointThreeAngle);
            tim.setLineWidth(4);
            tim.forward(50);
            if ( haveObject ) {
                object.setPosition( tim.getPositionX(), tim.getPositionY() );
                object.setOrientation( tim.getOrientation() );
            }
            
            int key=0;
            while ( key==0 ) key=g.getKey();
            if ( key=='a' ) {
                jointTwoAngle= jointTwoAngle-2;
            } else if ( key=='s') {
                jointTwoAngle= jointTwoAngle+2;                
            } else if ( key=='k') {
                jointOneAngle= jointOneAngle-2;                
            } else if ( key=='l') {
                jointOneAngle= jointOneAngle+2;                
            } else if ( key=='j') {
                jointThreeAngle= jointThreeAngle-5;                
            } else if ( key=='n') {
                jointThreeAngle= jointThreeAngle+5;                
            } else if ( key==' ' ) {
                if ( haveObject ) {
                    // drop the object
                    haveObject=false;
                } else {
                    object= g.getSpriteAt( tim.getPositionX(), tim.getPositionY() );
                    if ( object!=null ) {
                        haveObject= true;
                    }
                }
            }

        }
        
        
        
        
        /* two braces below */
    }
    
}
