/// <summary> /// Removes a particle from this shell /// </summary> /// <param name="particle">Particle to remove</param> /// <returns></returns> public bool RemoveParticle(Particle particle) { //make sure the particle is an electron and actually in this shell if (particles.Contains(particle)) { //remove particle from this layer Remove(particle); particle.transform.SetParent(null); FallUp(); return(true); } //not in shell, check the next one else if (NextShell != null) { //recursively check if particle in next shell if (NextShell.RemoveParticle(particle)) { //make sure there are electrons AND NOT (sBlock into dBlock OR pBlock into fBlock) if (ElectronCount > 0 && !((ElectronCount <= 2 && NextShell.pBlockFull) || (ElectronCount <= 8 && NextShell.dBlockFull))) { //replace the removed partcicle with one from this shell TransferParticle(this, NextShell); FallUp(); } return(true); } } return(false); }
/// <summary> /// Figures out where to Add a particle /// </summary> /// <param name="particle">Particle to be added</param> /// <returns>true if sucessfully added</returns> public bool AddParticle(Particle particle) { //0 recursively fill in electrons in PREVIOUS LEVEL that MUST be there if (NextShell) { if (!NextShell.pBlockFull) { return(NextShell.AddParticle(particle)); } } //1 Fill shell sBlock if (!sBlockFull) { Add(particle); return(true); } if (NextShell) { //2 Fill shell-2 fBlock if (NextShell.NextShell && !NextShell.NextShell.fBlockFull) { NextShell.NextShell.Add(particle); return(true); } //3 Fill shell-1 dBlock if (!NextShell.dBlockFull) { NextShell.Add(particle); return(true); } } //4 Fill shell blocks if (!pBlockFull) { Add(particle); return(true); } //No open place for electron return(false); }