Advertisement
Kyle1264x

Untitled

Jun 11th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
  2. import java.util.Random;
  3. /**
  4.  * Write a description of class elephant here.
  5.  *
  6.  * @author (your name)
  7.  * @version (a version number or a date)
  8.  */
  9. public class elephant extends Actor
  10. {
  11.     /**
  12.      * Act - do whatever the elephant wants to do. This method is called whenever
  13.      * the 'Act' or 'Run' button gets pressed in the environment.
  14.      */
  15.    
  16.     GreenfootImage elephant = new GreenfootImage("elephant.jpg");
  17.     GreenfootImage hippo = new GreenfootImage("hippo.jpg");
  18.     int score = 0;
  19.     public void act()
  20.     {
  21.         image();
  22.        
  23.         if(Greenfoot.isKeyDown("a") && getImage().equals(elephant)){
  24.             score++;
  25.             setImage(hippo);
  26.         }
  27.         if(Greenfoot.isKeyDown("d") && getImage().equals(elephant)){
  28.             score++;
  29.             setImage(elephant);
  30.         }
  31.     }
  32.     public void image(){
  33.         Random rn = new Random();
  34.         int rn1 = rn.nextInt(2);
  35.        
  36.         if(rn1 == 1){
  37.             setImage(elephant);
  38.         }
  39.         if(rn1 == 0){
  40.             setImage(hippo);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement