Example #1
0
        public void Init()
        {
            _scene = new Scene(_width, _height);
            _snake = new Snake(_scene, new Point(_width / 2, _height / 2));

            _scene.GenerateNewFood(_snake);
            _snake.FoodEaten += OnFoodEaten;

            _snap = new SnakePresenter(_snake)
            {
                CanvasHeight = FormHeight,
                CanvasWidth = FormWidth,
                Graphics = g,
                Line = _height,
                Column = _width
            };

            _scep = new ScenePresenter(_scene)
            {
                CanvasHeight = FormHeight,
                CanvasWidth = FormWidth,
                Graphics = g,
                Line = _height,
                Column = _width
            };
        }
Example #2
0
        public void GenerateNewFood(Snake snake)
        {
            Random ran = new Random();
            Point rst;
            do
            {
                rst = new Point(ran.Next(Column), ran.Next(Line));
            } while (snake.BodyBlock.Contains(rst) || GridState[rst.X, rst.Y] == 0);

            GridState[rst.X, rst.Y] = 2;
            Food = rst;
        }
Example #3
0
 void OnFoodEaten(Snake snake, Point position)
 {
     _scene.OnFoodEaten(snake, position);
     _scep.Draw();
 }
Example #4
0
 public void OnFoodEaten(Snake snake, Point position)
 {
     GridState[position.X, position.Y] = 1;
     GenerateNewFood(snake);
 }
Example #5
0
 public SnakePresenter(Snake snake)
 {
     _snake = snake;
 }