public bool EqualCoords(Coords newCoords) { return(this.x == newCoords.x && this.y == newCoords.y); }
public void Update(Coords direction, Apple apple, Rocks rock) { for (int i = this.SnakeBody.Count - 1; i > 0; i--) { this.SnakeBody[i].x = this.SnakeBody[i - 1].x; this.SnakeBody[i].y = this.SnakeBody[i - 1].y; } this.SnakeBody[0].x += direction.x; this.SnakeBody[0].y += direction.y; ////to end if snake hits a wall //if (snakeBody[0].x<1|| // snakeBody[0].x>Console.WindowWidth|| // snakeBody[0].y<1|| // snakeBody[0].y>Console.WindowHeight) //{ // isGameOver = true; //} //to pass through walls if (this.SnakeBody[0].x == Console.BufferWidth - 2) { this.SnakeBody[0].x = 2; } if (this.SnakeBody[0].y == Console.BufferHeight - 2) { this.SnakeBody[0].y = 2; } if (this.SnakeBody[0].x == 1) { this.SnakeBody[0].x = Console.BufferWidth - 3; } if (this.SnakeBody[0].y == 1) { this.SnakeBody[0].y = Console.BufferHeight - 3; } // apple collision if (this.SnakeBody[0].EqualCoords(apple.AppleCoords)) { this.EatApple(apple); } // rock collision for (int i = 0; i < rock.AllRocks.Count; i++) { if (this.SnakeBody[0].EqualCoords(rock.AllRocks[i])) { isGameOver = true; break; } } // tail collison for (int i = 1; i < this.SnakeBody.Count; i++) { if (this.SnakeBody[0].EqualCoords(this.SnakeBody[i])) { isGameOver = true; break; } } }
public Apple() { this.AppleCoords = new Coords(0, 0); this.Exists = false; }