Esempio n. 1
0
        private RobotParameter GetParameter()
        {
            Random random = new Random();

            Type  type   = typeof(RobotParameter);
            Array values = type.GetEnumValues();
            int   index  = random.Next(values.Length);

            RobotParameter result = (RobotParameter)values.GetValue(index);

            return(result);
        }
Esempio n. 2
0
 public Robot(RobotParameter robotParameter)
 {
     _player                 = robotParameter.Player;
     Hp                      = robotParameter.Hp;
     _bodyBrokenPoint        = robotParameter.BodyBrokenPoint;
     _defaultBodyBrokenPoint = robotParameter.BodyBrokenPoint;
     _rightWeapon            = robotParameter.RightWeapon;
     _leftWeapon             = robotParameter.LeftWeapon;
     _energyToRepairBody     = robotParameter.EnergyToRepairBody;
     Observable.EveryUpdate().Subscribe(_ =>
     {
         Energy = Math.Min((Energy + Time.deltaTime * ConstValue.EnergyRecoveryRate), 100f);
     });
 }
    public void LoadXMLConfig()
    {
        string text;

        using (StreamReader sr = new StreamReader(playerValueXMLPath))
        {
            text = sr.ReadToEnd();
        }

        XmlDocument doc = new XmlDocument();

        doc.LoadXml(text);
        XmlElement allValues = doc.DocumentElement;

        for (int i = 0; i < allValues.ChildNodes.Count; i++)
        {
            XmlNode valueNode = allValues.ChildNodes.Item(i);
            switch (valueNode.Name)
            {
            case "Robots":
            {
                for (int j = 0; j < valueNode.ChildNodes.Count; j++)
                {
                    XmlNode        robotNode = valueNode.ChildNodes.Item(j);
                    RobotParameter rp        = new RobotParameter();
                    Robots         robot     = (Robots)Enum.Parse(typeof(Robots), robotNode.Attributes["name"].Value);
                    rp.MaxEnergy        = float.Parse(robotNode.Attributes["MaxEnergy"].Value);
                    rp.StartEnergy      = float.Parse(robotNode.Attributes["StartEnergy"].Value);
                    rp.SolarChargeSpeed = int.Parse(robotNode.Attributes["SolarChargeSpeed"].Value);
                    rp.StartTrash       = int.Parse(robotNode.Attributes["StartTrash"].Value);
                    rp.PowerConsume     = int.Parse(robotNode.Attributes["PowerConsume"].Value);
                    rp.Relife_speed     = float.Parse(robotNode.Attributes["Relife_speed"].Value);
                    rp.Rotate_Speed     = float.Parse(robotNode.Attributes["Rotate_Speed"].Value);
                    rp.Max_Speed        = float.Parse(robotNode.Attributes["Max_Speed"].Value);
                    rp.Shoot_Speed      = float.Parse(robotNode.Attributes["Shoot_Speed"].Value);
                    rp.Shoot_CD         = float.Parse(robotNode.Attributes["Shoot_CD"].Value);
                    rp.RobotMass        = float.Parse(robotNode.Attributes["RobotMass"].Value);
                    rp.RobotDrag        = float.Parse(robotNode.Attributes["RobotDrag"].Value);
                    rp.RobotRotateDrag  = float.Parse(robotNode.Attributes["RobotRotateDrag"].Value);
                    rp.AmmoMass         = float.Parse(robotNode.Attributes["AmmoMass"].Value);
                    rp.AmmoDrag         = float.Parse(robotNode.Attributes["AmmoDrag"].Value);
                    rp.RobotScale       = float.Parse(robotNode.Attributes["RobotScale"].Value);
                    rp.AmmoScale        = float.Parse(robotNode.Attributes["AmmoScale"].Value);
                    rp.AmmoDamage       = int.Parse(robotNode.Attributes["AmmoDamage"].Value);
                    rp.wake             = float.Parse(robotNode.Attributes["wake"].Value);
                    rp.ContactDamage    = float.Parse(robotNode.Attributes["ContactDamage"].Value);
                    rp.ContactX         = float.Parse(robotNode.Attributes["ContactX"].Value);
                    rp.Move_Speed       = float.Parse(robotNode.Attributes["Move_Speed"].Value);
                    rp.Do_num           = int.Parse(robotNode.Attributes["Do_num"].Value);
                    rp.EmojiScale       = float.Parse(robotNode.Attributes["EmojiScale"].Value);

                    if (!RobotParameters.ContainsKey(robot))
                    {
                        RobotParameters.Add(robot, rp);
                    }
                }

                break;
            }

            case "Map":
            {
                GarbageBulletBeLitterSpeedThreshold = float.Parse(valueNode.Attributes["GarbageBulletBeLitterSpeedThreshold"].Value);
                StarterFloorGarbage = int.Parse(valueNode.Attributes["StarterFloorGarbage"].Value);
                LevelTime           = float.Parse(valueNode.Attributes["LevelTime"].Value);
                break;
            }
            }
        }
    }