Exemplo n.º 1
0
        public void Play()
        {
            //reset
            if (_gameTimer != null && InitialPosition != null & InitialVelocity != null)
            {
                _gameTimer.Stop();
                IsGameRunning = false;
                CarFoundResults.Clear();
                _currentTickCount = 0;

                //start the game
                _gameTimer.Start();
                IsGameRunning = true;
            }
        }
Exemplo n.º 2
0
        private void TickEvent(object sender, EventArgs e)
        {
//            Console.WriteLine(e.SignalTime);
            lock (_lock)
            {
                _currentTickCount++;

                //move car forward
                MoveCar();

                //Call find car agents
                var results = _carFinderManager.CallAgents(_currentTickCount);

                results.ForEach(x =>
                {
                    if (x.IsCarFound)
                    {
                        CarFoundResults.Add(x);
                    }
                });

                // 1 millisecond = 10,000 ticks so 5000000 ticks = 500 milliseconds

                if (_currentTickCount >= 500 || CarFoundResults.Count == 2)
                {
                    //game ended
                    _gameTimer.Stop();
                    IsGameRunning = false;
                    foreach (var carFoundResult in results)
                    {
                        if (!carFoundResult.IsCarFound)
                        {
                            carFoundResult.Position     = null;
                            carFoundResult.CarFoundTime = null;
                        }
                        CarFoundResults.Add(carFoundResult);
                    }

                    //raise the game end event
                    OnGameEnd(new GameEndEventArgs()
                    {
                        CarFoundResults = CarFoundResults
                    });
                }
            }
        }