package turtleonestep;

/**
 * @author Burt Rosenberg
 * @version 12 June 2002
 * Copyright (c) 2002 Burt Rosenberg. All rights reserved
 */

import javax.swing.* ;
import java.awt.* ;

public class ModelView
extends JPanel {

   TurtleModel tm ;

   private static final int BODY_D = 7 ;
   private static final int HEAD_D = 3 ;
   private static final int TOTAL_D = BODY_D + HEAD_D ;

   ModelView( TurtleModel tm ) {
      this.tm = tm ;
   }

   public void paintComponent(Graphics gc) {
      super.paintComponent(gc) ;
      int x = tm.getX() ;
      int y = tm.getY() ;
      int d = tm.getDirection() ;
      gc.setColor( Color.green );
      gc.drawLine( x-TOTAL_D, y-TOTAL_D, x+TOTAL_D, y+TOTAL_D);
      gc.drawLine( x+TOTAL_D, y-TOTAL_D, x-TOTAL_D, y+TOTAL_D);
      gc.fillRect( x-BODY_D, y-BODY_D, 2*BODY_D, 2*BODY_D ) ;
      switch ( d ) {
         case 0: x += TOTAL_D ; break ;
         case 1: y -= TOTAL_D ; break ;
         case 2: x -= TOTAL_D ; break ;
         case 3: y += TOTAL_D ; break ;
      }
      gc.fillRect( x-HEAD_D, y-HEAD_D, 2*HEAD_D, 2*HEAD_D ) ;
   }

}
