Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Reactor extends AbstractActor implements Switchable{
- private int temperature;
- private int damage;
- private Animation normalAnimation;
- private Animation hotAnimation;
- private Animation brokenAnimation;
- private Animation offAnimation;
- private boolean isRunning = false;
- private Light light;
- private String manufacturer;
- private int yearOfProduction;
- private List<EnergyConsumer> devices;
- private EnergyConsumer zariadenie;
- public Reactor() {
- this("TUKE", 1995);
- }
- public Reactor(String manufacturer, int yearOfProduction) {
- temperature = 0;
- damage = 0;
- offAnimation = new Animation("images/reactor.png",80,80,100);
- hotAnimation = new Animation ("images/reactor_hot.png", 80, 80, 100);
- hotAnimation.setPingPong(true);
- normalAnimation = new Animation ("images/reactor_on.png", 80, 80, 100);
- normalAnimation.setPingPong(true);
- brokenAnimation = new Animation ("images/reactor_broken.png",80,80,100);
- brokenAnimation.setPingPong(true);
- setAnimation(offAnimation);
- this.manufacturer = manufacturer;
- this.yearOfProduction = yearOfProduction;
- this.devices = new ArrayList<EnergyConsumer>();
- System.out.println(yearOfProduction);
- System.out.println(manufacturer);
- }
- public int getTemperature(){
- return temperature;
- }
- public int getDamage(){
- return damage;
- }
- public String setManufacturer() {
- return this.manufacturer;
- }
- public int setyearOfProduction() {
- return this.yearOfProduction;
- }
- public boolean isServiceNeeded(){
- if(temperature > 3000 && damage > 50){
- return true;
- }
- else return false;
- }
- public void increaseTemperature(int increment) {
- if (increment < 0){
- return;
- }
- if (increment >= 0 && isRunning) {
- if (damage < 33) {
- temperature = temperature + increment;
- } else if (damage >= 33 && damage < 66) {
- temperature = temperature + (increment *= 1.5);
- } else if (damage >= 66) {
- temperature = temperature + (increment * 2);
- }
- if (temperature >= 2000) {
- int d = (int) ((temperature - 2000) * 100 / 4000);
- damage = d > damage ? d : damage;
- if (damage > 100) {
- isRunning = false;
- damage = 100;
- }
- if (this.temperature >= 5000) {
- this.temperature = 5000;
- this.damage = 100;
- }
- }
- updateAnimation();
- }
- }
- public void decreaseTemperature(int decrement) {
- if (decrement < 0){
- return;
- }
- if(temperature > 0) {
- if (damage != 100 && isRunning) {
- if (damage >= 50) {
- temperature = temperature - (decrement *= 0.5);
- } else temperature -= decrement;
- updateAnimation();
- }
- }
- }
- private void updateAnimation(){
- if(isRunning && temperature < 4000){
- setAnimation(normalAnimation);
- }
- if (isRunning && temperature >= 4000){
- setAnimation(hotAnimation);
- }
- if(damage == 100 ) {
- setAnimation(brokenAnimation);
- }
- if(!isRunning)
- setAnimation(offAnimation);
- }
- public void repairWith(AbstractTool hammer){
- if(hammer.getPossibleUses() != 0){
- if(hammer != null && damage > 0 && damage < 100){
- if(damage >= 50){
- damage -= 50;
- temperature = 40 * damage + 2000;
- } else {
- int d = damage - 50;
- int t = 40 * d + 2000;
- temperature = t < temperature ? t : temperature;
- damage = 0;
- }
- hammer.use();
- updateAnimation();
- }
- }
- }
- public void turnOn(){
- this.isRunning = false;
- if(zariadenie != null){
- zariadenie.setElectricityFlow(false);
- }
- }
- public void turnOff() {
- this.isRunning = true;
- if(zariadenie != null){
- zariadenie.setElectricityFlow(true);
- }
- }
- public boolean isOn(){
- return isRunning;
- }
- public void addLight(Light light){
- if (light != null){
- this.light = light;
- if( this.damage < 100 && isOn() )
- this.light.setElectricityFlow(true);
- else
- this.light.setElectricityFlow(false);
- }
- }
- public void removeLight(){
- this.light.setElectricityFlow(false);
- this.light = null;
- }
- public void act(){
- if(damage != 100 && isRunning == true ){
- temperature = temperature + 1;
- }
- updateAnimation();
- increaseTemperature(0);
- }
- public void extinguishWith(AbstractTool tool) {
- if (this.damage == 100 && tool instanceof FireExtinguisher) {
- temperature=4000;
- tool.use();
- updateAnimation();
- }
- }
- public void addDevice(EnergyConsumer zariadenie) {
- this.devices.add(zariadenie);
- this.zariadenie = zariadenie;
- if (this.running == true) {
- for (int i = 0; i < this.devices.size(); i++) {
- this.devices.get(i).setElectricityFlow(true);
- }
- }
- }
- public void removeDevice(EnergyConsumer zariadenie) {
- if (devices.contains(zariadenie)) {
- zariadenie.setElectricityFlow(false);
- devices.remove(zariadenie);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement