JSFiddle - React, Tailwind, and code Playground

by Danny Michaelis

JavaScript

class Planet {
  constructor( id, productionCount = 10, shipAmmount = 10, divisor = 1 ) {
		this.id	= id;    
		this.productionCount = productionCount;
    this.shipAmmount = shipAmmount;
    this.divisor = divisor;
    this.squads = this.devide_ships();
    return this;
  }
  
  update_divisor( newDivisor ) {
  	this.divisor = newDivisor;
    devide_ships();
    return this;
  }
  
  devide_ships( divisor = this.divisor) {
  	const flatSquad = [].concat( ...this.squads );
    this.squads = [];
    while (a.length > 0) {
      this.squads.push( flatSquad.splice( 0, size ) );
    }
    return this;
  }
  
  order_squads( numberOfSquads, target ) {
  	 const attackingSquads = this.squads.splice( 0, numberOfSquads )
     target.attack( attackingSquads )
     return this;
  }
  
  attack( attackingSquads ) {
  	const defenderCount = 0;
    while( this.squads.length > 0 && attackingSquads > 0 ) {
      	const attackingSquad = attackingSquads.shift();
	    	const defendingSquad = this.squads.shift();
        defenderCount += attackingSquad - defendingSquad;
    }
    if ( attackingSquad.length > 0 ) {
    
    }
  }
}