Subversion Repositories SoapBoxCore

Rev

Rev 8 | Rev 13 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 scott 1
#region "SoapBox.Demo License"
2
/// <header module="SoapBox.Demo"> 
3
/// Copyright (C) 2009 SoapBox Automation Inc., All Rights Reserved.
4
/// Contact: SoapBox Automation Licencing (license@soapboxautomation.com)
5
/// 
6
/// This file is part of SoapBox Demo.
7
/// 
8
/// GNU Lesser General Public License Usage
9
/// SoapBox Demo is free software: you can redistribute it and/or modify 
10
/// it under the terms of the GNU Lesser General Public License
11
/// as published by the Free Software Foundation, either version 3 of the
12
/// License, or (at your option) any later version.
13
/// 
14
/// SoapBox Demo is distributed in the hope that it will be useful, 
15
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
/// GNU Lesser General Public License for more details.
18
/// 
19
/// You should have received a copy of the GNU Lesser General Public License 
20
/// along with SoapBox Demo. If not, see <http://www.gnu.org/licenses/>.
21
/// </header>
22
#endregion
23
 
24
using System;
25
using System.Collections.Generic;
26
using System.Linq;
27
using System.Text;
28
using System.ComponentModel;
29
using SoapBox.Core;
30
 
31
namespace SoapBox.Demo.PinBall
32
{
33
    class PinBallStopController
34
    {
35
        public PinBallStopController(
12 scott 36
            PinBallTable table,
8 scott 37
            PinBallStop pinBallStop,
38
            PinBallCircularSensor ballPresentSensor,
39
            PinBallRectangularSensor launcherOccupiedSensor,
40
            PinBallRectangularSensor ballInPlaySensor)
41
        {
42
            if (table == null)
43
            {
44
                throw new ArgumentNullException("table");
45
            }
46
            if (pinBallStop == null)
47
            {
48
                throw new ArgumentNullException("pinBallStop");
49
            }
50
            if (ballPresentSensor == null)
51
            {
52
                throw new ArgumentNullException("ballPresentSensor");
53
            }
54
            if (launcherOccupiedSensor == null)
55
            {
56
                throw new ArgumentNullException("launcherOccupiedSensor");
57
            }
58
            if (ballInPlaySensor == null)
59
            {
60
                throw new ArgumentNullException("ballInPlaySensor");
61
            }
62
            m_table = table;
63
            m_pinBallStop = pinBallStop;
64
            m_ballPresentSensor = ballPresentSensor;
65
            m_launcherOccupiedSensor = launcherOccupiedSensor;
66
            m_ballInPlaySensor = ballInPlaySensor;
67
 
68
            ballPresentSensor.PropertyChanged +=
69
                new PropertyChangedEventHandler(sensors_PropertyChanged);
70
            launcherOccupiedSensor.PropertyChanged +=
71
                new PropertyChangedEventHandler(sensors_PropertyChanged);
72
            ballInPlaySensor.PropertyChanged +=
73
                new PropertyChangedEventHandler(sensors_PropertyChanged);
74
 
75
        }
12 scott 76
        private PinBallTable m_table = null;
8 scott 77
        private PinBallStop m_pinBallStop = null;
78
        private PinBallCircularSensor m_ballPresentSensor = null;
79
        private PinBallRectangularSensor m_launcherOccupiedSensor = null;
80
        private PinBallRectangularSensor m_ballInPlaySensor = null;
81
 
82
        void sensors_PropertyChanged(object sender, PropertyChangedEventArgs e)
83
        {
84
            if ((sender is PinBallRectangularSensor && e.PropertyName == m_RectangularSensor_ActiveName) &&
85
                (m_lastBallInPlayActive && !m_ballInPlaySensor.Active))
86
            {
87
                // falling edge of ball in play sensor, so decrement the ball count
88
                m_table.Balls--;
89
            }
90
            m_lastBallInPlayActive = m_ballInPlaySensor.Active;
91
 
92
            if ((sender is PinBallRectangularSensor && e.PropertyName == m_RectangularSensor_ActiveName) ||
93
                (sender is PinBallCircularSensor && e.PropertyName == m_CircularSensor_ActiveName) ||
12 scott 94
                (sender is PinBallTable && e.PropertyName == m_IPinBallTable_BallsName))
8 scott 95
            {
96
                m_pinBallStop.Release =
97
                    m_ballPresentSensor.Active
98
                    && !m_launcherOccupiedSensor.Active
99
                    && !m_ballInPlaySensor.Active
100
                    && (m_table.Balls > 0);
101
            }
102
        }
103
        private bool m_lastBallInPlayActive = false;
104
        static readonly string m_RectangularSensor_ActiveName =
105
            NotifyPropertyChangedHelper.GetPropertyName<PinBallRectangularSensor>(o => o.Active);
106
        static readonly string m_CircularSensor_ActiveName =
107
            NotifyPropertyChangedHelper.GetPropertyName<PinBallCircularSensor>(o => o.Active);
108
        static readonly string m_IPinBallTable_BallsName =
12 scott 109
            NotifyPropertyChangedHelper.GetPropertyName<PinBallTable>(o => o.Balls);
8 scott 110
    }
111
}