Пример #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            player = new PlayerContext(Content, new Vector2(0, 0));

            // Initialize commands
            ICommand quitCommand      = new QuitCommand(this);
            ICommand moveLeftCommand  = new MoveLeftCommand(player);
            ICommand moveRightCommand = new MoveRightCommand(player);
            ICommand moveUpCommand    = new MoveUpCommand(player);
            ICommand moveDownCommand  = new MoveDownCommand(player);

            // Link keys to commands
            Dictionary <Keys, ICommand> keysMap = new Dictionary <Keys, ICommand>();

            keysMap.Add(Keys.Q, quitCommand);
            keysMap.Add(Keys.Left, moveLeftCommand);
            keysMap.Add(Keys.Right, moveRightCommand);
            keysMap.Add(Keys.Up, moveUpCommand);
            keysMap.Add(Keys.Down, moveDownCommand);
            //secondary commands for WASD
            keysMap.Add(Keys.W, moveUpCommand);
            keysMap.Add(Keys.A, moveLeftCommand);
            keysMap.Add(Keys.S, moveDownCommand);
            keysMap.Add(Keys.D, moveRightCommand);

            // Add controls to controller
            keyboardController = new KeyboardController(keysMap);

            base.Initialize();
        }
Пример #2
0
        public InteractiveConsole()
        {
            _commands              = new Dictionary <string, ICommand>();
            _commands["help"]      = new HelpCommand(this, _commands);
            _commands["magic"]     = new MagicCommand(this);
            _commands["aperft"]    = new AdvancedPerftCommand(this);
            _commands["dperft"]    = new DividedPerftCommand(this);
            _commands["perft"]     = new SimplePerftCommand(this);
            _commands["benchmark"] = new BenchmarkCommand(this);
            _commands["verify"]    = new VerifyCommand(this);
            _commands["evaluate"]  = new EvaluateCommand(this);
            _commands["tuner"]     = new TunerCommand(this);
            _commands["uci"]       = new UciCommand(this);
            _commands["quit"]      = new QuitCommand(this);

            _symbols = new List <string> {
                "%", "s", "ns", "MN/s", "ML/s"
            };

            _keywordColor = ConsoleColor.Cyan;
            _moveColor    = ConsoleColor.Red;
            _numberColor  = ConsoleColor.Yellow;
            _symbolColor  = ConsoleColor.Yellow;

            CultureInfo.CurrentCulture = new CultureInfo("en-US", false);
        }
Пример #3
0
 public void Init()
 {
     playerInput = new ParsedInput("quit", new ArrayList());
     thePlayer   = new Player("greg");
     handler     = new CommandHandler();
     quit        = new QuitCommand();
 }
Пример #4
0
        public void Test_Quit_TwoParameters_InvalidValueException()
        {
            var excelService = A.Fake <IExcelService>();

            var command = new QuitCommand(excelService);

            command.Execute(new string[] { "Q", "1" });
        }
Пример #5
0
        public void Test_Quit_Success()
        {
            var excelService = A.Fake <IExcelService>();

            var command = new QuitCommand(excelService);

            command.Execute(new string[] { "Q" });
        }
Пример #6
0
        public void When_passing_zero_arguments_to_quit_will_succeed()
        {
            var stream = new MemoryStream();
            var quit   = new QuitCommand(null);

            quit.SetContext(stream);
            Assert.IsTrue(quit.Init());
        }
Пример #7
0
        public static byte[] BuildQuitResponse(QuitCommand command)
        {
            if (command.NoReply == true)
            {
                return(null);
            }

            return(BuildResposne(command.Opcode, BinaryResponseStatus.no_error, command.Opaque, 0, null, null, null));
        }
Пример #8
0
        public void When_passing_arguments_to_quit_will_send_error()
        {
            var stream = new MemoryStream();
            var quit   = new QuitCommand(null);

            quit.SetContext(stream);

            quit.Init("foo");
            Assert.AreEqual("CLIENT_ERROR Quit accepts no paramters\r\n", ReadAll(stream));
        }
Пример #9
0
        public void When_calling_execute_will_call_action()
        {
            var  stream    = new MemoryStream();
            bool wasCalled = false;
            var  quit      = new QuitCommand(() => wasCalled = true);

            quit.SetContext(stream);
            quit.Execute();
            Assert.IsTrue(wasCalled);
        }
Пример #10
0
    void CreateCommands()
    {
        QuitCommand  quitc  = QuitCommand.CreateCommand();
        ItemList     listc  = ItemList.CreateCommand();
        HelpCommand  helpc  = HelpCommand.CreateCommand();
        ClearCommand clearc = new ClearCommand();

        Log(string.Format("A total of {0} commands exist.", CommandList.Keys.Count));
        Log("Type 'help' for more info.");
    }
