Beispiel #1
0
        static void Main(string[] args)
        {
            BattleShip b = new BattleShip();

            b.Run();

            /*Make the sea array... then make ships.
             * make it so the ships can be placed.
             * then make it so they can be attacked and stored where and what health they have.
             *
             *
             */



            // b.Menu();
            b.PlayingBoard();


            //Console.WriteLine(BoardToString(SeaArray));
            //Working on the if statements on if there is a ship there where you shoot
            Console.WriteLine("Enter coordinates for shoots thing x first then y after you hit enter");
            Console.ReadLine();
            // int shotx = int.Parse(Console.ReadLine());
            Console.ReadLine();
            // int shoty = int.Parse(Console.ReadLine());
            // if (shot = Cell.LiveBoat) {


            // }


            Console.ReadKey();
        }
Beispiel #2
0
        public void Test_Multiple_2()
        {
            BattleShip.BattleShip shp = null;

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            Boolean placed = m_newBoard.PlaceShip(1, 8, shp, Orientation.UVERTICAL);

            Assert.IsTrue(placed);

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            placed = m_newBoard.PlaceShip(8, 8, shp, Orientation.DVERTICAL);

            Assert.IsTrue(placed);

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            placed = m_newBoard.PlaceShip(8, 1, shp, Orientation.LHORIZONTAL);

            Assert.IsTrue(placed);

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            placed = m_newBoard.PlaceShip(7, 8, shp, Orientation.RHORIZONTAL);

            Assert.IsTrue(placed);
        }
Beispiel #3
0
 public void AddBattleShip(BattleShip Obj)
 {
     if (m_currNumShapes >= m_numShapes)
     {
         return; //need to handle better
     }
     m_shapes[m_currNumShapes++] = Obj;
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            BattleShip b = new BattleShip();

            while (true)
            {
                b.Run();
            }
        }
Beispiel #5
0
        public void Test_WrongPlaceShipDV()
        {
            BattleShip.BattleShip shp = null;

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            Boolean placed = m_newBoard.PlaceShip(9, 0, shp, Orientation.DVERTICAL);

            Assert.IsFalse(placed);
        }
Beispiel #6
0
        public void Test_WrongPlaceShipRH()
        {
            BattleShip.BattleShip shp = null;

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            Boolean placed = m_newBoard.PlaceShip(0, 9, shp, Orientation.RHORIZONTAL);

            Assert.IsFalse(placed);
        }
Beispiel #7
0
        public Boolean Attack(UInt16 row, UInt16 col)
        {
            BattleShip shp = IsOccupied(row, col);

            if (null != shp)
            {
                shp.DelCell();
                return(true);
            }
            return(false);
        }
 private void StartGame(object sender, EventArgs e)
 {
     backgroundLoader.Stop();
     backgroundController.Speed = 6;
     mainBattleShip             = new BattleShip(Properties.Resources.battleship, new Point(this.Width / 2 - 25, this.Height - 120), new Size(70, 80), 10);
     chickenArmy     = new ChickenArmy(this.ClientSize);
     chickenLocation = new Random((int)DateTime.Now.Ticks);
     score           = 0;
     gameOver        = false;
     gameProccesser.Start();
     btnStartGame.Visible = lbHowToPlayContent.Visible = lbHowToPlayTitle.Visible = gamePause = false;
 }
Beispiel #9
0
        public void Test_PlaceShips()
        {
            BattleShip.BattleShip shp = null;

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            m_newBoard.PlaceShip(1, 1, shp, Orientation.RHORIZONTAL);

            shp = m_newBoard.IsOccupied(1, 1);

            Assert.IsNotNull(shp);
        }
Beispiel #10
0
        public Boolean PlaceShip(UInt16 startrow, UInt16 startcol, BattleShip Obj, Orientation orient)
        {
            try
            {
                m_Grid.PlaceShip(startrow, startcol, Obj, orient);
            }
            catch (Exception err)
            {
                return(false);
            }

            return(true);
        }
