Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
- import java.util.Random;
- /**
- * Write a description of class elephant here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class elephant extends Actor
- {
- /**
- * Act - do whatever the elephant wants to do. This method is called whenever
- * the 'Act' or 'Run' button gets pressed in the environment.
- */
- GreenfootImage elephant = new GreenfootImage("elephant.jpg");
- GreenfootImage hippo = new GreenfootImage("hippo.jpg");
- int score = 0;
- public void act()
- {
- image();
- if(Greenfoot.isKeyDown("a") && getImage().equals(elephant)){
- score++;
- setImage(hippo);
- }
- if(Greenfoot.isKeyDown("d") && getImage().equals(elephant)){
- score++;
- setImage(elephant);
- }
- }
- public void image(){
- Random rn = new Random();
- int rn1 = rn.nextInt(2);
- if(rn1 == 1){
- setImage(elephant);
- }
- if(rn1 == 0){
- setImage(hippo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement