Path: blob/main/public/games/files/algaes-escapade/js/lib/gates/andGate.js
1039 views
/**1* Simulates an AND gate in JavaScript. As an io object this can be used to2* chain together logic operators and objects3*4* @author David North5*/6function andGate()7{8andGate.prototype.constructor.call(this);910/**11* Overrides the setState method of the parent so that the state may only12* be changed to true if all inputs are also set to true13*14* @param boolean state The state to attempt to change to15*16* @return andGate17*/18this.setState = function( state ){19state = true;2021//Keep the state at true unless a false value is found22for( var i = 0; i < this.getInputs().length; i++ )23{24if ( !(this.getInputs()[i].getState()) )25{26state = false;27break;28}29}3031//Update the state using the parent setState method32return andGate.prototype.setState.call(this, state);33}34}3536//Set the parent of the andGate to io37include_once(['lib/io.js']);38andGate.prototype = new io();394041