Example #1
0
        public void ConstructorCheck()
        {
            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.getRobotPos(), gameInfo.robot);
            Assert.AreEqual(gameModel.getSize(), 7);
            Assert.AreEqual(gameInfo.size, 7);

            CrazyBotInfo gameInfo11 = new CrazyBotInfo(11, robotpos, time, robotdir, fieldOnBot, timeleftcrazy);

            gameModel.newGame(11, gameInfo11);
            Assert.AreEqual(gameModel.getRobotPos(), gameInfo11.robot);
            Assert.AreEqual(gameModel.getSize(), 11);
            Assert.AreEqual(gameInfo11.size, 11);

            for (int i = 0; i < 10; i++)
            {
                int prev = gameModel.getTime();
                gameModel.AdvanceTime(this, new System.EventArgs());
                if (gameModel.isInGame())
                {
                    Assert.IsTrue(prev < gameModel.getTime());
                }
            }
        }
Example #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);
        }
Example #3
0
        public void MoveRobot()
        {
            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);

            Assert.AreEqual(gameModel.getRobotPos(), gameInfo.robot);
            gameModel.AdvanceTime(this, new System.EventArgs());
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getRobotPos(), gameInfo.robot);
            Console.WriteLine(gameModel.getRobotPos().X + ", " + gameModel.getRobotPos().Y);
            Assert.AreEqual(gameModel.getRobotPos(), new Position(1, 0));

            gameInfo.robotDir = RobotDirection.DOWN;
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getRobotPos(), gameInfo.robot);
            Assert.AreEqual(gameModel.getRobotPos(), new Position(1, 1));

            gameInfo.robotDir = RobotDirection.RIGHT;
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getRobotPos(), gameInfo.robot);
            Assert.AreEqual(gameModel.getRobotPos(), new Position(2, 1));

            gameInfo.robotDir = RobotDirection.LEFT;
            gameModel.AdvanceTime(this, new System.EventArgs());
            Assert.AreEqual(gameModel.getRobotPos(), gameInfo.robot);
            Assert.AreEqual(gameModel.getRobotPos(), new Position(1, 1));
        }