Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package sk.tuke.oop.aliens;
  7.  
  8. import sk.tuke.oop.aliens.actor.AbstractActor;
  9. import sk.tuke.oop.framework.Animation;
  10.  
  11.  
  12.  
  13. /**
  14. *
  15. * @author Matus
  16. */
  17. public class Light extends AbstractActor implements Switchable,EnergyConsumer{
  18.  
  19. private Animation animationOff,animationOn;
  20.  
  21. private boolean lightIsOn;
  22. private boolean powered;
  23.  
  24. @Override
  25. public void setElectricityFlow(boolean set)
  26. {
  27. this.powered=set;
  28. this.updateStatus();
  29. }
  30.  
  31.  
  32. public boolean isPowered()
  33. {
  34. return this.powered;
  35. }
  36.  
  37. @Override
  38. public boolean isOn()
  39. {
  40. return this.lightIsOn;
  41. }
  42.  
  43. @Override
  44. public void on()
  45. {
  46. this.lightIsOn=true;
  47. this.updateStatus();
  48. }
  49.  
  50. @Override
  51. public void off()
  52. {
  53. this.lightIsOn=false;
  54. this.updateStatus();
  55. }
  56.  
  57. public void toggle()
  58. {
  59. if(this.powered==false) return;
  60. this.lightIsOn=!this.lightIsOn;
  61.  
  62. this.updateStatus();
  63. }
  64.  
  65.  
  66. public void updateStatus()
  67. {
  68. if(!this.powered)
  69. {
  70. setAnimation(this.animationOff);
  71. }else{
  72. if(this.lightIsOn) setAnimation(this.animationOn);
  73. else setAnimation(this.animationOff);
  74. }
  75. }
  76.  
  77. public Light()
  78. {
  79. this.powered=false;
  80. this.lightIsOn=false;
  81. this.animationOn=new Animation("resources/images/light_on.png",16,16,10);
  82. this.animationOff=new Animation("resources/images/light_off.png",16,16,10);
  83. setAnimation(this.animationOff);
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement