/// <summary> /// Evaluates the logical result. /// </summary> /// <returns>The logical result of the whole circuit</returns> public override bool Evaluate() { try { Gate gateA = pins[0].InputWire.FromPin.Owner; if (gateA.Evaluate() == true) { _outputVoltage = true; } else { _outputVoltage = false; } return(gateA.Evaluate()); } catch { //Program catches if there is no wire connected to the pin, returning false and displaying an error message MessageBox.Show("There are no wires connected to the input pin(s)."); return(false); } }
/// <summary> /// Evaluates the logical result of the NOT Gate. /// </summary> /// <returns>The NOT result of the gate</returns> public override bool Evaluate() { try { Gate gate = pins[0].InputWire.FromPin.Owner; //Whatever the result of the gate is, return the NOT of it return(!gate.Evaluate()); } catch { //Program catches if there is no wire connected to the pin, returning false and throwing an exception MessageBox.Show("There are no wires connected to the input pin(s)."); return(false); } }
/// <summary> /// Computes the logical result of the Or Gate. /// If either pins evaluate true then the /// gate is true. /// </summary> /// <returns>The logical result</returns> public override bool Evaluate() { try { Gate gateA = pins[0].InputWire.FromPin.Owner; Gate gateB = pins[1].InputWire.FromPin.Owner; //One of the gates must be true for the OR Gate to return true return(gateA.Evaluate() || gateB.Evaluate()); } catch { //Program catches if there is no wire connected to the pin, returning false and throwing an exception MessageBox.Show("There are no wires connected to the input pin(s)."); return(false); } }
/// <summary> /// Computes the logical result of the And Gate. /// If both pins evaluate to true, then the whole /// gate is true. /// </summary> /// <returns>The logical result</returns> public override bool Evaluate() { try { //Set the Gates for the two input pins Gate gateA = pins[0].InputWire.FromPin.Owner; Gate gateB = pins[1].InputWire.FromPin.Owner; //Both gates must return a true value for the AND Gate to return true return(gateA.Evaluate() && gateB.Evaluate()); } catch { //Program catches if there is no wire connected to the pin, returning false and throwing an exception MessageBox.Show("There are no wires connected to the input pin(s)."); return(false); } }