Beispiel #1
0
        public void TestPlayerEatObject()
        {
            var model             = new HungerGameModel(Controller);
            var levelObjectsCount = model.Level.LevelObjects.Count();

            model.Level.LevelObjects.Add(new GameObjects.Apple_Stump(new Point(0, 0)));
            model.UpdateLevel();
            Assert.AreEqual(levelObjectsCount - 1, model.Level.LevelObjects.Count());
        }
Beispiel #2
0
        public HungerGameForm()
        {
            Controller      = new MouseController();
            Model           = new HungerGameModel(Controller);
            DoubleBuffered  = true;
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;
            KeyDown        += (sender, args) =>
            {
                if (args.KeyCode == Keys.Escape)
                {
                    Close();
                }
            };
            Paint += (sender, args) =>
            {
                args.Graphics.TranslateTransform(Model.Offset.X, Model.Offset.Y);
                args.Graphics.DrawImage(Model.Level.LevelBackground, Model.Level.LevelBorder);
                foreach (var objectToDraw in Model.Level.LevelObjects)
                {
                    DrawGameObject(objectToDraw, args);
                }
                DrawGameObject(Model.Player, args);
            };
            MouseMove += (sender, args) =>
            {
                Controller.UpdatePositionShift();
            };
            var timer = new Timer();

            timer.Interval = 30;
            timer.Tick    += (sender, args) =>
            {
                Model.UpdatePlayer();
                Model.UpdateLevel();
                Invalidate();
            };
            timer.Start();
        }