Exemple #1
0
        /// <summary>
        /// Sanitizes data provided by the client and passes it to the clients ship to be processed in the next frame.
        /// </summary>
        /// <param name="shipID"></param>
        /// <param name="userInput"></param>
        private void ProcessUserInput(int shipID, string userInput)
        {
            Ship   currentShip   = (Ship)theWorld.getPlayers()[shipID];
            string commandString = "";

            // Normalize user input.
            if (userInput.Contains("L"))
            {
                commandString += "L";
            }
            if (userInput.Contains("R"))
            {
                commandString += "R";
            }
            if (userInput.Contains("F"))
            {
                commandString += "F";
            }
            if (userInput.Contains("T"))
            {
                commandString += "T";
            }

            // Used for preventing dead ships from receiving user input
            if (currentShip != null)
            {
                currentShip.queueCommands(commandString);
            }
        }
        public void TestShipProcessingCommands()
        {
            World    testWorld = new World();
            Vector2D shipLoc   = new Vector2D(0, 0);

            Ship test1 = new Ship(1, shipLoc, shipLoc, false, "testName", 5, 0);

            test1.queueCommands("TL");
            Assert.AreEqual("TL", test1.GetCommands());
            test1.ProcessCommands();
            test1.queueCommands("RT");
            Assert.AreEqual("RT", test1.GetCommands());
            test1.ProcessCommands();
            test1.queueCommands("F");
            Assert.AreEqual("F", test1.GetCommands());
            test1.ProcessCommands();

            testWorld.updateShips();
        }