示例#1
0
        public void WalkOnCannotWall()
        {
            int            size          = 7;
            Position       robotpos      = new Position(1, 1);
            ulong          time          = 0;
            RobotDirection robotdir      = RobotDirection.UP;
            FieldType      fieldOnBot    = FieldType.NO_WALL;
            int            timeleftcrazy = 8;

            CrazyBotInfo  gameInfo  = new CrazyBotInfo(size, robotpos, time, robotdir, fieldOnBot, timeleftcrazy);
            CrazyBotModel gameModel = new CrazyBotModel();

            gameModel.newGame(7, gameInfo);
            Assert.AreEqual(gameModel.getSize(), 7);
            Assert.AreEqual(gameInfo.size, 7);
            gameModel.AdvanceTime(this, new System.EventArgs());


            //Place walls
            Assert.AreEqual(gameModel.getBoard()[2, 4], FieldType.NO_WALL);
            gameModel.invertWall(new Position(2, 4));
            Assert.AreEqual(gameModel.getBoard()[2, 4], FieldType.WALL);
            gameInfo.robot = new Position(2, 5);
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getBoard()[2, 4], FieldType.CANNOT_WALL);
        }
示例#2
0
        private GridButton GridButtonStyler(GridButton btn)
        {
            int x = btn.X;
            int y = btn.Y;

            buttons[x, y].Text = "";
            if (model.getBoard()[x, y] == FieldType.NO_WALL)
            {
                buttons[x, y].BackgroundImage = noWallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.WALL)
            {
                buttons[x, y].BackgroundImage = WallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.CANNOT_WALL)
            {
                buttons[x, y].BackgroundImage = cannotWallTexture;
            }
            else if (model.getBoard()[x, y] == FieldType.MAGNET)
            {
                Image imageBackground = noWallTexture;
                int   size            = Convert.ToInt32(imageBackground.Width * 0.8);
                Image imageOverlay    = new Bitmap(magnetTexture, new Size(size, size));

                Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
                using (Graphics gr = Graphics.FromImage(img))
                {
                    gr.DrawImage(imageBackground, new Point(0, 0));
                    gr.DrawImage(imageOverlay, new Point(Convert.ToInt32(imageBackground.Size.Width * 0.1), Convert.ToInt32(imageBackground.Size.Height * 0.1)));
                }

                btn.BackgroundImage = img;
            }


            if (model.getRobotPos().Equals(new Position(x, y)))
            {
                Image imageBackground = (model.getFieldTypeOnRobot() == FieldType.NO_WALL) ? noWallTexture : cannotWallTexture;
                int   size            = Convert.ToInt32(imageBackground.Width * 0.8);
                Image imageOverlay    = new Bitmap(robotTexture, new Size(size, size));

                Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
                using (Graphics gr = Graphics.FromImage(img))
                {
                    gr.DrawImage(imageBackground, new Point(0, 0));
                    gr.DrawImage(imageOverlay, new Point(Convert.ToInt32(imageBackground.Size.Width * 0.1), Convert.ToInt32(imageBackground.Size.Height * 0.1)));
                }

                btn.BackgroundImage = img;
            }


            btn.BackgroundImageLayout = ImageLayout.Stretch;

            return(btn);
        }
