Beispiel #1
0
        static void Main(string[] args)
        {
            Terminal.Open();
            Terminal.Set(string.Format("window.title='{0}'", "SharpSnake"));
            Terminal.Refresh();

            var consoleScreen = new ConsoleScreen(36, 28);
            var context       = new StateContext(consoleScreen, new Settings());
            var stateStack    = new StateStack(context);

            stateStack.RegisterState <MenuState>(StateId.Menu);
            stateStack.RegisterState <OptionsState>(StateId.Options);
            stateStack.RegisterState <PlayState>(StateId.Play);
            stateStack.RegisterState <GameOverState>(StateId.GameOver);
            stateStack.RegisterState <PauseState>(StateId.Pause);

            // Initial state
            stateStack.PushState(StateId.Menu);

            while (!stateStack.Empty)
            {
                stateStack.HandleInput();
                stateStack.Update();

                consoleScreen.Clear();
                stateStack.Draw();
                consoleScreen.Display();

                System.Threading.Thread.Sleep(16);
            }

            Terminal.Close();
        }
Beispiel #2
0
            /// <summary>
            ///   Adds the states stored in the <see cref="_transitions" /> cache.
            /// </summary>
            private void AddStates()
            {
                if (_transitions.Count == 0)
                {
                    throw new InvalidOperationException("Deadlock detected.");
                }

                var transitionCount = 0;

                _stateStack.PushFrame();

                for (var i = 0; i < _transitions.Count; ++i)
                {
                    var transition = _transitions[i];
                    if (!transition->IsValid)
                    {
                        continue;
                    }

                    // Store the state if it hasn't been discovered before
                    int index;
                    if (_states.AddState(transition->TargetState, out index))
                    {
                        Interlocked.Increment(ref _context._stateCount);
                        _stateStack.PushState(index);
                    }

                    // Check if the invariant is violated; if so, generate a counter example and abort
                    if (!transition->Formulas[0])
                    {
                        _context._loadBalancer.Terminate();
                        CreateCounterExample(endsWithException: false);

                        return;
                    }

                    ++transitionCount;
                }

                Interlocked.Add(ref _context._transitionCount, transitionCount);
                Interlocked.Add(ref _context._computedTransitionCount, _transitions.ComputedTransitionCount);
            }