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 }; }
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; }
void OnFoodEaten(Snake snake, Point position) { _scene.OnFoodEaten(snake, position); _scep.Draw(); }
public void OnFoodEaten(Snake snake, Point position) { GridState[position.X, position.Y] = 1; GenerateNewFood(snake); }
public SnakePresenter(Snake snake) { _snake = snake; }