////////////////////////////////////////////////////////////////////////////// /** * * First code entered into Car class - 9/14 lecture * * */ ////////////////////////////////////////////////////////////////////////////// import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Car here. * * @author (your name) * @version (a version number or a date) */ public class Car extends Vehicle { /** * Act - do whatever the Car wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { turn(14); } } ////////////////////////////////////////////////////////////////////////////// /** * * Second code entered into Car class - 9/14 lecture * Original turn method call commented out - replaced with call to move() * */ ////////////////////////////////////////////////////////////////////////////// import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Car here. * * @author (your name) * @version (a version number or a date) */ public class Car extends Vehicle { /** * Act - do whatever the Car wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //turn(14); move(); } } ////////////////////////////////////////////////////////////////////////////// /** * * Car class at the end of 9/16 lecture * Insertion of end of world test * Insertion of code for seeing other cars and reacting * */ ////////////////////////////////////////////////////////////////////////////// import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Car here. * * @author (your name) * @version (a version number or a date) */ public class Car extends Vehicle { /** * Act - do whatever the Car wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //turn(14); if(atWorldEdge()) { turn(-75); } if(canSee(Car.class)) { turn(34); } move(); } } ////////////////////////////////////////////////////////////////////////////// /** * * Car class at the end of 9/18 lecture * Insertion of random turning behavior * Start of breaking actions out into separate methods * */ ////////////////////////////////////////////////////////////////////////////// import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Car here. * * @author (your name) * @version (a version number or a date) */ public class Car extends Vehicle { /** * Act - do whatever the Car wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //turn(14); checkWorldEdge(); if(canSee(Car.class)) { turn(34); } if(Greenfoot.getRandomNumber(100) < 25) { turn(6); } if(Greenfoot.isKeyDown("s")) { //Greenfoot.delay(3); Greenfoot.stop(); } if(Greenfoot.isKeyDown("escape")) { turn(90); } move(); } public void checkWorldEdge() { if(atWorldEdge()) { turn(-75); } } }