Advertisement
Guest User

Light

a guest
Oct 28th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package sk.tuke.oop.aliens;
  2.  
  3. import sk.tuke.oop.aliens.actor.AbstractActor;
  4. import sk.tuke.oop.framework.Animation;
  5.  
  6. /**
  7.  * Created by mirco on 06.10.2016.
  8.  */
  9. public class Light extends AbstractActor implements Switchable, EnergyConsumer {
  10.     private Animation lightOn;
  11.     private Animation lightOff;
  12.     private boolean isPowered;
  13.     private boolean on;
  14.  
  15.     public Light(){
  16.         lightOn = new Animation("resources/images/light_on.png", 16, 16, 10);
  17.         lightOff = new Animation("resources/images/light_off.png", 16, 16, 10);
  18.         setAnimation(lightOff);
  19.         on = false;
  20.     }
  21.  
  22.     public void toggle(){
  23.         if(this.on = !this.on){
  24.             updateAnimation();
  25.         }
  26.     }
  27.  
  28.     /*public void toggle(){
  29.         if(this.on){
  30.             on = true;
  31.             if(this.isPowered=true){
  32.                 setAnimation(lightOn);
  33.             }
  34.         }
  35.         else
  36.             setAnimation(lightOff);
  37.         updateAnimation();
  38.     }*/
  39.  
  40.     public void setElectricityFlow(boolean power){
  41.         isPowered = power;
  42.         updateAnimation();
  43.     }
  44.  
  45.  
  46.     public void turnOn(){
  47.         on = true;
  48.         updateAnimation();
  49.     }
  50.  
  51.     public void turnOff(){
  52.         on = false;
  53.         updateAnimation();
  54.     }
  55.  
  56.     public boolean isOn(){
  57.         return on;
  58.     }
  59.  
  60.  
  61.     public void updateAnimation(){
  62.         if(isOn() && isPowered)
  63.             setAnimation(lightOn);
  64.         else
  65.             setAnimation(lightOff);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement