Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //First Create the BattleField
            string      battleFieldDimensions = Console.ReadLine();
            BattleField battleField           = new BattleField(battleFieldDimensions);

            //Create the 2 Players
            Player player1 = new Player("Player-1");
            Player player2 = new Player("Player-2");

            int          noOfBattleShipsForEachPlayer = Convert.ToInt32(Console.ReadLine());
            List <IShip> player1Ships = new List <IShip>();
            List <IShip> player2Ships = new List <IShip>();

            for (int i = 0; i < noOfBattleShipsForEachPlayer; i++)
            {
                string      inputLine          = Console.ReadLine();
                string[]    inputs             = inputLine.Split(' ');
                char        shipType           = Convert.ToChar(inputs[0]);
                int         shipWidth          = Convert.ToInt32(inputs[1]);
                int         shipHeight         = Convert.ToInt32(inputs[2]);
                Coordinates player1Coordinates = new Coordinates(inputs[3]);
                Coordinates player2Coordinates = new Coordinates(inputs[4]);

                player1.AddShip(ShipFactory.GetShip(shipType, player1Coordinates, shipHeight, shipWidth));
                player2.AddShip(ShipFactory.GetShip(shipType, player2Coordinates, shipHeight, shipWidth));
            }

            Queue <Coordinates> player1Shots = new Queue <Coordinates>();
            Queue <Coordinates> player2Shots = new Queue <Coordinates>();

            string player1ShotsInput = Console.ReadLine();

            string[] player1ShotsSplit = player1ShotsInput.Split(' ');
            for (int i = 0; i < player1ShotsSplit.Length; i++)
            {
                player1.shots.Enqueue(new Coordinates(player1ShotsSplit[i]));
            }


            string player2ShotsInput = Console.ReadLine();

            string[] player2ShotsSplit = player2ShotsInput.Split(' ');
            for (int i = 0; i < player2ShotsSplit.Length; i++)
            {
                player2.shots.Enqueue(new Coordinates(player2ShotsSplit[i]));
            }


            Game game = new Game(battleField, player1, player2);

            game.Begin();
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int battlefieldSize = 10;

            var humanBatlefield = new BattleField(battlefieldSize);
            var robotBatlefield = new BattleField(battlefieldSize);

            var humanDrawer = new BoardDrawer(humanBatlefield, "Human");
            var robotDrawer = new BoardDrawer(robotBatlefield, "Computer");

            var allShips = Enum.GetValues(typeof(ShipType)).Cast <ShipType>().ToArray();

            //var humanPlacer = new HumanShipPlacer(allShips, humanBatlefield);
            var humanPlacer = new RandomShipPlacer(allShips, humanBatlefield);
            var robotPlacer = new RandomShipPlacer(allShips, robotBatlefield);

            var humanPlayer = new HumanPlayer(robotDrawer, robotBatlefield, robotPlacer);
            var robotPlayer = new RobotPlayer(humanDrawer, humanBatlefield, humanPlacer);

            var game = new Game(humanPlayer, robotPlayer);

            game.Play();
        }
