public void MoveSnakeParts(LinkedList <SnakePart> snakeParts, MapManager mm) { LinkedListNode <SnakePart> snakeHead = snakeParts.Last; Tile destinationTile = mm.GetTileInFrontOfSnakePart(snakeHead.Value); Tile currentTile = mm.GetTileWithItem(snakeParts.First.Value); mm.PlaceItemOnTile(currentTile, null); for (LinkedListNode <SnakePart> snakePartNode = snakeParts.First; snakePartNode != null;) { LinkedListNode <SnakePart> nextSnakePartNode = snakePartNode.Next; if (nextSnakePartNode != null) { // Move snakePart forward to take the tile of the next snakePart MoveSnakePartToTileOfNextSnakePart(mm, snakePartNode.Value, nextSnakePartNode.Value); } else { //Moves snakehead to destination MoveSnakeHeadToDestinationTile(mm, destinationTile, snakePartNode.Value); } snakePartNode = nextSnakePartNode; } if (ShouldGrow) { GrowSnake(mm); } HandleCollision(mm.GetTileInFrontOfSnakePart(snakeHead.Value)); }
public void Draw(MapManager mm, Graphics gfx) { Tile tile = mm.GetTileWithItem(this); if (tile != null) { gfx.DrawImage(snakeImg, tile.X * mm.GetTileSize(), tile.Y * mm.GetTileSize(), snakeImg.Width, snakeImg.Height); } }
void MoveSnakePartToTileOfNextSnakePart(MapManager mm, SnakePart snakePart, SnakePart nextSnakePart) { Tile nextTile = mm.GetTileWithItem(nextSnakePart); if (nextTile == null) { throw new Exception("nextTile is null"); } mm.PlaceItemOnTile(nextTile, snakePart); snakePart.SetSnakePartDirection(nextSnakePart.GetSnakeDirection().GetCurrentDirection()); }
public void Draw(MapManager mm, Graphics gfx) { if (!MIsEaten) { Tile tile = mm.GetTileWithItem(this); if (tile != null) { gfx.DrawImage(foodImg, tile.X * mm.GetTileSize(), tile.Y * mm.GetTileSize(), mm.GetTileSize(), mm.GetTileSize()); } else { MIsEaten = true; } } }