示例#1
0
        /// <summary>
        /// This creates a new match.
        /// </summary>
        public void NewMatch()
        {
            match = new UserMatch(configuration);
            user  = new Player(match, NAME);
            match.AddUser(user);

            var bots = ControllerSkeleton.LoadControllerFolder(Environment.CurrentDirectory + "\\..\\bots");

            foreach (ControllerSkeleton bot in bots)
            {
                if (bot.Controller.Name == BOTNAME)
                {
                    computer = match.PlayerCreate(bot);
                    break;
                }
            }

            match.OnEvent += UpdateShot;
            match.OnEvent += UpdateShotHit;
            match.OnEvent += UpdateWinner;
            match.OnEvent += RoundEnd;
            match.OnEvent += UpdateShipDestroyed;

            match.Play();
        }
示例#2
0
        private bool SelectionConfirm(string btn)
        {
            ControllerSkeleton red = null, blue = null;

            foreach (var bot in selectableBots)
            {
                var botName = bot.GetAttribute <NameAttribute>().Name;
                if (red == null && redGroup.GetSelected() == botName)
                {
                    red = bot;
                }
                if (blue == null && blueGroup.GetSelected() == botName)
                {
                    blue = bot;
                }
                if (red != null && blue != null)
                {
                    break;
                }
            }
            BattleshipConsole.RemoveModule(this);
            BattleshipConsole.AddModule(new CompetitionOptionsDisplay(red, blue));
            BattleshipConsole.UpdateDisplay();
            return(true);
        }
        /// <summary>
        /// Adds a Player from an IController to the match.
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public Player PlayerCreate(ControllerSkeleton skeleton)
        {
            ControlledPlayer newPlayer = new ControlledPlayer(this, skeleton.GetAttribute <NameAttribute>().Name, skeleton.CreateInstance());

//            newPlayer.OnEvent += ApplyEvent;
            PlayerAdd(newPlayer);
//            foreach (Ship ship in newPlayer.Ships)
//            {
//                ship.OnEvent += ApplyEvent;
//            }
            newPlayer.Controller.Player = newPlayer;
            return(newPlayer);
        }
 public CompetitionOptionsDisplay(ControllerSkeleton red, ControllerSkeleton blue)
 {
     this.red = red;
     this.blue = blue;
     layout = new VerticalLayout(VerticalLayout.VerticalAlign.Center);
     roundsNumberControl = new NumericControl(new NumericControl.NumericControlParameters("# of rounds", false, 1, 100000, 10, 1000));
     millisecondControl = new NumericControl(new NumericControl.NumericControlParameters("Millisecond delay", false, 0, 10000, 5, 0));
     showBoards = new CheckboxControl("Show ASCII boards");
     layout.Add(roundsNumberControl);
     //layout.Add(new CheckboxControl("Play out rounds"));
     layout.Add(millisecondControl);
     layout.Add(showBoards);
     layout.Add(new ButtonControl("Confirm", ButtonConfirmEvent));
     AddControlLayout(layout);
 }
示例#5
0
 public CompetitionOptionsDisplay(ControllerSkeleton red, ControllerSkeleton blue)
 {
     this.red            = red;
     this.blue           = blue;
     layout              = new VerticalLayout(VerticalLayout.VerticalAlign.Center);
     roundsNumberControl = new NumericControl(new NumericControl.NumericControlParameters("# of rounds", false, 1, 100000, 10, 1000));
     millisecondControl  = new NumericControl(new NumericControl.NumericControlParameters("Millisecond delay", false, 0, 10000, 5, 0));
     showBoards          = new CheckboxControl("Show ASCII boards");
     layout.Add(roundsNumberControl);
     //layout.Add(new CheckboxControl("Play out rounds"));
     layout.Add(millisecondControl);
     layout.Add(showBoards);
     layout.Add(new ButtonControl("Confirm", ButtonConfirmEvent));
     AddControlLayout(layout);
 }
        /// <summary>
        /// Constructor for the MainWindow. Collapses the collapseable elements of the WPF application.
        /// </summary>
        public MainWindow()
        {
            Configuration.Initialize(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MBC Data");
            InitializeComponent();
            centerConsoleBorder.Visibility = System.Windows.Visibility.Collapsed;
            advTabs.Visibility             = System.Windows.Visibility.Collapsed;

            configuration = Configuration.Global;

            availableControllers = ControllerSkeleton.LoadControllerFolder(
                configuration.GetValue <string>("app_data_root") + "controllers");
            availableControllers.AddRange(ControllerSkeleton.LoadControllerFolder(Environment.CurrentDirectory + "\\..\\bots"));

            //currentMatch = new ControlledMatch(configuration, availableControllers.ToArray());

            UpdateLayout();
        }
        private void menuSelector_Click(object sender, RoutedEventArgs e)
        {
            MenuItem selected = e.Source as MenuItem;

            foreach (var ctrl in availableControllers)
            {
                if (ctrl.ToString() == selected.Header)
                {
                    if (redPopupActivated)
                    {
                        redSelected = ctrl;
                    }
                    else
                    {
                        blueSelected = ctrl;
                    }
                    break;
                }
            }
        }
示例#8
0
        /// <summary>
        /// AppConsole entry point
        /// </summary>
        /// <param name="args">Arguments to be specified for running commands as batch mode.</param>
        private static void Main(string[] args)
        {
            //Set up the console
            Console.Title = "MBC console";
            Console.TreatControlCAsInput = true;
            Console.CancelKeyPress      += (a, b) =>
            {
                b.Cancel = false;
            };
            Configuration.Initialize(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MBC Data");

            //Load controllers from the application data directory.
            availableControllers = ControllerSkeleton.LoadControllerFolder(
                Configuration.Global.GetValue <string>("app_data_root") + "controllers");
            //Load controllers from the running application root directory.
            availableControllers.AddRange(ControllerSkeleton.LoadControllerFolder(Environment.CurrentDirectory + "\\..\\bots"));

            if (args.Length != 0)
            {
                if (!RunCommand(args))
                {
                    Console.WriteLine("Invalid command specified.");
                }
                return;
            }

            Console.WriteLine("Type \"help\" for usage.");

            inputRunning = true;
            while (inputRunning)
            {
                Console.Write("\n> ");

                var consoleInput = Console.ReadLine();
                if (consoleInput != null && !RunCommand(consoleInput))
                {
                    Console.WriteLine("Invalid command specified.");
                }
            }
        }
示例#9
0
 private void LoadControllers()
 {
     selectableBots = ControllerSkeleton.LoadControllerFolder(Environment.CurrentDirectory + "\\..\\bots");
 }
示例#10
0
 private void menuSelector_Click(object sender, RoutedEventArgs e)
 {
     MenuItem selected = e.Source as MenuItem;
     foreach (var ctrl in availableControllers)
     {
         if (ctrl.ToString() == selected.Header)
         {
             if (redPopupActivated)
             {
                 redSelected = ctrl;
             }
             else
             {
                 blueSelected = ctrl;
             }
             break;
         }
     }
 }