Пример #1
0
 public bool DoMove(Direction direction)
 {
     var tail = Body.LastOrDefault();
     var head = Body.FirstOrDefault();
     if (tail != null && head != null)
     {
         switch (direction)
         {
             case Direction.Up:
                 if (_lastDirection == Direction.Down)
                 {
                     direction = Direction.Down;
                 }
                 break;
             case Direction.Right:
                 if (_lastDirection == Direction.Left)
                 {
                     direction = Direction.Left;
                 }
                 break;
             case Direction.Down:
                 if (_lastDirection == Direction.Up)
                 {
                     direction = Direction.Up;
                 }
                 break;
             case Direction.Left:
                 if (_lastDirection == Direction.Right)
                 {
                     direction = Direction.Right;
                 }
                 break;
         }
         var x = direction == Direction.Right ? 1 : (direction == Direction.Left ? -1 : 0);
         var y = direction == Direction.Down ? 1 : (direction == Direction.Up ? -1 : 0);
         var newPos = new Tile(head.X + x, head.Y + y);
         if (newPos.X < _map.X && newPos.X >= 0 && newPos.Y < _map.Y && newPos.Y >= 0 &&
             !Body.Any(s => s.X == newPos.X && s.Y == newPos.Y))
         {
             _lastTail = new Tile(tail.X, tail.Y);
             Body.RemoveAt(Body.Count - 1);
             Body.Insert(0, newPos);
             _lastDirection = direction;
             if (OnMove != null)
             {
                 OnMove(null, null);
             }
             return true;
         }
     }
     return false;
 }
Пример #2
0
 public Vector2 Tile2Positon(Tile tile)
 {
     return new Vector2(Center.X + tile.X * TileSize, Center.Y + tile.Y * TileSize);
 }
Пример #3
0
 public void Generate()
 {
     Position = GetFreeTiles().OrderBy(x => Guid.NewGuid()).FirstOrDefault();
 }