Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/lib/gates/andGate.js
1039 views
1
/**
2
* Simulates an AND gate in JavaScript. As an io object this can be used to
3
* chain together logic operators and objects
4
*
5
* @author David North
6
*/
7
function andGate()
8
{
9
andGate.prototype.constructor.call(this);
10
11
/**
12
* Overrides the setState method of the parent so that the state may only
13
* be changed to true if all inputs are also set to true
14
*
15
* @param boolean state The state to attempt to change to
16
*
17
* @return andGate
18
*/
19
this.setState = function( state ){
20
state = true;
21
22
//Keep the state at true unless a false value is found
23
for( var i = 0; i < this.getInputs().length; i++ )
24
{
25
if ( !(this.getInputs()[i].getState()) )
26
{
27
state = false;
28
break;
29
}
30
}
31
32
//Update the state using the parent setState method
33
return andGate.prototype.setState.call(this, state);
34
}
35
}
36
37
//Set the parent of the andGate to io
38
include_once(['lib/io.js']);
39
andGate.prototype = new io();
40
41