JSFiddle - React, Tailwind, and code Playground
by holden321
JavaScript
class World {
constructor() {
}
createPowerPlant() {
let powerPlant = new PowerPlant();
return powerPlant;
}
createHousehold() {
let household = new Household();
return household;
}
connectHouseholdToPowerPlant(household, powerPlant) {
household.connectionToPowerPlant(powerPlant);
}
connectHouseholdToHousehold(household1, household2) {
if(household1.isConnected == true){
household2.isConnected = true;
household2.connectedToAnyHouseholds.push(household1)
}
else{
household2.isConnected = true;
household1.connectedToAnyHouseholds.push(household2);
}
}
disconnectHouseholdFromPowerPlant(household, powerPlant) {
household.disconnection(powerPlant);
}
killPowerPlant(powerPlant) {
powerPlant.changeKillStatus()
}
repairPowerPlant(powerPlant) {
powerPlant.repair()
}
householdHasEletricity(household) {
return household.checkConnection()
}
}
class Household{
constructor() {
this.isConnected = false;
this.connectedToPlants = [];
this.connectedToAnyHouseholds = [];
this.listOfKilledPlants = [];
}
connectionToPowerPlant(powerPlant){
this.connectedToPlants.push(powerPlant);
this.isConnected = true;
}
searchKillStatus(){
this.connectedToPlants.forEach((plant)=>{
if(plant.isKilled == true){
this.listOfKilledPlants.push(plant)
this.connectedToPlants.splice(plant, 1);
}
})
}
searchRepairStatus(){
this.listOfKilledPlants.forEach((plant)=>{
if(plant.isKilled == false){
this.connectedToPlants.push(plant)
this.listOfKilledPlants.splice(plant,1);
}
})
}
disconnection(powerPlant){
this.connectedToPlants.splice(powerPlant.nameOfPlant,1);
}
checkConnection(){
this.searchKillStatus();
this.searchRepairStatus();
if(this.connectedToPlants.length ==...