コード例 #1
0
 private void PlugButton_Click(object sender, EventArgs e)
 {
     PlugButton pButton = (PlugButton)sender;
     if (this.activatedPlug == null)
     {
         if (!pButton.IsPlugged)
         {
             pButton.Activate();
             this.activatedPlug = pButton;
         }
         else
         {
             int index1=this.IndexOfPlug(pButton);
             int index2;
             this.plugboard.MutateSignal(index1, out index2);
             Debug.Assert(index1 != index2);
             this.plugboard.UnPlug(index1, index2);
             this.ShowPlugs();
         }
     }
     else if (this.activatedPlug==pButton)
     {
         pButton.Deactivate();
         this.activatedPlug = null;
     }
     else if (!pButton.IsPlugged)
     {
         int index1=this.IndexOfPlug(pButton);
         int index2=this.IndexOfPlug(this.activatedPlug);
         this.plugboard.Plug(index1, index2);
         this.activatedPlug = null;
         this.ShowPlugs();
     }
     else if (pButton.IsPlugged)
     {
         return;
     }
 }
コード例 #2
0
 private int IndexOfPlug(PlugButton pButton)
 {
     return Array.FindIndex<PlugButton>(this.plugButtons, btn => btn == pButton);
 }