Пример #11
0
        public void TestCase()
        {
            QuitCommand quit       = new QuitCommand();
            Player      testPlayer = new Player("James", "Deer hunter");

            Assert.AreEqual("Quitting", quit.Execute(testPlayer, new String[] { "quit" }));
            Assert.AreEqual("Quitting", quit.Execute(testPlayer, new String[] { "exit" }));

            Assert.AreEqual("I don't understand that", quit.Execute(testPlayer, new String[] { "wrongCommand" }));
        }
Пример #12
0
        public MainWindowViewModel()
        {
            PageUri   = new Uri("Pages/LogInPage.xaml", UriKind.Relative);
            IsWorking = false;

            LogInPageCommand         = new LogInPageCommand(this);
            WorkPageCommand          = new WorkPageCommand(this);
            AdministratorPageCommand = new AdministratorPageCommand(this);
            LogOutCommand            = new LogOutCommand(this);
            QuitCommand = new QuitCommand();
        }
        public void Execute_ShouldThrowQuitProgramException()
        {
            // Arrange
            var command = new QuitCommand();

            // Act
            Action action = () => command.Execute();

            // Assert
            action.Should().ThrowExactly <QuitProgramException>();
        }
Пример #14
0
        public void QuitValidator_Invalid_Type()
        {
            // arrange
            // act
            var spreadSheet = new SpreadSheet();
            var command     = new QuitCommand();
            var validator   = new PerformSumValidator();

            // assert
            Assert.ThrowsException <ArgumentException>(() => validator.Validate(spreadSheet, command));
        }
Пример #15
0
 protected override async void OnExecute(object parameter)
 {
     try
     {
         await QuitCommand.ExecuteAsync(this.shell);
     }
     catch (Exception e)
     {
         await AppMessageBox.ShowErrorAsync(e);
     }
 }
Пример #16
0
        private static ParseResult GetQuitParseResult()
        {
            var command   = new QuitCommand();
            var validator = new QuitValidator();

            return(new ParseResult
            {
                Command = command,
                Validator = validator,
            });
        }
        public void Run_SetsProgramStateExecution_ToFalse()
        {
            var state = new ProgramState {
                Executing = true
            };
            var command = new QuitCommand(state);

            command.Run(string.Empty);

            Assert.IsFalse(state.Executing);
        }
        public void Handles_DoesNotHandle_Null()
        {
            var state = new ProgramState {
                Executing = true
            };
            var command = new QuitCommand(state);

            var result = command.Handles(null);

            Assert.IsFalse(result);
        }
        public void Handles_HandlesQuitCommand_UpperCase()
        {
            var state = new ProgramState {
                Executing = true
            };
            var command = new QuitCommand(state);

            var result = command.Handles("QUIT");

            Assert.IsTrue(result);
        }
Пример #20
0
        public async Task QuitClosesConnectionAfterReply()
        {
            var channel = new MockSmtpChannel();
            var command = new QuitCommand(channel);

            command.Initialize("");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.Closing);
            Assert.True(channel.IsClosed);
        }
 private void InitCommands()
 {
     DragCommand             = new DragCommand(this);
     MinimizeCommand         = new MinimizeCommand(this);
     MaximizeCommand         = new MaximizeCommand(this);
     QuitCommand             = new QuitCommand(this);
     NewCommand              = new NewCommand(this);
     ExportCommand           = new ExportCommand(this);
     ChangeHeightCommand     = new ChangeHeightCommand(this);
     DetailResolutionCommand = new DetailResolutionCommand(this);
     HelpCommand             = new HelpCommand(this);
 }
Пример #22
0
        public void ExecuteCmd_Test()
        {
            Sheet       sheet = new Sheet();
            QuitCommand cmd   = new QuitCommand(sheet);

            bool result = cmd.AnalysisCmd("Q");

            Assert.AreEqual(result, true);

            result = cmd.ExecuteCmd();
            Assert.AreEqual(result, true);
        }
Пример #23
0
        public void QuitValidator()
        {
            // arrange
            var spreadSheet = new SpreadSheet();
            var command     = new QuitCommand();
            var validator   = new QuitValidator();

            // act
            validator.Validate(spreadSheet, command);

            // assert
            Assert.IsTrue(true);
        }
Пример #24
0
        public ICommand Build(string command)
        {
            string[] commandSplit = command?.Split(' ');

            ICommand createdCommand;

            switch (commandSplit[0])
            {
            case "/help":
            case "/h":
                createdCommand = new HelpCommand();
                break;

            case "/version":
            case "/v":
                createdCommand = new VersionCommand();
                break;

            case "/clear":
                createdCommand = new ClearCommand();
                break;

            case "/quit":
            case "/q":
                createdCommand = new QuitCommand();
                break;

            case "/post":
            case "/p":
                createdCommand = new PostCommand(commandSplit);
                break;

            case "/retrieve":
            case "/r":
                createdCommand = new RetrieveCommand(commandSplit);
                break;

            case "/settings":
                createdCommand = new SettingsCommand(commandSplit);
                break;

            default:
                createdCommand = new DefaultCommand();
                break;
            }

            return(createdCommand);
        }
