Exemple #1
0
        void aiSelection(object source, EventArgs e)
        {
            myTimer.Stop();
            Square t = computer.makeSmartTarget();

            if (t.getXLoc() == -1)
            {
                t = computer.makeRandomTarget();
            }
            computer.firedOn[t.getXLoc(), t.getYLoc()] = true;
            shotResolution(t.getXLoc(), t.getYLoc(), controller.getPlayer());
        }
 public void TestShotDefaultConstructor()
 {
     Shot shot = new Shot();
     Square square = new Square();
     Assert.IsTrue(shot.getTarget().getXLoc() == square.getXLoc());
     Assert.IsTrue(shot.getTarget().getYLoc() == square.getYLoc());
     Assert.IsTrue(shot.getTarget().getSquareState() == square.getSquareState());
 }
 public void TestShotGettersAndSetters()
 {
     Shot shot = new Shot();
     Square square = new Square();
     shot.setTarget(square);
     Assert.IsTrue(shot.getTarget().getXLoc() == square.getXLoc());
     Assert.IsTrue(shot.getTarget().getYLoc() == square.getYLoc());
     Assert.IsTrue(shot.getTarget().getSquareState() == square.getSquareState());
 }
Exemple #4
0
        public Square makeSmartTarget()
        {
            Square target = new Square();

            target.setXLoc(-1);
            target.setYLoc(-1);
            bool needSelection = true;

            while (needSelection && knownTargets.Count > 0)
            {
                Random r     = new Random();
                int    t     = r.Next() % knownTargets.Count();
                Square known = knownTargets[t];
                needSelection = false;
                if (known.getXLoc() > 0 && !firedOn[known.getXLoc() - 1, known.getYLoc()])
                {
                    target.setXLoc(known.getXLoc() - 1);
                    target.setYLoc(known.getYLoc());
                }
                else if (known.getXLoc() < 9 && !firedOn[known.getXLoc() + 1, known.getYLoc()])
                {
                    target.setXLoc(known.getXLoc() + 1);
                    target.setYLoc(known.getYLoc());
                }
                else if (known.getYLoc() > 0 && !firedOn[known.getXLoc(), known.getYLoc() - 1])
                {
                    target.setYLoc(known.getYLoc() - 1);
                    target.setXLoc(known.getXLoc());
                }
                else if (known.getYLoc() < 9 && !firedOn[known.getXLoc(), known.getYLoc() + 1])
                {
                    target.setYLoc(known.getYLoc() + 1);
                    target.setXLoc(known.getXLoc());
                }
                else
                {
                    knownTargets.RemoveAt(t);
                    needSelection = true;
                }
            }
            return(target);
        }
Exemple #5
0
 public Square makeRandomTarget()
 {
     Random r = new Random();
     Square target = new Square();
     bool valid = false;
     while (!valid)
     {
         target.setXLoc(r.Next() % 10);
         target.setYLoc(r.Next() % 10);
         if (!firedOn[target.getXLoc(), target.getYLoc()])
         {
             valid = true;
         }
     }
     return target;
 }
Exemple #6
0
        public Square makeRandomTarget()
        {
            Random r      = new Random();
            Square target = new Square();
            bool   valid  = false;

            while (!valid)
            {
                target.setXLoc(r.Next() % 10);
                target.setYLoc(r.Next() % 10);
                if (!firedOn[target.getXLoc(), target.getYLoc()])
                {
                    valid = true;
                }
            }
            return(target);
        }
        public void TestSquareGetterAndSetter()
        {
            Square square = new Square();
            Random r = new Random();
            int n = r.Next(-1, 100);
            int m = r.Next(-1, 100);

            square.setXLoc(n);
            square.setYLoc(m);
            square.setState(State.hit);
            Assert.IsTrue(square.getXLoc().Equals(n));
            Assert.IsTrue(square.getYLoc().Equals(m));
            Assert.IsTrue(square.getSquareState().Equals(State.hit));
        }
 public void TestSquareDefaultConstructor()
 {
     Square square = new Square();
     Assert.IsTrue(square.getXLoc().Equals(0));
     Assert.IsTrue(square.getXLoc().Equals(0));
     Assert.IsTrue(square.getSquareState().Equals(State.empty));
 }
        public void TestSquareNonDefaultConstructor()
        {
            Random r = new Random();
            int n = r.Next(-1, 100);
            int m = r.Next(-1, 100);

            Square square = new Square(n, m);
            Assert.IsTrue(square.getXLoc().Equals(n));
            Assert.IsTrue(square.getYLoc().Equals(m));
            Assert.IsTrue(square.getSquareState().Equals(State.empty));
        }