示例#1
0
        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));
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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());
        }
示例#4
0
文件: Food.cs 项目: Avalin/wf_snake
 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;
         }
     }
 }