Beispiel #11
0
        public void Attack_WithOneDestroyed()
        {
            m_newBoard.AddBattleShip(new BattleShip.BattleShip(1, 3));
            m_newBoard.AddBattleShip(new BattleShip.BattleShip(1, 1));

            Boolean placed = m_newBoard.PlaceShip(2, 2, m_newBoard.GetBattleShip(0), Orientation.RHORIZONTAL);

            Assert.IsTrue(m_newBoard.Attack(2, 4));
            Assert.IsTrue(m_newBoard.Attack(2, 2));
            Assert.IsTrue(m_newBoard.Attack(2, 3));

            BattleShip.BattleShip ship = m_newBoard.GetBattleShip(0);
            Assert.IsTrue(ship.IsDestroyed());
        }
Beispiel #12
0
        public void Test_Multiple_1()
        {
            BattleShip.BattleShip shp = null;

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(2, 4));

            Boolean placed = m_newBoard.PlaceShip(2, 5, shp, Orientation.DVERTICAL);

            Assert.IsTrue(placed);

            shp = m_newBoard.IsOccupied(5, 6);

            Assert.IsNotNull(shp);

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(2, 4));

            placed = m_newBoard.PlaceShip(5, 4, shp, Orientation.RHORIZONTAL);

            Assert.IsFalse(placed);

            placed = m_newBoard.PlaceShip(5, 1, shp, Orientation.RHORIZONTAL);

            Assert.IsTrue(placed);

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 7));

            placed = m_newBoard.PlaceShip(1, 7, shp, Orientation.LHORIZONTAL);

            Assert.IsTrue(placed);

            m_newBoard.AddBattleShip(shp = new BattleShip.BattleShip(1, 2));

            placed = m_newBoard.PlaceShip(0, 8, shp, Orientation.UVERTICAL);

            Assert.IsFalse(placed);

            placed = m_newBoard.PlaceShip(1, 4, shp, Orientation.UVERTICAL);

            Assert.IsFalse(placed);

            placed = m_newBoard.PlaceShip(1, 8, shp, Orientation.UVERTICAL);

            Assert.IsTrue(placed);
        }
Beispiel #13
0
        public void PlaceShip(UInt16 startrow, UInt16 startcol, BattleShip ship, Orientation orient)
        {
            //check if the object overlaps some other
            if (startrow < 0 || startrow >= m_rows)
            {
                throw new Exception();
            }
            if (startcol < 0 || startcol >= m_cols)
            {
                throw new Exception();
            }

            m_scratchPad.Clear();

            m_ScratchStartRow    = startrow;
            m_ScratchStartCol    = startcol;
            m_ScratchBSRows      = ship.Rows;
            m_ScratchBSCols      = ship.Cols;
            m_scratchOrientation = orient;

            GridEnumerator itor = GetEnumerator();

            //this loop could throw exception
            foreach (Cell one in this)
            {
                m_scratchPad.Add(one);
            }

            foreach (Cell one in m_scratchPad)
            {
                one.Val = m_shapes.Count + 1;
                ship.AddCell();
            }

            m_shapes.Add(ship);
        }
Beispiel #14
0
        public void Attack_WithAllDestroyed()
        {
            m_newBoard.AddBattleShip(new BattleShip.BattleShip(1, 3));
            m_newBoard.AddBattleShip(new BattleShip.BattleShip(1, 1));

            Boolean placed = m_newBoard.PlaceShip(2, 2, m_newBoard.GetBattleShip(0), Orientation.RHORIZONTAL);

            placed = m_newBoard.PlaceShip(0, 2, m_newBoard.GetBattleShip(1), Orientation.DVERTICAL);

            Assert.IsTrue(placed);
            Assert.IsTrue(m_newBoard.Attack(2, 4));
            Assert.IsTrue(m_newBoard.Attack(2, 2));
            Assert.IsTrue(m_newBoard.Attack(2, 3));

            BattleShip.BattleShip ship = m_newBoard.GetBattleShip(0);
            Assert.IsTrue(ship.IsDestroyed());

            Assert.IsTrue(m_newBoard.Attack(0, 2));

            ship = m_newBoard.GetBattleShip(1);
            Assert.IsTrue(ship.IsDestroyed());

            Assert.IsTrue(m_newBoard.HasLostGame());
        }