コード例 #1
0
ファイル: Program.cs プロジェクト: bubish/NetduinoMemoryGame
        public static void Main()
        {
            var redControl =
                new ControlPair(
                    new InterruptPort(Pins.GPIO_PIN_D7, true, Port.ResistorMode.PullUp,
                                      Port.InterruptMode.InterruptEdgeBoth),
                    new OutputPort(Pins.GPIO_PIN_D13, false));
            var greenControl =
                new ControlPair(
                    new InterruptPort(Pins.GPIO_PIN_D3, true, Port.ResistorMode.PullUp,
                                      Port.InterruptMode.InterruptEdgeBoth),
                    new OutputPort(Pins.GPIO_PIN_D1, false));

            var controlPairs = new[] {redControl, greenControl};

            var noiseMaker = new NoiseMaker(PWMChannels.PWM_PIN_D9);

            try
            {
                var game = new Game(controlPairs, noiseMaker);

                while (game.IsRunning)
                {
                }

                controlPairs.ClearLeds();

                if (game.PlayerWon)
                {
                    greenControl.ShowLed();
                    noiseMaker.PlayWinningSound(250);
                }
                else
                {
                    redControl.ShowLed();
                    noiseMaker.PlaySadSound();
                }
            }
            catch (Exception)
            {
                new OutputPort(Pins.ONBOARD_LED, true).Write(true);
            }
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: bubish/NetduinoMemoryGame
        public Game(ControlPair[] controlPairs, NoiseMaker noiseMaker)
        {
            _controlPairs = controlPairs;
            _noiseMaker = noiseMaker;

            var random = new Random();

            for (var i = 0; i < _gameOrder.Length; i++)
            {
                var whichControl = random.Next(_controlPairs.Length);
                _gameOrder[i] = _controlPairs[whichControl].ButtonPin;
            }

            foreach (var controlPair in _controlPairs)
            {
                controlPair.Button.OnInterrupt += ButtonHandler;
            }

            Demonstrate();
        }