Пример #25
0
        /// <summary>
        /// Creates the command.
        /// </summary>
        /// <param name="input">The input command.</param>
        /// <returns></returns>
        public static ICommand CreateCommand(string input)
        {
            ICommand command = null;

            try
            {
                var inputSplit = input.Split(' ');
                switch (inputSplit[0])
                {
                case "C":
                    command = new CanvasCommand(inputSplit[1], inputSplit[2]);
                    break;

                case "L":
                    command = new LineCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "R":
                    command = new RectCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "B":
                    command = new FillCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3]);
                    break;

                case "Q":
                    command = new QuitCommand();
                    break;

                default:
                    break;
                }

                if (command != null && !command.IsValid)
                {
                    command = null;
                }
            }
            catch (System.Exception)
            {
                command = null;
            }
            return(command);
        }
Пример #26
0
        public void AnalysisCmdAnalysisCmd_Test()
        {
            Sheet       sheet = new Sheet();
            QuitCommand cmd   = new QuitCommand(sheet);

            bool result = cmd.AnalysisCmd("Qtt 1");

            Assert.AreEqual(result, false);

            result = cmd.AnalysisCmd("N 1 1");
            Assert.AreEqual(result, false);

            result = cmd.AnalysisCmd("Q");
            Assert.AreEqual(result, true);

            Console.WriteLine("Test Complete");
        }
        public StregsystemController()
        {
            StatusCommands     MakeAktive       = new StatusCommands(Aktivate);
            StatusCommands     MakeDeactivacted = new StatusCommands(Deactivate);
            QuitCommand        Quit             = new QuitCommand(CLI.Close);
            CreditCommands     MakeCreditOn     = new CreditCommands(CreaditOn);
            CreditCommands     MakeCreditOff    = new CreditCommands(CreditOff);
            AddCreditsCommands AddCredits       = new AddCreditsCommands(sSystem.AddCreditsToAccount);

            _adminCommands.Add(":activate", MakeAktive);
            _adminCommands.Add(":deactivate", MakeDeactivacted);
            _adminCommands.Add(":quit", Quit);
            _adminCommands.Add(":q", Quit);
            _adminCommands.Add(":crediton", MakeCreditOn);
            _adminCommands.Add(":creditoff", MakeCreditOff);
            _adminCommands.Add(":addcredits", AddCredits);
        }
Пример #28
0
        public ICommand Build(string command)
        {
            string[] commandSplit = command?.Split(' ');

            ICommand createdCommand;

            switch (commandSplit[0])
            {
            case "/help":
            case "/h":
                createdCommand = new HelpCommand();
                break;

            case "/version":
            case "/v":
                createdCommand = new VersionCommand();
                break;

            case "/clear":
            case "/c":
                createdCommand = new ClearCommand();
                break;

            case "/quit":
            case "/q":
                createdCommand = new QuitCommand();
                break;

            case "/list":
            case "/l":
                createdCommand = new ListCommand();
                break;

            case "/run":
            case "/r":
                createdCommand = new RunCommand(commandSplit);
                break;

            default:
                createdCommand = new DefaultCommand();
                break;
            }

            return(createdCommand);
        }
Пример #29
0
        private void OnMainFormClosing(CancelEventArgs args)
        {
            var quit = DialogResult.Yes;

            // show msgbox if connected to a host
            if (ToolboxApp.SocketManager.IsConnected)
            {
                quit = QuitCommand.ShowPrompt();
            }

            // quit
            if (quit == DialogResult.Yes)
            {
                ToolboxApp.AppEvents.ApplicationCleanUp();
            }
            else
            {
                args.Cancel = true;
            }
        }
        public void QuitCommand_Successful()
        {
            var expectedInterface = new Helpers.TestUserInterface(
                new List <Tuple <string, string> >(), // ReadValue()
                new List <string>                     // WriteMessage()
            {
                "Thank you for using FlixOne Inventory Management System"
            },
                new List <string>() // WriteWarning()
                );

            // create an instance of the command
            var command = new QuitCommand(expectedInterface);

            // add a new book with parameter "name"
            var result = command.RunCommand();

            expectedInterface.Validate();

            Assert.IsTrue(result.shouldQuit, "Quit is a terminating command.");
            Assert.IsTrue(result.wasSuccessful, "Quit did not complete Successfully.");
        }