public void MoveInDirection(Snake.Directions dir, int momentum) { switch (dir) { case (Snake.Directions.UP): { head.Y -= momentum; break; } case (Snake.Directions.DOWN): { head.Y += momentum; break; } case (Snake.Directions.LEFT): { head.X -= momentum; break; } case (Snake.Directions.RIGHT): { head.X += momentum; break; } } }
public SnakeBodyPart(Point p, Snake.Directions dir) { nextShifts = new Queue <Shift>(); bodyPart = new Rectangle(p, defaultSize); myDirection = dir; defaultBrush = Brushes.SteelBlue; }
public CorsairLedId?GetNextKey(CorsairLedId originKey, Snake.Directions direction) { var rowAndKeyIndex = GetRowAndKeyIndex(originKey); var originRowIndex = rowAndKeyIndex[0]; var originKeyIndex = rowAndKeyIndex[1]; switch (direction) { case Snake.Directions.Up: return(GetKeyAtIndex( new int[] { originRowIndex - 1, originKeyIndex } )); case Snake.Directions.Left: return(GetKeyAtIndex( new int[] { originRowIndex, originKeyIndex - 1 } )); case Snake.Directions.Right: return(GetKeyAtIndex( new int[] { originRowIndex, originKeyIndex + 1 } )); case Snake.Directions.Down: return(GetKeyAtIndex( new int[] { originRowIndex + 1, originKeyIndex } )); default: return(null); } }
protected void MovementThread() { while (true) { var key = Console.ReadKey(true).Key; if ( key == ConsoleKey.LeftArrow || key == ConsoleKey.RightArrow || key == ConsoleKey.UpArrow || key == ConsoleKey.DownArrow ) { //_snake.MoveSnake(GetDirection(key).GetValueOrDefault()); _currentMovementDirection = GetDirection(key).GetValueOrDefault(); } } Snake.Directions?GetDirection(ConsoleKey pressedKey) { switch (pressedKey) { case ConsoleKey.LeftArrow: return(Snake.Directions.Left); case ConsoleKey.RightArrow: return(Snake.Directions.Right); case ConsoleKey.DownArrow: return(Snake.Directions.Down); case ConsoleKey.UpArrow: return(Snake.Directions.Up); default: return(null); } } }
public void Move(int momentum) { if (nextShifts.Count() > 0) { if (bodyPart.Location == nextShifts.ToList().First().ShiftSpot.Location) { Shift s = nextShifts.Dequeue(); myDirection = s.Direction; } } switch (myDirection) { case (Snake.Directions.UP): { bodyPart.Y -= momentum; break; } case (Snake.Directions.DOWN): { bodyPart.Y += momentum; break; } case (Snake.Directions.LEFT): { bodyPart.X -= momentum; break; } case (Snake.Directions.RIGHT): { bodyPart.X += momentum; break; } } }
public Shift(Rectangle snapShot, Snake.Directions dir) { ShiftSpot = snapShot; Direction = dir; }