public override bool Equals(object obj)
        {
            if (obj is null || obj.GetType() != typeof(TankControlCommand))
            {
                return(false);
            }
            TankControlCommand other = obj as TankControlCommand;
            bool isEqual             = (this.Moving == other.Moving) &&
                                       (this.Fire == other.Fire) &&
                                       (this.TurretDirection == other.TurretDirection);

            return(isEqual);
        }
Example #2
0
        private void UpdateTankBodyPosition(Tank tank, TankControlCommand command)
        {
            // update tank location
            Vector2D movingDirection = new Vector2D(0, 0);

            // tank.BodyDirection = movingDirection;

            movingDirection = ModifyMovingDirection(command.Moving, movingDirection);
            // Build our velocity vector
            Vector2D velocity = movingDirection * gameSettings.TankSpeed;

            // add velocity to position
            tank.Location = tank.Location + velocity;
        }
        private bool TryParseJsonAsTankControlCommand(string json, out TankControlCommand tankControlCommand)
        {
            JObject parsedObject    = JObject.Parse(json);
            JToken  movingAttribute = parsedObject["moving"];

            if (movingAttribute != null)
            {
                tankControlCommand = (TankControlCommand)parsedObject.ToObject <TankControlCommand>();
                return(true);
            }
            else
            {
                tankControlCommand = null;
                return(false);
            }
        }
Example #4
0
 public GameController()
 {
     theWorld           = new World();
     tankControlCommand = new TankControlCommand();
 }
Example #5
0
        private void SendTankControlCommand(TankControlCommand controlCommand)
        {
            string controlCommandJson = JsonConvert.SerializeObject(controlCommand) + "\n";

            Networking.Send(serverSocketState.TheSocket, controlCommandJson);
        }
Example #6
0
        private void UpdateTankBodyDirection(Tank tank, TankControlCommand command)
        {
            Vector2D movingDirection = tank.BodyDirection;

            tank.BodyDirection = ModifyMovingDirection(command.Moving, movingDirection);
        }
 public bool TryGetTankControlCommandByTankID(int tankID, out TankControlCommand tankControlCommand)
 {
     return(controlCommands.TryGetValue(tankID, out tankControlCommand));
 }
 public void UpdateTankControlCommand(int tankID, TankControlCommand tankControlCommand)
 {
     controlCommands[tankID] = tankControlCommand;
 }
 public void AddNewPlayer(int tankID)
 {
     controlCommands[tankID] = new TankControlCommand();
 }
Example #10
0
 public void UpdateGameControlState(int tankID, TankControlCommand tankControlCommand)
 {
     gameControlState.UpdateTankControlCommand(tankID, tankControlCommand);
 }