示例#3
0
        public void PlaceWalls()
        {
            int            size          = 7;
            Position       robotpos      = new Position(1, 1);
            ulong          time          = 0;
            RobotDirection robotdir      = RobotDirection.UP;
            FieldType      fieldOnBot    = FieldType.NO_WALL;
            int            timeleftcrazy = 8;

            CrazyBotInfo  gameInfo  = new CrazyBotInfo(size, robotpos, time, robotdir, fieldOnBot, timeleftcrazy);
            CrazyBotModel gameModel = new CrazyBotModel();

            gameModel.newGame(7, gameInfo);
            Assert.AreEqual(gameModel.getSize(), 7);
            Assert.AreEqual(gameInfo.size, 7);

            //Place walls
            Assert.AreEqual(gameModel.getBoard()[6, 6], FieldType.NO_WALL);
            gameModel.invertWall(new Position(6, 6));
            Assert.AreEqual(gameModel.getBoard()[6, 6], FieldType.WALL);

            Assert.AreEqual(gameModel.getBoard()[3, 1], FieldType.NO_WALL);
            gameModel.invertWall(new Position(3, 1));
            Assert.AreEqual(gameModel.getBoard()[3, 1], FieldType.WALL);

            Assert.AreEqual(gameModel.getBoard()[2, 5], FieldType.NO_WALL);
            gameModel.invertWall(new Position(2, 5));
            Assert.AreEqual(gameModel.getBoard()[2, 5], FieldType.WALL);

            //Try to pick up those walls
            Assert.AreEqual(gameModel.getBoard()[6, 6], FieldType.WALL);
            gameModel.invertWall(new Position(6, 6));
            Assert.AreEqual(gameModel.getBoard()[6, 6], FieldType.WALL);

            Assert.AreEqual(gameModel.getBoard()[3, 1], FieldType.WALL);
            gameModel.invertWall(new Position(3, 1));
            Assert.AreEqual(gameModel.getBoard()[3, 1], FieldType.WALL);

            Assert.AreEqual(gameModel.getBoard()[2, 5], FieldType.WALL);
            gameModel.invertWall(new Position(2, 5));
            Assert.AreEqual(gameModel.getBoard()[2, 5], FieldType.WALL);

            //Try place walls on robot and magnet
            Console.WriteLine(gameModel.getBoard()[gameInfo.robot.X, gameInfo.robot.Y].ToString());
            Assert.IsTrue(gameModel.getBoard()[gameInfo.robot.X, gameInfo.robot.Y] == FieldType.ROBOT);
            gameModel.invertWall(new Position(gameInfo.robot.X, gameInfo.robot.Y));
            Assert.IsTrue(gameModel.getBoard()[gameInfo.robot.X, gameInfo.robot.Y] == FieldType.ROBOT);
            Assert.IsFalse(gameModel.getBoard()[gameInfo.robot.X, gameInfo.robot.Y] == FieldType.WALL);

            Assert.IsTrue(gameModel.getBoard()[gameModel.getMagnetPos().X, gameModel.getMagnetPos().Y] == FieldType.MAGNET);
            gameModel.invertWall(new Position(6, 6));
            Assert.IsTrue(gameModel.getBoard()[gameModel.getMagnetPos().X, gameModel.getMagnetPos().Y] == FieldType.MAGNET);
            Assert.IsFalse(gameModel.getBoard()[gameModel.getMagnetPos().X, gameModel.getMagnetPos().Y] == FieldType.WALL);
        }
示例#4
0
        public void HitPlacedWall()   //TODO: CSINÁLD MEG A MOCK-OLÁST
        {
            int            size          = 7;
            Position       robotpos      = new Position(1, 1);
            ulong          time          = 0;
            RobotDirection robotdir      = RobotDirection.RIGHT;
            FieldType      fieldOnBot    = FieldType.NO_WALL;
            int            timeleftcrazy = 8;

            CrazyBotInfo  gameInfo  = new CrazyBotInfo(size, robotpos, time, robotdir, fieldOnBot, timeleftcrazy);
            CrazyBotModel gameModel = new CrazyBotModel();

            gameModel.newGame(7, gameInfo);
            Assert.AreEqual(gameModel.getSize(), 7);
            Assert.AreEqual(gameInfo.size, 7);

            RobotDirection prevDir;

            gameModel.AdvanceTime(this, new EventArgs());

            //Place walls and hit it from RIGHT
            prevDir = gameInfo.robotDir;
            Assert.AreEqual(gameModel.getBoard()[2, 1], FieldType.NO_WALL);
            gameModel.invertWall(new Position(2, 1));
            Assert.AreEqual(gameModel.getBoard()[2, 1], FieldType.WALL);
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getBoard()[2, 1], FieldType.CANNOT_WALL);

            Assert.AreNotEqual(prevDir, gameInfo.robotDir);


            //Place walls and hit it from LEFT;
            gameInfo.robotDir = RobotDirection.LEFT;
            prevDir           = gameInfo.robotDir;

            gameInfo.robot = new Position(2, 2);
            Assert.AreEqual(gameModel.getBoard()[1, 2], FieldType.NO_WALL);
            gameModel.invertWall(new Position(1, 2));
            Assert.AreEqual(gameModel.getBoard()[1, 2], FieldType.WALL);
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getBoard()[1, 2], FieldType.CANNOT_WALL);

            Assert.AreNotEqual(prevDir, gameInfo.robotDir);


            //Place walls and hit it from UP;
            gameInfo.robotDir = RobotDirection.UP;
            prevDir           = gameInfo.robotDir;

            gameInfo.robot = new Position(5, 3);
            Assert.AreEqual(gameModel.getBoard()[5, 2], FieldType.NO_WALL);
            gameModel.invertWall(new Position(5, 2));
            Assert.AreEqual(gameModel.getBoard()[5, 2], FieldType.WALL);
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getBoard()[5, 2], FieldType.CANNOT_WALL);

            Assert.AreNotEqual(prevDir, gameInfo.robotDir);


            //Place walls and hit it from DOWN;
            gameInfo.robotDir = RobotDirection.DOWN;
            prevDir           = gameInfo.robotDir;

            gameInfo.robot = new Position(4, 3);
            Assert.AreEqual(gameModel.getBoard()[4, 4], FieldType.NO_WALL);
            gameModel.invertWall(new Position(4, 4));
            Assert.AreEqual(gameModel.getBoard()[4, 4], FieldType.WALL);
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getBoard()[1, 2], FieldType.CANNOT_WALL);

            Assert.AreNotEqual(prevDir, gameInfo.robotDir);
        }