示例#1
0
 private void button_WOC1_Click(object sender, EventArgs e)
 {
     button_WOC1.Hide();
     button_WOC2.Hide();
     label1.Hide();
     label3.TextAlign = ContentAlignment.MiddleCenter;
     label3.Show();
     computerGrid  = new modelNmspc.Grid(10, 10);
     computerFleet = new modelNmspc.fleet();
     while (generateComputerGrid() == 404)
     {
         computerGrid  = new modelNmspc.Grid(10, 10);
         computerFleet = new modelNmspc.fleet();
     }
     foreach (var i in computerButtons)
     {
         foreach (var button in i)
         {
             button.Enabled = true;
         }
     }
     //var x = computerFleet.Ships;                 //debugging purpose only
     //foreach (var t in x)                         //draws computer fleet
     //{
     //    foreach (var z in t.squares)
     //    {
     //        computerButtons[z.row][z.column].BackColor = Color.Pink;
     //    }
     //}
 }
示例#2
0
        public void HitShipReturnsResultOfShooting()
        {
            fleet Fleet = new fleet();

            Fleet.addShip(new List <Square> {
                new Square(1, 4), new Square(1, 5), new Square(1, 6)
            });
            Fleet.addShip(new List <Square> {
                new Square(4, 5), new Square(5, 5)
            });
            var hit = Fleet.Hit(new Square(1, 4));

            Assert.AreEqual(HitResult.Hit, hit);
            hit = Fleet.Hit(new Square(1, 5));
            Assert.AreEqual(HitResult.Hit, hit);
            hit = Fleet.Hit(new Square(1, 6));
            Assert.AreEqual(HitResult.Sunken, hit);

            hit = Fleet.Hit(new Square(1, 9));
            Assert.AreEqual(HitResult.Missed, hit);
            hit = Fleet.Hit(new Square(4, 5));
            Assert.AreEqual(HitResult.Hit, hit);
            hit = Fleet.Hit(new Square(5, 5));
            Assert.AreEqual(HitResult.Sunken, hit);
        }
 private void Grid_Paint(object sender, PaintEventArgs e)
 {
     while (CreateGrid() == 404)
     {
         gr = new modelNmspc.Grid(10, 10);                             //petlja se vrti dok createGrid uspješno ne izgenerira valjanu flotu
         fl = new modelNmspc.fleet();
         Console.WriteLine("!fail!");
     }
     DrawGrid();
 }
示例#4
0
 public fleet CreateFleet(IEnumerable <int> shipLengths)
 {
     for (int i = 0; i < 3; ++i)
     {
         fleet fl = placeShips(shipLengths);
         if (fl != null)
         {
             return(fl);
         }
     }
     throw new ArgumentOutOfRangeException();
 }
示例#5
0
 private void button_WOC2_Click(object sender, EventArgs e) //reset fleet button
 {
     resetButtonsColor();
     playerGrid               = new modelNmspc.Grid(10, 10);
     playerFleet              = new modelNmspc.fleet();
     currentShipMaking        = new List <modelNmspc.Square>();
     currentPlacingShipLength = 0;
     shipHead   = null;
     terminator = new modelNmspc.squareTerminator(10, 10);
     resetLabels();
     button_WOC1.Enabled     = false;
     button_WOC1.ButtonColor = Color.Black;
 }
示例#6
0
        public void AddShipCreatesNewShipInTheFleet()
        {
            fleet Fleet = new fleet();

            Fleet.addShip(new List <Square> {
                new Square(1, 4), new Square(1, 5), new Square(1, 6)
            });
            Assert.AreEqual(1, Fleet.Ships.Count());
            Assert.IsTrue(Fleet.Ships.First().squares.Contains(new Square(1, 4)));
            Assert.IsTrue(Fleet.Ships.First().squares.Contains(new Square(1, 5)));
            Assert.IsTrue(Fleet.Ships.First().squares.Contains(new Square(1, 6)));
            Fleet.addShip(new List <Square> {
                new Square(4, 5), new Square(5, 5), new Square(6, 5)
            });
            Assert.AreEqual(2, Fleet.Ships.Count());
        }
示例#7
0
        private fleet placeShips(IEnumerable <int> shipLengths)
        {
            List <int> lengths = new List <int>(shipLengths.OrderByDescending(x => x));
            Grid       grid    = new Grid(rows, columns);
            //squareTerminator terminator = new squareTerminator(rows,columns);
            fleet Fleet = new fleet();

            while (lengths.Count() > 0)
            {
                var placements = grid.GetAvailablePlacements(lengths[0]);
                if (placements.Count() == 0)
                {
                    return(null);
                }
                lengths.RemoveAt(0);
                int index = rand.Next(0, placements.Count());
                Fleet.addShip(placements.ElementAt(index));
                var toElimiante = terminator.ToEliminate(placements.ElementAt(index));
                grid.eliminateSquares(toElimiante);
            }
            return(Fleet);
        }