/// <summary> /// Metoda, ktora kontroluje ci nastala kolizia /// </summary> /// <returns>true/false</returns> private bool Collision() { var newHeadPos = Snake.GetHead(); if (GameField.gameField[newHeadPos.X, newHeadPos.Y].Info == GameInfo.Apple) { GenerateBody(); GenerateApple(); SpeedMS -= SubSpeed; } if (GameField.gameField[newHeadPos.X, newHeadPos.Y].Info == GameInfo.SnakeBody) { return(false); } if (GameField.gameField[newHeadPos.X, newHeadPos.Y].Info == GameInfo.Wall) { return(false); } if (GameField.gameField[newHeadPos.X, newHeadPos.Y].Info == GameInfo.Snail) { SpeedMS += IncSpeed; } if (Enemy.Break || Enemy2.Break) { return(false); } return(true); }
/// <summary> /// Aktualizacia pozicie hadika /// </summary> /// <returns>stav hry true/false</returns> public bool Update() { int x = Snake.GetHead().X; int y = Snake.GetHead().Y; Direction newDirection = Snake.GetHead().Facing; if (_direction == Direction.Up) { y--; newDirection = Direction.Up; } if (_direction == Direction.Down) { y++; newDirection = Direction.Down; } if (_direction == Direction.Left) { x--; newDirection = Direction.Left; } if (_direction == Direction.Right) { x++; newDirection = Direction.Right; } UpdateSnakePosition(x, y, newDirection); return(GameStatus); }
/// <summary> /// aktualizacia pozicie hadika /// </summary> /// <param name="x">x os</param> /// <param name="y">y os</param> /// <param name="direction">smerovanie hlavy hadika</param> /// <returns>true/false</returns> private bool UpdateSnakePosition(int x, int y, Direction direction) { if (GameStatus) { var tmpSnake = new Snake(Snake); Snake.UpdatePosition(x, y, direction); GameStatus = Collision(); if (!GameStatus) { return(false); } for (int i = 0; i < tmpSnake.Count(); i++) { var pp = tmpSnake.GetBody(i); GameField.gameField[pp.X, pp.Y].SetToNaN(); } GameField.gameField[Snake.GetHead().X, Snake.GetHead().Y].SetSnakeHead(direction); if (Snake.Count() > 1) { for (int i = 1; i < Snake.Count(); i++) { var oldPos = Snake.GetBody(i); GameField.gameField[oldPos.X, oldPos.Y].SetSnakeBody(); } } return(true); } return(false); }