Ejemplo n.º 1
0
 /// <summary>
 /// Updates the command for a specific player to be send to the client
 /// </summary>
 /// <param name="ID"> The ID of the player command </param>
 /// <param name="c"> Given Control Command to be given to PlayerCommands </param>
 public void UpdateCommand(int ID, ControlCommands c)
 {
     PlayerCommands[ID] = c;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Method that informs the server
        /// </summary>
        public void Process()
        {
            lock (world)
            {
                String movingDir = "";

                //If the keyPressed was up, then it sets moving dir to up
                if (keyPressedUp)
                {
                    movingDir = "up";
                }
                //If the keyPressed was left, then it sets moving dir to left
                if (keyPressedLeft)
                {
                    movingDir = "left";
                }
                //If the keyPressed was right, then it sets moving dir to right
                if (keyPressedRight)
                {
                    movingDir = "right";
                }
                //If the keyPressed was down, then it sets moving dir to down
                if (keyPressedDown)
                {
                    movingDir = "down";
                }
                //If the keyPressed was not pressed, then it sets moving dir to none
                if (!keyPressedLeft && !keyPressedDown && !keyPressedRight && !keyPressedUp)
                {
                    movingDir = "none";
                }


                String fireType = "";

                //If the left mouse was pressed, sets fireType to main
                if (leftMousePressed)
                {
                    fireType = "main";
                }
                //If the right mouse was pressed, sets fireType to alt
                else if (rightMousePressed)
                {
                    fireType = "alt";
                }
                //If the left mouse and right mouse were not pressed, sets fireType to none
                else if (!leftMousePressed && !rightMousePressed)
                {
                    fireType = "none";
                }

                //Creates a new vector with the xCoord, and yCoord and normalizes the new vector created
                vec = new Vector2D(xCoord, yCoord);
                vec.Normalize();

                //Passes this information in a ControlCommands
                ControlCommands c = new ControlCommands(movingDir, fireType, vec);

                //Serializes the control commands
                string serializedString = JsonConvert.SerializeObject(c);

                //If the server is open, then it passes the serialized string to the server
                if (theServer != null)
                {
                    Networking.Send(theServer.TheSocket, serializedString + "\n");
                }
            }
        }