Exemplo n.º 3
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.MyField = ((Battleship.BattleField)(target));
                return;

            case 2:
                this.labelA = ((System.Windows.Controls.Label)(target));
                return;

            case 3:
                this.labelB = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.labelC = ((System.Windows.Controls.Label)(target));
                return;

            case 5:
                this.labelD = ((System.Windows.Controls.Label)(target));
                return;

            case 6:
                this.labelE = ((System.Windows.Controls.Label)(target));
                return;

            case 7:
                this.labelF = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.labelG = ((System.Windows.Controls.Label)(target));
                return;

            case 9:
                this.labelH = ((System.Windows.Controls.Label)(target));
                return;

            case 10:
                this.labelI = ((System.Windows.Controls.Label)(target));
                return;

            case 11:
                this.labelJ = ((System.Windows.Controls.Label)(target));
                return;

            case 12:
                this.label1 = ((System.Windows.Controls.Label)(target));
                return;

            case 13:
                this.label2 = ((System.Windows.Controls.Label)(target));
                return;

            case 14:
                this.label3 = ((System.Windows.Controls.Label)(target));
                return;

            case 15:
                this.label4 = ((System.Windows.Controls.Label)(target));
                return;

            case 16:
                this.label5 = ((System.Windows.Controls.Label)(target));
                return;

            case 17:
                this.label6 = ((System.Windows.Controls.Label)(target));
                return;

            case 18:
                this.label7 = ((System.Windows.Controls.Label)(target));
                return;

            case 19:
                this.label8 = ((System.Windows.Controls.Label)(target));
                return;

            case 20:
                this.label9 = ((System.Windows.Controls.Label)(target));
                return;

            case 21:
                this.label10 = ((System.Windows.Controls.Label)(target));
                return;

            case 22:
                this.Group1 = ((System.Windows.Controls.GroupBox)(target));
                return;

            case 23:
                this.radioButton1 = ((System.Windows.Controls.RadioButton)(target));

            #line 34 "..\..\MainWindow.xaml"
                this.radioButton1.Click += new System.Windows.RoutedEventHandler(this.radioButton1_Click);

            #line default
            #line hidden
                return;

            case 24:
                this.radioButton2 = ((System.Windows.Controls.RadioButton)(target));

            #line 35 "..\..\MainWindow.xaml"
                this.radioButton2.Click += new System.Windows.RoutedEventHandler(this.radioButton1_Click);

            #line default
            #line hidden
                return;

            case 25:
                this.radioButton3 = ((System.Windows.Controls.RadioButton)(target));

            #line 36 "..\..\MainWindow.xaml"
                this.radioButton3.Click += new System.Windows.RoutedEventHandler(this.radioButton1_Click);

            #line default
            #line hidden
                return;

            case 26:
                this.radioButton4 = ((System.Windows.Controls.RadioButton)(target));

            #line 37 "..\..\MainWindow.xaml"
                this.radioButton4.Click += new System.Windows.RoutedEventHandler(this.radioButton1_Click);

            #line default
            #line hidden
                return;

            case 27:
                this.groupBox = ((System.Windows.Controls.GroupBox)(target));
                return;

            case 28:
                this.radioButtonGor = ((System.Windows.Controls.RadioButton)(target));

            #line 42 "..\..\MainWindow.xaml"
                this.radioButtonGor.Click += new System.Windows.RoutedEventHandler(this.radioButtonGor_Click);

            #line default
            #line hidden
                return;

            case 29:
                this.radioButtonVer = ((System.Windows.Controls.RadioButton)(target));

            #line 43 "..\..\MainWindow.xaml"
                this.radioButtonVer.Click += new System.Windows.RoutedEventHandler(this.radioButtonVer_Click);

            #line default
            #line hidden
                return;

            case 30:
                this.buttonStartGame = ((System.Windows.Controls.Button)(target));

            #line 46 "..\..\MainWindow.xaml"
                this.buttonStartGame.Click += new System.Windows.RoutedEventHandler(this.buttonStartGame_Click);

            #line default
            #line hidden
                return;

            case 31:
                this.buttonClear = ((System.Windows.Controls.Button)(target));

            #line 47 "..\..\MainWindow.xaml"
                this.buttonClear.Click += new System.Windows.RoutedEventHandler(this.buttonClear_Click);

            #line default
            #line hidden
                return;

            case 32:
                this.EnemyField = ((Battleship.BattleField)(target));
                return;

            case 33:
                this.labelA2 = ((System.Windows.Controls.Label)(target));
                return;

            case 34:
                this.labelB2 = ((System.Windows.Controls.Label)(target));
                return;

            case 35:
                this.labelC2 = ((System.Windows.Controls.Label)(target));
                return;

            case 36:
                this.labelD2 = ((System.Windows.Controls.Label)(target));
                return;

            case 37:
                this.labelE2 = ((System.Windows.Controls.Label)(target));
                return;

            case 38:
                this.labelF2 = ((System.Windows.Controls.Label)(target));
                return;

            case 39:
                this.labelG2 = ((System.Windows.Controls.Label)(target));
                return;

            case 40:
                this.labelH2 = ((System.Windows.Controls.Label)(target));
                return;

            case 41:
                this.labelI2 = ((System.Windows.Controls.Label)(target));
                return;

            case 42:
                this.labelJ2 = ((System.Windows.Controls.Label)(target));
                return;

            case 43:
                this.label12 = ((System.Windows.Controls.Label)(target));
                return;

            case 44:
                this.label22 = ((System.Windows.Controls.Label)(target));
                return;

            case 45:
                this.label32 = ((System.Windows.Controls.Label)(target));
                return;

            case 46:
                this.label42 = ((System.Windows.Controls.Label)(target));
                return;

            case 47:
                this.label52 = ((System.Windows.Controls.Label)(target));
                return;

            case 48:
                this.label62 = ((System.Windows.Controls.Label)(target));
                return;

            case 49:
                this.label72 = ((System.Windows.Controls.Label)(target));
                return;

            case 50:
                this.label82 = ((System.Windows.Controls.Label)(target));
                return;

            case 51:
                this.label92 = ((System.Windows.Controls.Label)(target));
                return;

            case 52:
                this.label102 = ((System.Windows.Controls.Label)(target));
                return;

            case 53:
                this.groupBox1 = ((System.Windows.Controls.GroupBox)(target));
                return;

            case 54:
                this.radioButtonEzLvl = ((System.Windows.Controls.RadioButton)(target));

            #line 71 "..\..\MainWindow.xaml"
                this.radioButtonEzLvl.Click += new System.Windows.RoutedEventHandler(this.radioButtonEzLvl_Click);

            #line default
            #line hidden
                return;

            case 55:
                this.radioButtonHardLvl = ((System.Windows.Controls.RadioButton)(target));

            #line 72 "..\..\MainWindow.xaml"
                this.radioButtonHardLvl.Click += new System.Windows.RoutedEventHandler(this.radioButtonHardLvl_Click);

            #line default
            #line hidden
                return;

            case 56:
                this.buttonAutoPlacement = ((System.Windows.Controls.Button)(target));

            #line 75 "..\..\MainWindow.xaml"
                this.buttonAutoPlacement.Click += new System.Windows.RoutedEventHandler(this.buttonAutoPlacement_Click);

            #line default
            #line hidden
                return;

            case 57:
                this.buttonNewGame = ((System.Windows.Controls.Button)(target));

            #line 76 "..\..\MainWindow.xaml"
                this.buttonNewGame.Click += new System.Windows.RoutedEventHandler(this.buttonNewGame_Click);

            #line default
            #line hidden
                return;

            case 58:
                this.SaveMenuItem = ((System.Windows.Controls.MenuItem)(target));

            #line 79 "..\..\MainWindow.xaml"
                this.SaveMenuItem.Click += new System.Windows.RoutedEventHandler(this.SaveMenuItem_Click);

            #line default
            #line hidden
                return;

            case 59:
                this.LoadMenuItem = ((System.Windows.Controls.MenuItem)(target));

            #line 80 "..\..\MainWindow.xaml"
                this.LoadMenuItem.Click += new System.Windows.RoutedEventHandler(this.LoadMenuItem_Click);

            #line default
            #line hidden
                return;

            case 60:
                this.ExitMenuItem = ((System.Windows.Controls.MenuItem)(target));

            #line 81 "..\..\MainWindow.xaml"
                this.ExitMenuItem.Click += new System.Windows.RoutedEventHandler(this.ExitMenuItem_Click);

            #line default
            #line hidden
                return;

            case 61:

            #line 83 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.StatisticMenuItem_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Exemplo n.º 4
0
 public EnemyAI(Level lvl, BattleField battleField)
 {
     this.Lvl         = lvl;
     this.battleField = battleField;
 }
Exemplo n.º 5
0
 public Game(BattleField battlefield, Player player1, Player player2)
 {
     this.battlefield = battlefield;
     this.player1     = player1;
     this.player2     = player2;
 }