예제 #1
0
        public static EnemyCollection ReloadEnemies(string robocodeDir)
        {
            EnemyCollection robotList = new EnemyCollection();

            try
            {
                var robotsDir  = new DirectoryInfo(Path.Combine(robocodeDir, "robots"));
                var robotFiles = robotsDir.GetFiles("*", SearchOption.AllDirectories)
                                 .Where(x => x.Extension == ".class" || x.Extension == ".jar");
                var robotSet = new Dictionary <string, StringValue>();
                foreach (var robot in robotFiles)
                {
                    string robotName = Path.Combine(robot.DirectoryName, Path.GetFileNameWithoutExtension(robot.FullName));
                    robotName = robotName.Remove(0, robotsDir.FullName.Length);
                    string[] nameParts = robotName.Split(new[] { Path.DirectorySeparatorChar },
                                                         StringSplitOptions.RemoveEmptyEntries);
                    robotName = string.Join(".", nameParts);
                    robotSet[robot.FullName] = new StringValue(robotName);
                }
                robotList.AddRange(robotSet.Values);

                foreach (var robot in robotList)
                {
                    robotList.SetItemCheckedState(robot, false);
                }
            }
            catch { }

            //select one robot so that if a user tries out the Robocode problem it works with the default settings
            if (robotList.Exists(x => x.Value == sampleRobotToSelect))
            {
                StringValue sampleRobot = robotList.Single(x => x.Value == sampleRobotToSelect);
                robotList.SetItemCheckedState(sampleRobot, true);
            }

            return(robotList);
        }
예제 #2
0
 protected EnemyCollection(EnemyCollection original, Cloner cloner)
     : base(original, cloner)
 {
     RobocodePath = original.RobocodePath;
 }